Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File not uploading properly when use MTOM in SoapUI

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?

like image 968
lakshman Avatar asked May 21 '15 10:05

lakshman


People also ask

How do I enable Mtom in SoapUI?

First you need to set the request properties to enable and force MTOM. Then, on the attachments tab click the + icon and select a file to attach. You have the option of caching the file inside the request or not, I usually chose to cache it just in case the original file is deleted.

How do I upload files to SoapUI?

Switch to the Attachment tab of the request editor, click and select a file from the file system. Simply drag a file from a file manager (like Windows Explorer) to the Attachments tab. SoapUI will prompt if the file should be cached in the request or not.

How do you send a multipart file in SoapUI?

Choose multipart/form-data from the Media Type drop down. Now, click on Attachments tab at the bottom of the request editor (see below). Click on + icon at the top left corner of the attachment window to browse and attach a file to request. Browse for a file in your local file system and add it as an attachment.


1 Answers

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.

like image 190
Arjan Avatar answered Oct 05 '22 01:10

Arjan