Skip to main content

1a) Modifying your schema for MTOM

Lets say we have a Picture schema type like this:

<schema targetNamespace="http://pictures.com"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <element name="Picture">
      <complexType>
         <sequence>
            <element name="Title" type="xsd:string"/>
            <element name="ImageData" type="xsd:base64Binary"/>
         </sequence>
      </complexType>
   </element>
</schema>

In this case the ImageData element is something we would like to have transferred as an attachment. To do this we just need to add an xmime:expectedContentTypes annotation:

<schema targetNamespace="http://pictures.com" 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
   <element name="Picture">
      <complexType>
         <sequence>
            <element name="Title" type="xsd:string"/>
            <element name="ImageData" type="xsd:base64Binary"
               xmime:expectedContentTypes="application/octet-stream"/>
         </sequence>
      </complexType>
   </element>
</schema>

This tells JAXB (which WSDL2Java uses to generate POJOs for your service) that this field could be of any content type. Instead of creating a byte[] array for the base64Binary element, it will create a DataHandler instead which can be used to stream the data.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!