Question

I am trying to create a SOAP message with a large XML body. The XML body comes from an input stream and the SOAP message is created manually. How can I use AXIOM to create the message without loading the entire XML body into memory. The code I started with is:

// "in" contains SOAP body
final OMXMLParserWrapper payloadBuilder = OMXMLBuilderFactory.createOMBuilder( in );
final OMElement payloadElement = payloadBuilder.getDocumentElement();

final SOAPEnvelope soapEnvelope = msgContext.getEnvelope();
soapEnvelope.getBody().addChild( payloadElement );

However, this loads the whole XML body into memory (payloadElement.detach() gets called as part of addChild()).

What is the recommended way to merge AXIOM models like this?

I have modified my code as below to make this work without loading the whole XML body. However I'm not happy with the solution because it uses the implementation classes rather than the public API.

final OMXMLParserWrapper payloadBuilder = OMXMLBuilderFactory.createOMBuilder( in );
final OMNodeEx payloadElement = (OMNodeEx)payloadBuilder.getDocumentElement();
payloadElement.setParent( null );

final SOAPEnvelope soapEnvelope = msgContext.getEnvelope();
final OMElementImpl soapBody = (OMElementImpl)soapEnvelope.getBody();
soapBody.addChild( payloadElement, true );

Does anyone have a better way of doing this?

Was it helpful?

Solution

Recent versions of Axiom have a variant of the getDocumentElement method that allows you to do exactly what you are looking for:

http://ws.apache.org/axiom/apidocs/org/apache/axiom/om/OMXMLParserWrapper.html#getDocumentElement(boolean)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top