【问题标题】:Attachment missing in MTOM response from Citrus SOAP server simulationCitrus SOAP 服务器模拟的 MTOM 响应中缺少附件
【发布时间】:2018-06-25 09:48:57
【问题描述】:

我已经构建了一个示例 Citrus 测试用例来模拟一个响应 MTOM 附件的 SOAP 服务器

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 的 RAW 视图如下所示。

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 的方法。

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

【问题讨论】:

    标签: soap mtom citrus-framework


    【解决方案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 或 citrus 都会吞下附件。一些帮助或工作 JavaDSL 示例会很好。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-27
        • 1970-01-01
        • 2011-04-21
        • 2017-03-08
        • 2014-04-04
        • 1970-01-01
        相关资源
        最近更新 更多