来自 Citrus SOAP 服务器模拟的 MTOM 响应中缺少附件

Attachment missing in MTOM response from Citrus SOAP server simulation

我构建了一个示例 Citrus 测试用例,以模拟一个 SOAP 服务器,该服务器响应 MTOM 附件

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")
);

当我 运行 此测试并使用 SoapUI 调用 Citrus 模拟时,我在调试日志中看到 myAttachment.pdf 的内容。所以至少看起来 Citrus 试图发送附件。

但是,在 SoapUI 中我没有得到附件。 SOAP 响应中有一个 XOP 元素,但没有附件。 Citrus 响应的 SoapUI 原始视图如下所示。

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--

在带有附件的 MTOM 响应中,附件从该 RAW 视图结束的地方开始。它应该像这样继续

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

%PDF-1.4... [PDF content]

我正在使用 Citrus 2.7.2 版本。

更新

仍然没有成功。 Wireshark 显示与 SoapUI 相同的图片:响应中缺少附件。

但是,当我在服务器 (Citrus) 端调试代码时,我会在响应消息中看到附件,直到我迷失在 MessageSendingTemplate 的某处。在控制台日志上也是如此。邮件有附件。

Citrus 文档中有一个内联 MTOM 变体,但我找不到在 Java 配置中的附件上设置此 mtom-inline 的方法。

任何提示,在哪里设置断点以查找附件丢失的位置?或者柑橘方面的任何其他 suggestions/examples?

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);
    });

如果我对 MtomInline 设置为 true 执行相同的操作,我会在 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 或 citrus 吞下附件。一些帮助或工作 JavaDSL 示例会很好。

这实际上是一个错误,将在 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>