SOAP MTOM attachments with Linux CURL
Asked Answered
R

1

6

So far I've been sending attachments with SOAP using simple base64 encoding and placing them inline - all done by CURL. Now I have a new request, where attachments need to be sent as MTOM attachments, the question is: is it possible with linux curl? Probably I would need a content-type of multipart/related or similar.

I can see that it is possible using JAX-WS, but in order to do this we would have to develop a new client which isn't actually the best option for us.

Please, tell me if it is possible, and if yes, give me any hints how to do it.

Roman answered 8/8, 2012 at 7:51 Comment(0)
J
1

You can include the file content in base64 encoding and using curl post.

Here is one example:

  1. Have mtom sample from axis2 installed and working for you
  2. Construct the following sample req.xml

$ cat req.xml

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mtom="http://ws.apache.org/axis2/mtomsample/" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
   <soap:Header/>
   <soap:Body>
      <mtom:AttachmentRequest>
         <mtom:fileName>one.txt</mtom:fileName>
         <mtom:binaryData xm:contentType="application/txt">SSBhbSB0aGUgZ3JlYXRlc3Qu</mtom:binaryData>
  </mtom:AttachmentRequest>
   </soap:Body>
</soap:Envelope>
  1. post the request using curl

$ cat req.xml | curl -X POST -H 'Content-type: application/soap+xml' -d @-
http://yourmachine.com:8080/axis2/services/MTOMSample.MTOMSampleSOAP12port_http/

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
  <soapenv:Body>
    <ns2:AttachmentResponse xmlns:ns2="http://ws.apache.org/axis2/mtomsample/">
      File saved succesfully.
    </ns2:AttachmentResponse>
  </soapenv:Body>
</soapenv:Envelope>

Does this work for you?

Jaysonjaywalk answered 25/2, 2013 at 2:5 Comment(2)
The base64-encoded binary data is not MTOM/XOP. It's just SOAP. This link explains the difference. In short: with MTOM/XOP the binary message content is attached as a second "part" in a multipart MIME message. the SOAP message is the first part. the second part is not base64-encoded so it saves 33% of space, and also some cpu time on either end.Rosyrot
@Rosyrot It is generally allowed to use inline base64 content in MTOM/XOP and it doesn't enforce you to use attachments (though without attachments you don't get any optimization of course, so you generally should use them). But your are right that this is not MTOM/XOP. It lacks the "content-type: application/xop+xml" header and MIME part boundaries etc.Abreast

© 2022 - 2024 — McMap. All rights reserved.