File does not load properly when using MTOM in SoapUI

I am using SoapUI version 5.1.3. I am sending a request for our service below.

<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 end of the web service, when I check the value of the dataHandler, it looks like it is truncated at the end of the line. I inserted the file using the context menu option Insert file as Base64 . I changed the Enable MTOM property to true. what could be the reason for the lack of data sent to the web service?

UPDATE

I wrote an HTTP server to capture a soap request without sending it to a web service, changing the URL in SoapUI to http://localhost:5000/ . below is the server that 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 starting the http server, I sent the above request for soap, and I could see that the http client also received the same request as above. but since I enabled MTOM, the SoapUI request must be changed, and the HTTP server should receive another request from the above soap request. According to the MTOM definition described in this SO question , the value of the binary dataHandler must be ported to the shell. it should be replaced with the xop tag and link. As an example, an envelope should look something like this.

 <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: 1.4aefed8d8cef221bc29fec3e7341b21813a53a5181b39c2b@apache.org " /> </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> 

Now my problem is that the correct way to enable MTOM in SoapUI or is it an error?

+6
source share
2 answers

For future readers:

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

Inserting the file as Base64 makes the content included in the XML directly, and not as an attachment. You will see something like:

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

For this, SoapUI does not convert the Base64 string to an attachment, and therefore MTOM is not required. You can select both Enable MTOM and Force MTOM , but even this will not send binary content as an attachment. Instead, you will receive a multi-page message with only one part (being XML with an embedded Base64 encoded file).

To receive the MTOM attachment, you must add the file to the request as an attachment (see the Attachment tab under the query editor), which will provide you with a content identifier. Then refer to this content id using cid: for example:

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

Now, regardless of Force MTOM , SoapUI will create a multi-page message with two parts.

+1
source

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

1-outgoing message is sent as a Mime Multipart message with the corresponding MTOM content type

2- The first part of Mime contains a message, the second contains an attachment

3. The ClaimImage element in the message contains the XOP Include element, which refers to the second part of the Mime-Part (highlighted)

-1
source

Source: https://habr.com/ru/post/987654/


All Articles