Search code examples
soapmtomcitrus-framework

Attachment missing in MTOM response from Citrus SOAP server simulation


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?


Solution

  • It was actually a bug that will be fixed in Citrus 2.7.4 release. See https://github.com/christophd/citrus/issues/328

    The inline MTOM variant with XML config works for me in the current release.

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