Contact Us 1-800-596-4880

Using MTOM

This page describes the basics of how to use W3C Message Transmission Optimization Mechanism (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=""

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

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 corresponds to an operation in your WSDL. If the base64Binary type is an argument to one of your operations, CXF generates a method like this:

public void yourOperation(DataHandler handler) {

You can use a 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:


Configuring the Web Service Consumer

To configure an MTOM client with the Web Service Consumer, you must specify the mtomEnabled attribute. The message payload should include a sub-section that holds attachments (such as text, images, or applications) that travel with the message. For more information on attachments, see Attachment Transformer Reference.


The following examples use Dataweave transforms to construct code blocks for MTOM access.

Download a File

The following example downloads a file from the test site

<ws:consumer-config name="Web_Service_Consumer" service="ExampleServerImplService" port="ExampleServerImplPort" serviceAddress="" wsdlLocation="" doc:name="Web Service Consumer"/>
<flow name="download-file">

  <dw:transform-message doc:name="Transform Message">
      <dw:set-payload><![CDATA[%dw 1.0
%namespace ex
%output application/xml
ex#downloadFile: { arg0: 'filename.txt' }


  <ws:consumer config-ref="Web_Service_Consumer" operation="downloadFile" mtomEnabled="true" doc:name="Web Service Consumer"/>

  <logger message="This is what we got back #[message]" level="INFO" doc:name="Logger"/>

  <logger message="Attachments are: #[flowVars.cxf_attachments]" level="INFO" doc:name="Logger"/>

The output of the Dataweave transform is:

<?xml version='1.0' encoding='US-ASCII'?>
<ex:downloadFile xmlns:ex="">

Upload a File

The following example uses MTOM to upload a file from the test site

<file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="upload-file">
  <file:inbound-endpoint path="/some/path" connector-ref="File" responseTimeout="10000" doc:name="File"/>

  <set-attachment attachmentName="#[message.inboundProperties.originalFilename]" value="#[payload]" contentType="image/jpg" doc:name="Attachment1"/>

  <dw:transform-message doc:name="Transform Message">
      <dw:set-payload><![CDATA[%dw 1.0
%namespace ex
%namespace inc
%output application/xml
ex#uploadFile: { arg0: { inc#Include  @(href: 'cid:' ++ flowVars.originalFilename): '' } }


  <ws:consumer config-ref="Web_Service_Consumer" operation="uploadFile" mtomEnabled="true" doc:name="Web Service Consumer"/>


The output of the Dataweave transform is:

<?xml version='1.0' encoding='US-ASCII'?>
<ex:uploadFile xmlns:ex="">
    <inc:Include xmlns:inc="" href="cid:myfile.txt"></inc:Include>