Mtom, Soap with Attachment in Composite Applications

Understanding Mtom ( Message Transmission Optimization Mechanism)


Mtom is used to optimize the transmission of soap message over the wire. MTOM uses a  wire format of a SOAP message by selectively encoding portions of the message, whilst still presenting an XML Infoset to the SOAP application. Optimization is available only for element content that is in a canonical lexical representation of the xs:base64Binary data type , For more info see the mtom and xop specificaiton


 Example WSDL 



Message Part: Consider a message with one of it part as base64Binary


<message name="mtomOperationRequest">
        <part name="part1" type="xsd:string"/>
        <part name="part2" type="xsd:base64Binary"/>
    </message>


Binding: it shows how the binding use the MTOM policy


<binding name="mtomBinding" type="tns:mtomPortType">
        <wsp:PolicyReference URI="#mtomBindingPolicy"/>
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="mtomOperation">
            <soap:operation/>
            <input name="input1">
                <soap:body use="literal" namespace="http://j2ee.netbeans.org/wsdl/mtomBP/mtom"/>
            </input>


MTOM policy


<wsp:Policy wsu:Id="mtomBindingPolicy">
        <wsp:ExactlyOne>
            <wsp:All>
                <wsoma:OptimizedMimeSerialization/>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>



 


Wire Format: The wire format below show how the soap envelope is transmitted using http, take a note of the part2 which represent the binary data and how the data is trasmitted, note the data is not part of the soap envelope instead it is transmitted as a separate mime part



POST /mtomService/mtomPort HTTP/1.1
SOAPAction: ""
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, \*; q=.2, \*/\*; q=.2
Content-Type: multipart/related;start="<rootpart\*b0ef6adc-44fa-47ba-a7a7-95915eb54d9e@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:b0ef6adc-44fa-47ba-a7a7-95915eb54d9e";start-info="text/xml"
User-Agent: JAX-WS RI 2.1.4.1-hudson-346-
Host: localhost:9088
Connection: keep-alive
Content-Length: 890


--uuid:b0ef6adc-44fa-47ba-a7a7-95915eb54d9e
Content-Id: <rootpart\*b0ef6adc-44fa-47ba-a7a7-95915eb54d9e@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary


<?xml version='1.0' encoding='UTF-8'?><S:Envelope
   xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
    <ns2:mtomOperation
     xmlns:ns2="http://j2ee.netbeans.org/wsdl/mtomBP/mtom">
     <part1>hello</part1>
     <part2>
      <xop:Include xmlns:xop="
http://www.w3.org/2004/08/xop/include"
       href="cid:2f3a859b-6cdb-4eba-8163-0365521f094c@example.jaxws.sun.com" />
     </part2>

    </ns2:mtomOperation>
   </S:Body>
</S:Envelope>
  --uuid:b0ef6adc-44fa-47ba-a7a7-95915eb54d9e Content-Id:
  <2f3a859b-6cdb-4eba-8163-0365521f094c@example.jaxws.sun.com>
  Content-Type: application/octet-stream Content-Transfer-Encoding:
  binary


  I am the binary part
  --uuid:b0ef6adc-44fa-47ba-a7a7-95915eb54d9e--



 Some of the points to note in the above wire format example are



  • The binary attachment is packaged in a MIME multi-part message

  • An <xop:Include> element is used to mark where the binary data is.

  • The actual binary data is kept in a different MIME part.


If binary data is sent as inlined, then the runtime has  to encode the data to xs:base64Binary which bloats the data by 33%,   MTOM is efficient, in the sense that it doesn't have the 33% size increase penalty that xs:base64Binary has. It is interoperable, in the sense that it is a W3C standard. However, MIME multipart incurs a small cost proportional to the number of attachments, so it is not suitable for a large number of tiny attachments. One can control the behavior of the runtime by using the MTOM threshold provided by the jax-ws RI, if an attachment is smaller than the size specified in threshold, it will simply inline the binary data as base64 binary instead of making it an attachment. For more info see mtom threshold    


