Home

 

Sending binary data using MTOM

SOAP Message Transmission Optimization Mechanism (MTOM) is a standard that is developed by the World Wide Web Consortium (W3C). MTOM describes a mechanism for optimizing the transmission or wire format of a SOAP message by selectively re-encoding portions of the message while still presenting an XML Information Set (Infoset) to the SOAP application.

MTOM uses the XML-binary Optimized Packaging (XOP) in the context of SOAP and MIME over HTTP. XOP defines a serialization mechanism for the XML Infoset with binary content that is not only applicable to SOAP and MIME packaging, but to any XML Infoset and any packaging mechanism. It is an alternate serialization of XML that just happens to look like a MIME multipart or related package, with XML documents as the root part.

That root part is very similar to the XML serialization of the document, except that base64-encoded data is replaced by a reference to one of the MIME parts, which is not base64 encoded. This reference enables you to avoid the bulk and overhead in processing that is associated with encoding. Encoding is the only way binary data can work directly with XML.

In this section we use the top-down approach to create a JAX-WS Web service to send binary attachments along with SOAP request, and receive binary attachments along with SOAP response using MTOM.

The Web service client sends three types of document: Microsoft Word, image, and PDF file. We describe several ways to send the documents:

The client uses byte[] to send the Word document.

The client uses java.awt.Image to send the image file.

The client uses javax.activation.DataHandler to send the PDF file.

After the Web service receives the binary data from the client, it stores the received document on the local hard disk and then passes the same document back to the client. In a real world scenario, the provider or the consumer can just send an acknowledgement message, after it receives the binary data from the other side. For our example, we want to show how to enable the MTOM on both the client and the server side in a compact example.

ibm.com/redbooks