0

I have built a sample Citrus testcase to simulate a SOAP server that responds with an MTOM attachment.

runner.soap(action -> action.server("simulationServer")
        .receive()
        ...[validation etc]
);

runner.soap(action -> action.server("simulationServer")
        .send()
        .name("get-response")
        .mtomEnabled(Boolean.TRUE)
        .attachment("myAttachment", "application/octet-stream", new ClassPathResource("testfiles/myAttachment.pdf"))
        .payload("<getResponse xmlns:xmime=\"http://www.w3.org/2005/05/xmlmime\">\n" +
                "    <document>\n" +
                "        <contentElements>\n" +
                "            <contentElement xmime:contentType=\"application/pdf\">cid:myAttachment</contentElement>\n" +
                "        </contentElements>\n" +
                "        <id>Test</id>\n" +
                "    </document>\n" +
                "</getResponse>\n")
);

When I run this test and call the Citrus simulation with SoapUI, I see the contents of myAttachment.pdf in the debug logs. So at least it looks like Citrus tries to send the attachment.

However, in SoapUI I do not get an attachment. There is a XOP element in the SOAP response, but no attachment. The RAW view of SoapUI of the Citrus response looks like this.

HTTP/1.1 200 OK
Date: Tue, 16 Jan 2018 15:30:36 GMT
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: Multipart/Related; boundary="----=_Part_0_382348859.1516116636524"; type="application/xop+xml"; start-info="text/xml"
Transfer-Encoding: chunked
Server: Jetty(9.4.6.v20170531)

------=_Part_0_382348859.1516116636524
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><getResponse xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
    <document>
        <contentElements>
            <contentElement xmime:contentType="application/pdf"><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:myAttachment"/></contentElement>
        </contentElements>
        <id>Test</id>
    </document>
</getResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
------=_Part_0_382348859.1516116636524--

In an MTOM response with attachment the attachment starts where this RAW view ends. It should continue like this

------=_Part_0_382348859.1516116636524-- [last line from above]
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-ID: <myAttachment>

%PDF-1.4... [PDF content]

I am using Citrus 2.7.2 release.

Update

Still no success on this. Wireshark shows the same picture as SoapUI: the attachment is missing in the response.

However, when I debug into the code on the server (Citrus) side, I see the attachment in the response message until I get lost somewhere in a MessageSendingTemplate. Same on the console log. The message has the attachment.

There is an inline MTOM variant in the Citrus documentation, but I can't find a way to set this mtom-inline on the attachment in Java config.

Any hints, where to set a breakpoint to find where the attachment get lost? Or any other suggestions/examples on the Citrus side?

4

2 回答 2

1

setMtomInline字段位于 SoapAttachment接口上。我不确定我的设置是否正确 - 但似乎适用于内联附件 - 对于肥皂附件/多部分失败。SoapUI Mock 在接收来自以下测试用例的请求时不显示任何附件。

    SoapAttachment soapAttachment = new SoapAttachment();
    soapAttachment.setMtomInline(false);
    soapAttachment.setContentResourcePath("log4j.xml");
    soapAttachment.setContentType("application/octet-stream");
    soapAttachment.setContentId("FILE");

    SoapMessage soapMessage = new SoapMessage();
    soapMessage.mtomEnabled(true);
    soapMessage.soapAction("/HelloService/sayHello");
    soapMessage.setPayload(
            "<ht:HelloRequest " +
                    "xmlns:ht=\"http://citrusframework.org/schemas/samples/HelloMtomService\" " +
                    "xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" >\n" +
                    "   <ht:Message>Hei .. citrus does stream mtom</ht:Message>\n" +
                    "   <ht:Data><xop:Include href=\"cid:FILE\"/></ht:Data>\n" +
                    "</ht:HelloRequest>");
    soapMessage.addAttachment(soapAttachment);

    runner.soap(action -> {
        action.client("helloMtomSoapuiClient")
                .send()
                .soapAction("/HelloService/sayHello")
                .message(soapMessage);
    });

如果我对设置为 true 的 MtomInline 执行相同操作,我会在 ht:Data 节点中将附件视为 base64 编码的内容文本。

        SoapAttachment soapAttachment = new SoapAttachment();
    soapAttachment.setContentResourcePath("log4j.xml");
    soapAttachment.setMtomInline(true);
    soapAttachment.setContentType("application/xml");
    soapAttachment.setContentId("MyAttachement");
    soapAttachment.setEncodingType("base64Binary");

    runner.soap(action -> {
        action.client("helloMtomSoapuiClient")
                .send()
                .soapAction("/HelloService/sayHello")
                .mtomEnabled(true)
                .payload("<ht:HelloRequest xmlns:ht=\"http://citrusframework.org/schemas/samples/HelloMtomService\">\n" +
                        " <ht:Message>Hei .. citrus does mtom</ht:Message>\n" +
                        " <ht:Data>cid:MyAttachement</ht:Data>\n" +
                        "</ht:HelloRequest>")
                .attachment(soapAttachment);
    });

soapUI 或柑橘会吞下附件。一些帮助或工作 JavaDSL 示例会很好。

于 2018-01-21T09:48:58.573 回答
0

这实际上是一个将在 Citrus 2.7.4 版本中修复的错误。见https://github.com/christophd/citrus/issues/328

在当前版本中,带有 XML 配置的内联 MTOM 变体适用于我。

<ws:send endpoint="simulationServer" mtom-enabled="true">
    <message>
        <resource file="testfiles/simulation/get-response.xml" />
    </message>
    <ws:attachment content-id="myAttachment" content-type="application/octet-stream" mtom-inline="true" encoding-type="base64Binary">
        <ws:resource file="classpath:testfiles/myAttachment.pdf"/>
    </ws:attachment>
</ws:send>
于 2018-01-30T15:35:46.523 回答