Using Mtom in composite Applications


How to configure?   One does not have to create the above wsdl by hand , one had to go the CASA editor, clone the required wsdl port and the configure the "server configuration"


 how to enable mtom


Limitations


Note there could be two scenario while uisng MTOM in Composite Application



  • ExternalClient -------------->htttpbc------------>bpel( or any JBI Component)   

  • bpel( or any JBI Component)--------->httpbc----------->ExternalWebservice


The first scenario works fine where httpbc is provisioning the service, However the second scenarion in which  an user want to use MTOM while making an Outgoing CALL (invoking external web service ) httpbc--------->ExternalWebservice , then it does not work , i.e the data is not sent as an attachment ( rather gets inlined)  though the wsdl policy specifies the mtom policy. This is due to a limitation in the jax-ws dispatch API which is used the httpbc to invoke an webservice external to the composite application , The solution is that case is to use Soap With Attachment


Soap with Attachment


This profile compliments the WS-I Basic Profile 1.1 to add support for conveying interoperable SOAP Messages with Attachments-based attachments with SOAP messages.


SOAP Messages with Attachments (SwA) defines a MIME multipart/related structure for packaging attachments with SOAP messages. This profile complements the WS-I Basic Profile 1.1 to add support for conveying interoperable SwA-based attachments with SOAP messages.


Example WSDL 



Message Part: Consider a message with one of it part base64Binary


  <message name="requestMessage">
        <part name="inputType" element="ns:typeA"/>
        <part name="image" type="xsd:base64Binary"/>
</message>
   
<message name="responseMessage">
        <part name="resultType" element="ns:typeA"/>
        <part name="image" type="xsd:base64Binary"/>
</message>


 Binding:


<binding name="binding1" type="tns:portType1">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="operation1">
            <input name="input1">
                <mime:multipartRelated>
                    <mime:part>
                        <soap:body parts="inputType" use="literal"/>
                    </mime:part>
                    <mime:part>
                        <mime:content part="image" type="image/jpeg"/>
                    </mime:part>
                </mime:multipartRelated>
            </input>           
            <output name="output1">
                <mime:multipartRelated>
                    <mime:part>
                        <soap:body parts="resultType" use="literal"/>
                    </mime:part>
                    <mime:part>
                        <mime:content part="image" type="image/jpeg"/>
                    </mime:part>
                </mime:multipartRelated>
            </output>           
        </operation>
</binding>



Wire Format



POST /Synchronous HTTP/1.1
SOAPAction: ""
Content-Type: multipart/related; type="text/xml"; start="<rootpart@soapui.org>"; boundary="----=_Part_11_20752690.1234494006000"
MIME-Version: 1.0
User-Agent: Jakarta Commons-HttpClient/3.0.1
Host: localhost:9088
Content-Length: 29154



------=_Part_11_20752690.1234494006000
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:syn="http://xml.netbeans.org/schema/Synchronous">
   <soapenv:Header/>
   <soapenv:Body>
      <syn:typeA>
         <syn:paramA>Hello</syn:paramA>
      </syn:typeA>
   </soapenv:Body>
</soapenv:Envelope>
------=_Part_11_20752690.1234494006000
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <image=83407562804769@soapui.org>


.........binary part..............


........................................


Any MIME part may contain a soap:Envelope, but only the entity body of the root-part of the MIME package is treated as the primary SOAP envelope. Non-root parts are referred to as attachments.


In the message above the the Content-Type HTTP header field-value has a media-type of 'Multipart/Related' and a parameter 'type' with value of 'text/xml'


SOAP Messages with Attachments places no restriction on the type of any non-root part in a multipart/related message



Composite Application : Try the example here



 



SoapUI: Note how the attachment part is specified using soapUI



 soap ui showing how to attach image


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

sujit

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today