Contact Us 1-800-596-4880

Using MTOM

Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version.

This page describes the basics of how to use MTOM inside your service. For more information, go to the MTOM documentation for CXF. Portions of the examples on this page are from that guide.

For a WSDL-first service, the general process is as follows:

  1. Write your WSDL

  2. Generate your server stubs

  3. Configure the CXF endpoint in Mule

Writing an MTOM-enabled WSDL

To get started, write a WSDL like you would normally. Use xsd:base64Binary schema types to represent any binary data that you want to send.

Normally, when creating XML schema types for binary data, you would write a schema type like this:

<element name="yourData" type="xsd:base64Binary"/>

To tell CXF to treat this binary type as an attachment, you must add an xmime:expectedContentTypes attribute to it:

<schema targetNamespace="http://mediStor.org/types/"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:xmime="http://www.w3.org/2005/05/xmlmime">

<element name="yourData" type="xsd:base64Binary" xmime:expectedContentTypes="application/octet-stream"/>
...
</schema>

Generating Server Stubs and/or a Client

After writing your WSDL, you run wsdl2java on it to generate server stubs and a client (if you are creating outbound endpoints). To do this, download the CXF distribution, extract it, and then enter the following command:

$ ./apache-cxf-2.1.2-incubator/bin/wsdl2java -d outputDirectory path/to/your.wsdl

Configuring the CXF Inbound Endpoint

The above command generates a server stub interface. This is the interface that your service must implement. Each method will correspond to an operation in your WSDL. If the base64Binary type is an argument to one of your operations, CXF will generate a method like this:

public void yourOperation(DataHandler handler) {
...
}

You can use this DataHandler method to access the attachment data by calling "handler.getInputStream();".

When you configure the CXF service, set the mtomEnabled attribute to true to enable MTOM:

Configuring the CXF client

The configuration of an MTOM client is exactly like the configuration of a normal CXF outbound endpoint, except that you must specify the mtomEnabled attribute. For example:

<cxf:jaxws-client
    clientClass="org.mule.example.employee.EmployeeDirectory_Service"
    operation="addEmployee"
    wsdlPort="EmployeeDirectoryPort"
    wsdlLocation="classpath:employeeDirectory.wsdl"
    mtomEnabled="true"/>