File not uploading properly when use MTOM in SoapUI
Asked Answered
W

2

6

I am using SoapUI 5.1.3 version. I am sending below request to the we service.

<soapenv:Envelope       xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:upl="http://upload.application.carbon.wso2.org" xmlns:xsd="http://upload.application.carbon.wso2.org/xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <upl:uploadApp>
         <!--Zero or more repetitions:-->
         <upl:fileItems>
            <!--Optional:-->
            <xsd:dataHandler>UEsDBBLjAuMC52MjAxMTA1MjcxNTIxMDAvYXJ0aWZhY3QueG1sUEsFBgAAAAAJAAkAMAMAAC4IAAAAAA==</xsd:dataHandler>
            <!--Optional:-->
            <xsd:fileName>ESBproject1-1.0.0.car</xsd:fileName>
            <!--Optional:-->
            <xsd:fileType>jar</xsd:fileType>
         </upl:fileItems>
      </upl:uploadApp>
   </soapenv:Body>
</soapenv:Envelope>

at the web service end, when I check the dataHandler value seems like it is truncated at the end of the string. I inserted file using Insert file as Base64 context menu option. I changed Enable MTOM property to true. what could be the reason for missing a part of data that sends to web service?

UPDATE

I wrote a HTTP server to capture the soap request without sending it to the web service by changing the url in SoapUI to http://localhost:5000/. below is the server I wrote

public static void main(String[] args) throws Exception {
    ServerSocket server = new ServerSocket(5000);
    Socket conn = server.accept();
    StringBuilder sb = new StringBuilder();
    //getBytes() method returns a byte array for InputStream 
    ByteArrayInputStream reader = new ByteArrayInputStream(getBytes(conn.getInputStream()));

    int ch;
    while ( (ch = reader.read()) != -1) {
        sb.append((char)ch);
    }
    System.out.println("Your  message: "+sb.toString()); 
}

after running the HTTP server I sent the above mentioned soap request and I could have seen that http client also received the same request as above. but since I have enabled MTOM, SoapUI request should be modified and HTTP server should received different request from the above soap request. According to MTOM definition as described in this SO question, binary dataHandler value should be moved to out of the envelop. it should be replaced with xop tag and a reference. As an example envelop should be something like below.

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
 <soapenv:Body>
   <ns2:uploadApp xmlns:ns2="http://upload.application.carbon.wso2.org">
     <ns2:fileItems>
        <ns1:dataHandler xmlns:ns1="http://upload.application.carbon.wso2.org/xsd">
           <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:[email protected]" />
        </ns1:dataHandler>
        <ns1:fileName xmlns:ns1="http://upload.application.carbon.wso2.org/xsd">ESBproject1-1.0.0.car</ns1:fileName>
        <ns1:fileType xmlns:ns1="http://upload.application.carbon.wso2.org/xsd">jar</ns1:fileType>
     </ns2:fileItems>
   </ns2:uploadApp>
 </soapenv:Body>
</soapenv:Envelope>

my problem now is, is that the correct way to enable MTOM in SoapUI or is this a bug?

Wiencke answered 21/5, 2015 at 10:6 Comment(0)
S
1

For future readers:

I inserted file using Insert file as Base64 context menu option. I changed Enable MTOM property to true.

Inserting the file as Base64 makes the content being included in the XML directly, not as attachment. You'd see something like:

<myfile>some long Base64-encoded string here</myfile>

For this, SoapUI will not convert the Base64 string into an attachment, and hence no MTOM is needed. You could select both Enable MTOM and Force MTOM, but even that will not send the binary content as attachment. Instead, you'd then get a multipart message with just a single part (being the XML with the embedded Base64 encoded file).

To get an MTOM attachment, you should add the file to the request as attachment (see the "Attachment" tab underneath the request editor), which will get you a content id. Next, refer to that content id using cid:, like:

<myfile>cid:myfile.png</myfile>

Now, regardless of Force MTOM, SoapUI will create a multipart message with two parts.

Suburbanize answered 24/7, 2016 at 7:33 Comment(0)
P
-1

Document at http://www.soapui.org/soap-and-wsdl/headers-and-attachments.html says that "enable MTOM = true" does following things.

1-The outgoing message is being sent as a Mime Multipart message with the corresponding MTOM Content-Type

2-The first Mime Part contains the message, the second contains the attachment

3-The ClaimImage element in the message contains an XOP Include element referring to the second Mime-Part (highlighted)

Palladic answered 30/5, 2015 at 12:27 Comment(1)
As the second point mentioned, message will not in two parts even after doing "enable MTOM = true". that's the problem. then this should be a bug. isn't it?Wiencke

© 2022 - 2024 — McMap. All rights reserved.