Search code examples
javaweb-servicesjax-wsmtom

Does MTOM needed to be specified for both the client and server code


I am just getting started with SOAP web services and stumbled across MTOM.

I need to know 2 things based on following use case: A user will call a SOAP web service by passing an image. In response, they will get a formatted version of the same image.

  1. I know that I need to setMTOMEnabled(true) in client but do I have to mention it in service also. Also when the WSDL is generated how can I tell that this service uses MTOM?
  2. When client sends binary data then MTOM has to be mentioned in client code but if client sends textual data and server sends binary data then does the client also have to use MTOM?

Solution

  • I'll elaborate further as I gather more information and update this answer but on question one "JAX-WS applications require separate configuration of both the client and the server artifacts to enable MTOM support" and "the WSDL file includes a xsd:base64Binary or xsd:hexBinary element definition for the binary data." and also it may contain "xmime:expectedContentTypes"

    On two, I believe this answers your question "JAX-WS applications require separate configuration of both the client and the server artifacts to enable MTOM support"

    But again, still checking around for you.

    More of an example of what you'd see in the WSDL

    <xs:complexType name="ImageDepot">
        <xs:sequence>
            <xs:element name="imageData" type="xs:base64Binary" xmime:expectedContentTypes="image/jpeg"/>
        </xs:sequence>
    </xs:complexType>
    ........
    </types
    

    Mapping of MIME type and Java type. Describes the mapping between MIME types and Java types.

    MIME Type Java Type

    image/gif - java.awt.Image

    image/jpeg - java.awt.Image

    text/plain - java.lang.String

    text/xml - javax.xml.transform.Source

    application/xml javax.xml.transform.Source

    / javax.activation.DataHandler

    So on your second question I believe it was the text would just still be considered an attachment but would have the type of text/plain