Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

The following example shows a WSDL document for a Web service that uses a message which contains one string field, one integer field, and a binary field. The binary field is intended to carry a large image file, so it is not appropriate for sending along as part of a normal SOAP message.

Code Block
xmlxml
titleMessage for MTOM
xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="XrayStorage"
    targetNamespace="http://mediStor.org/x-rays"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://mediStor.org/x-rays"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:xsd1="http://mediStor.org/types/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <types>
    <schema targetNamespace="http://mediStor.org/types/"
            xmlns="http://www.w3.org/2001/XMLSchema">
      <complexType name="xRayType">
        <sequence>
          <element name="patientName" type="xsd:string" />
          <element name="patientNumber" type="xsd:int" />
          <element name="imageData" type="xsd:base64Binary" />
        </sequence>
      </complexType>
      <element name="xRay" type="xsd1:xRayType" />
    </schema>
  </types>

  <message name="storRequest">
    <part name="record" element="xsd1:xRay"/>
  </message>
  <message name="storResponse">
    <part name="success" type="xsd:boolean"/>
  </message>

  <portType name="xRayStorage">
    <operation name="store">
      <input message="tns:storRequest" name="storRequest"/>
      <output message="tns:storResponse" name="storResponse"/>
    </operation>
  </portType>

  <binding name="xRayStorageSOAPBinding" type="tns:xRayStorage">
    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="store">
      <soap12:operation soapAction="" style="document"/>
      <input name="storRequest">
        <soap12:body use="literal"/>
      </input>
      <output name="storResponse">
        <soap12:body use="literal"/>
      </output>
    </operation>
  </binding>
  ...
</definitions>

If you wanted to use MTOM to send the binary part of the message as an optimized attachment you would need to add the xmime:expectedContentTypes attribute to the element containing the binary data. This attribute is defined in the http://www.w3.org/2005/05/xmlmimeImage Removed namespace and specifies the MIME types that the element is expected to contain. You can specify a comma separated list of MIME types. The setting of this attribute will change how the code generators create the JAXB class for the data. For most MIME types, the code generator will create a DataHandler. Some MIME types, such as those for images, have defined mappings.

Note

The MIME types are maintained by the Internet Assigned Numbers Authority (IANA) and described in detail in Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies (ftp://ftp.isi.edu/in-notes/rfc2045.txtImage Removed) and Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types(ftp://ftp.isi.edu/in-notes/rfc2046.txtImage Removed)

Tip

For most uses you would specify application/octet-stream.

The following example shows how you would modify xRayType to use MTOM.

xml
Code Block
xml
titleBinary Data for MTOM
xml
...
  <types>
    <schema targetNamespace="http://mediStor.org/types/"
            xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
      <complexType name="xRayType">
        <sequence>
          <element name="patientName" type="xsd:string" />
          <element name="patientNumber" type="xsd:int" />
          <element name="imageData" type="xsd:base64Binary"
                   xmime:expectedContentTypes="application/octet-stream"/>
        </sequence>
      </complexType>
      <element name="xRay" type="xsd1:xRayType" />
    </schema>
  </types>
...

...

The following example shows a JAXB class annotated for using MTOM.

Code Block
javajava
titleJAXB Class for MTOM
java
@XmlType
public class XRayType {
    protected String patientName;
    protected int patientNumber;
    @XmlMimeType("application/octet-stream")
    protected DataHandler imageData;
  ...
}

...

  1. Get access to the Endpoint object for your published service.
    The easiest way to get the Endpoint object is when you publish the endpoint.
  2. Get the SOAP binding from the Endpoint using its getBinding() method as shown below.
    java
    Code Block
    java
    titleGetting the SOAP Binding from an Endpoint
    java
    // Endpoint ep is declared previously
    SOAPBinding binding = (SOAPBinding)ep.getBinding();
    
    You must cast the returned binding object to a SOAPBinding object in order to access the MTOM property.
  3. Set the bindings MTOM enabled property to true using the binding's setMTOMEnabled() method as shown below.
    Code Block
    javajava
    titleSetting a Service Provider's MTOM Enabled Property
    java
    binding.setMTOMEnabled(true);
    

...

  1. Cast the client's proxy to a BindingProvider object.
  2. Get the SOAP binding from the BindingProvider using its getBinding() method as shown below.
    Code Block
    javajava
    titleGetting a SOAP Binding from a BindingProvider
    java
    // BindingProvider bp declared previously
    SOAPBinding binding = (SOAPBinding)bp.getBinding();
    
  3. Set the bindings MTOM enabled property to true using the binding's setMTOMEnabled() method as shown below.
    Code Block
    javajava
    titleSetting a Consumer's MTOM Enabled Property
    java
    binding.setMTOMEnabled(true);
    

...

The following example shows an endpoint that is MTOM enabled.

xml
Code Block
xml
titleConfiguration for Enabling MTOM
xml
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">

  <jaxws:endpoint id="xRayStorage"
                  implementor="demo.spring.xRayStorImpl"
                  address="http://localhost/xRayStorage">
    <jaxws:properties>
      <entry key="mtom-enabled" value="true"/>
    </jaxws:properties>
  </jaxws:endpoint>
</beans>