public void handleMessage(Message message) {
XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
if (writer == null) {
throw new NullPointerException("XMLStreamWriter content not found");
}
SoapVersion soapVersion = message.get(SoapVersion.class);
if (soapVersion == null) {
soapVersion = this.soapVersion;
if (soapVersion == null) {
throw new IllegalStateException("No soap version specified");
}
}
try {
StaxUtil.writeStartElement(writer, soapVersion.getEnvelope());
// Write Header
if (message.getSoapHeaders().size() > 0) {
StaxUtil.writeStartElement(writer, soapVersion.getHeader());
for (Iterator it = message.getSoapHeaders().values().iterator(); it.hasNext();) {
DocumentFragment df = (DocumentFragment) it.next();
Element e = DomUtil.getFirstChildElement(df);
StaxUtil.copy(new DOMStreamReader(e), writer);
}
writer.writeEndElement();
}
// Write Body
StaxUtil.writeStartElement(writer, soapVersion.getBody());
// Write content
InterceptorChain chain = message.get(InterceptorChain.class);
chain.doIntercept(message);
// Close elements
writer.writeEndElement();