}
}
// Check the namespace and find SOAP version and factory
String nsURI = null;
SOAPFactory factory;
if (env.getNamespace().getNamespaceURI().equals(
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
nsURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
factory = DOOMAbstractFactory.getSOAP11Factory();
} else {
nsURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
factory = DOOMAbstractFactory.getSOAP12Factory();
}
StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(
env.getXMLStreamReader(), factory, nsURI);
SOAPEnvelope envelope = (stAXSOAPModelBuilder)
.getSOAPEnvelope();
((OMNode) envelope.getParent()).build();
//Set the processed flag of the processed headers
SOAPHeader header = envelope.getHeader();
for (Iterator iter = processedHeaderQNames.iterator(); iter
.hasNext();) {
QName name = (QName) iter.next();
Iterator omKids = header.getChildrenWithName(name);
if(omKids.hasNext()) {
((SOAPHeaderBlock)omKids.next()).setProcessed();
}
}
Element envElem = (Element) envelope;
return envElem.getOwnerDocument();
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
env.build();
env.serialize(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos
.toByteArray());
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setNamespaceAware(true);
return factory.newDocumentBuilder().parse(bais);
}
} catch (Exception e) {
throw new WSSecurityException(
"Error in converting SOAP Envelope to Document", e);
}