Axis2/Axiom handling SOAP MTOM/non-MTOM attachments
After looking around and trying different suggested solutions, I’m writing this. The 2 most common solutions suggested to extract binary data from a MTOM/non-MTOM SOAP message are:
- Retrieve the OMText node, and use the dataHandler instance present within it
- Find the OMElement node which contains the ‘href’ attribute. Get the ‘cid:xxxxx’ value, and use the ‘xxxxx’ part to retrieve the attachment from the attachment map present in the message context instance.
The problem I’m facing is that my client indicates that the SOAP response message is MTOM [I determined this using the isDoingMTOM() method o开发者_高级运维f the message context instance]. However, there are no OMElement nodes which contain the ‘href’ attribute. On printing the SOAP envelope, I found that the binary data is present inline within the body. So I tried the OMText node approach to get the data, but whenever I try to cast the OMElement to the corresponding OMText node, I keep getting a classCastException.
Can someone point out what I’m missing out on?
How are you printing out the SOAPEnvelope Axiom object? If you're calling the toString() method, this has some unfortunate side effects. Specifically, the toString() method will cause Axiom to parse the underlying SOAP message, and build an Axiom Object graph (OMElement nodes, etc.) that represent the raw XML. As the Object graph is being built, Axiom may alter the representation of the XML slightly:
Here's a link from Axiom's site that talks about the behavior of toString(): http://ws.apache.org/axiom/userguide/ch05.html#d0e1111
For MTOM messages in particular, as Axiom is building the Object graph it will replace the elements that point to the raw binary MTOM attachments with a Base64 encoded text representation of the raw binary -- effectively wiping out any benefit of using MTOM (MTOM allows you to forgo the Base64 encoding process which bloats the size of the binary). The replacement of elements will also take place if you look at the Axiom Object graph in the debugger (because doing so calls the toString() method as well).
Are you using ADB as your XML binding framework?
精彩评论