Email: []

Implementation of MTOM for AXIOM


MTOM (SOAP Message Transmission Optimization Mechanism) describes an abstract feature for optimizing the transmission and/or wire format of a SOAP message by selectively encoding portions of the message. This implementation focuses on implementing MTOM on top of AXIOM.


Transport module has given the responsibility of identifying MTOM messages and choosing between the right builder (MTOMStAXSOAPBuilder or StAXSOAPModelBuilder). Identifying MTOM messages can be done by looking at the “Content-Type” and “type” headers of the message.

MTOMStAXSOAPBuilder assumes that the Input Stream provided to it contains an MTOM encoded MIME message. It passes that Input stream to MTOMBuilder. MTOMbuilder extracts the root mime part which contains the XOP soap message and returns a XMLStreamReader(parser) built using that Soap message to the MTOMStAXSOAPModelBuilder. This builder deferred builds the AXIOM using that parser.

When the builder comes across an xop:include element with the correct namespace, it creates an OMBlob node in the AXIOM. This OMBlob node keeps the “CID” value read from xop:include element and a reference to the MTOMbuilder in it.

OMBlob achieves deferred building by reading the MIME parts referenced by it only when a user requests the actual binary data value stored in it. When a request comes for the binary data, OMBlob use its MTOMBuilder reference and “CID” to obtain the correct Data Handler.


MTOMXMLStreamReader has to be used when the message needs to be optimized using MTOM. This will ensure that OMBlobs in the AXIOM will be attached to the message by MTOM optimizing. This MTOMXMLStreamReader buffers the output stream taken from the internally initialized XMLStreamReader. When this serializes an OMBlob it generates an “CID” value and writes the <xop:include> element using it. At the same time it stores that “CID” & a reference to the OMBlob in a hash map.

The “complete()” method of the MTOMXMLStreamReader has to be called After serializing the whole document. At that point the MTOMXMLStreamReader generates the root mime part using the buffered outputStream data from the XMLStreamReader. Also it generates additional mime parts for all the OMBlob & CID pairs in the HashMap and creates a Mime message containing all.

Content in the OMBlob will be serialized as base64encoded strings when plain XMLStreamReader is used to serialize an AXIOM containing OMBlobs. This can be used when it is decided not to use MTOM optimization. Other than that the binary attachments which are not qualified to be optimized will remain as base 64 strings in OMText nodes.


-Thilina Gunarathne

FrontPage/Axis2/MTOM (last edited 2009-09-20 22:48:09 by localhost)