Search code examples
javasoapjaxbcxfmtom

Use MTOM on only certain fields, other fields inline - CXF SOAP


I have a CXF based web service that is using MTOM. It's using MTOM perfectly fine, however there are some byte[] fields that I always want to be inline in the SOAP XML. I do NOT want them to be sent as mime attachments.

Even if I do not use the @XmlMimeType attribute on the byte array responses always use MTOM on the byte fields. Is it possible to have some byte arrays place the payload inline and others use MTOM?

The only way I have seen this possible is based on size by using the threshold, but this is not what I want.

Example:

public class Content {

     //I want this field inline
     private byte[] contentNONMTOM;


     //I want this field to be attached/MTOM
     @XmlMimeType("application/octet-stream")
     private byte[] contentMTOM
     ....

Solution

  • The @XmlInlineBinaryData annotation is used to force JAXB to inline the data in the XML:

    @XmlInlineBinaryData
    private byte[] contentNONMTOM;
    

    For More Information

    I have written more about this use case on my blog: