try {
MessageFactory factory = saajOut.getFactory(message);
soapMessage = factory.createMessage();
SOAPPart part = soapMessage.getSOAPPart();
if (o instanceof Source) {
StaxUtils.copy((Source)o, new SAAJStreamWriter(part));
}
} catch (SOAPException e) {
throw new SoapFault("Error creating SOAPMessage", e,
message.getVersion().getSender());
} catch (XMLStreamException e) {
throw new SoapFault("Error creating SOAPMessage", e,
message.getVersion().getSender());
}
}
BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);
DocumentFragment frag = soapMessage.getSOAPPart().createDocumentFragment();
try {
Node body = SAAJUtils.getBody(soapMessage);
Node nd = body.getFirstChild();
while (nd != null) {
if (nd instanceof SOAPFault) {
message.put(Message.RESPONSE_CODE, 500);
validateFault(message, (SOAPFault)nd, bop);
}
body.removeChild(nd);
frag.appendChild(nd);
nd = SAAJUtils.getBody(soapMessage).getFirstChild();
}
message.setContent(SOAPMessage.class, soapMessage);
if (!message.containsKey(SAAJOutInterceptor.ORIGINAL_XML_WRITER)) {
XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
message.put(SAAJOutInterceptor.ORIGINAL_XML_WRITER, origWriter);
}
W3CDOMStreamWriter writer = new SAAJStreamWriter(soapMessage.getSOAPPart());
// Replace stax writer with DomStreamWriter
message.setContent(XMLStreamWriter.class, writer);
message.setContent(SOAPMessage.class, soapMessage);
int index = 0;