Search code examples
javamtom

How to detect in Java if SOAP message is MTOM


Is there any way in Java (1.6) to detect if SOAP message is MTOM or do I need to create method for that to check if message has multiparts?

Based on the SOAP 1.2 specs to

determine whether the HTTP SOAP Transmission Optimization Feature is used by checking the presence of the application/xop+xml media type

but I don't see it in my MTOM message which in a test (minimalistic) case looks like

------=_Part_0_591998098.1543337064443
Content-Type: application/soap+xml; charset=utf-8

<soapenv:Envelope>some SOAP message</soapenv:Envelope>


------=_Part_0_591998098.1543337064443
Content-Type: null
Content-ID: <[email protected]>
Content-Transfer-Encoding: binary
Content-Type: text/html

<?xml version="1.0" encoding="us-ascii"?><html><head><title>testlf</title></head><body><b>Message Type: </b>Direct<br /><b>Subject: </b>testlf<br /><hr /></body></html>

------=_Part_0_591998098.1543337064443
Content-Type: application/octet-stream
Content-ID: <http://tempuri.org/1/635742060149828871>
Content-Transfer-Encoding: binary

<?xml version='1.0'?><?xml-stylesheet type='text/xsl'?>Here is PDF

------=_Part_0_591998098.1543337064443--

Solution

  • I have ended up with

    private boolean isMTOM(SOAPMessage msg) throws SOAPException, IOException
    {
    
        boolean isMTOM = false;
    
        MimeHeaders headers = msg.getMimeHeaders();
        String[] contentType = headers.getHeader("Content-Type");
    
        if(contentType[0].toLowerCase().contains("multipart/related") && (contentType[0].toLowerCase().contains("application/soap+xml") || contentType[0].toLowerCase().contains("application/xop+xml"))) {
            isMTOM = true;
        }
    
        return isMTOM;
    }