try {
if (xmlReader.nextTag() == XMLStreamConstants.START_ELEMENT) {
String ns = xmlReader.getNamespaceURI();
if (ns == null || "".equals(ns)) {
throw new SoapFault(new Message("NO_NAMESPACE", LOG, xmlReader.getLocalName()),
Soap11.getInstance().getVersionMismatch());
}
SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
if (soapVersion == null) {
throw new SoapFault(new Message("INVALID_VERSION", LOG, ns, xmlReader.getLocalName()),
Soap11.getInstance().getVersionMismatch());
}
if (soapVersion == Soap12.getInstance()
&& version == Soap11.getInstance()) {
throw new SoapFault(new Message("INVALID_11_VERSION", LOG, ns, xmlReader.getLocalName()),
Soap11.getInstance().getVersionMismatch());
}
message.setVersion(soapVersion);
XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, message.getVersion()
.getBody());
Document doc = StaxUtils.read(filteredReader);
message.setContent(Node.class, doc);
// Find header
// TODO - we could stream read the "known" headers and just DOM read the
// unknown ones
Element element = doc.getDocumentElement();
QName header = soapVersion.getHeader();
List<Element> elemList =
DOMUtils.findAllElementsByTagNameNS(element,
header.getNamespaceURI(),
header.getLocalPart());
for (Element elem : elemList) {
Element hel = DOMUtils.getFirstElement(elem);
while (hel != null) {
// Need to add any attributes that are present on the parent element
// which otherwise would be lost.
if (elem.hasAttributes()) {
NamedNodeMap nnp = elem.getAttributes();
for (int ct = 0; ct < nnp.getLength(); ct++) {
Node attr = nnp.item(ct);
Node headerAttrNode = hel.hasAttributes()
? hel.getAttributes().getNamedItemNS(
attr.getNamespaceURI(), attr.getLocalName())
: null;
if (headerAttrNode == null) {
Attr attribute = hel.getOwnerDocument().createAttributeNS(
attr.getNamespaceURI(),
attr.getNodeName());
attribute.setNodeValue(attr.getNodeValue());
hel.setAttributeNodeNS(attribute);
}
}
}
HeaderProcessor p = bus.getExtension(HeaderManager.class)
.getHeaderProcessor(hel.getNamespaceURI());
Object obj;
DataBinding dataBinding = null;
if (p == null || p.getDataBinding() == null) {
obj = hel;
} else {
dataBinding = p.getDataBinding();
obj = dataBinding.createReader(Node.class).read(hel);
}
//TODO - add the interceptors
SoapHeader shead = new SoapHeader(new QName(hel.getNamespaceURI(),
hel.getLocalName()),
obj,
dataBinding);
String mu = hel.getAttributeNS(soapVersion.getNamespace(),
soapVersion.getAttrNameMustUnderstand());
String act = hel.getAttributeNS(soapVersion.getNamespace(),
soapVersion.getAttrNameRole());
if (!StringUtils.isEmpty(act)) {
shead.setActor(act);
}
shead.setMustUnderstand(Boolean.valueOf(mu) || "1".equals(mu));
//mark header as inbound header.(for distinguishing between the direction to
//avoid piggybacking of headers from request->server->response.
shead.setDirection(SoapHeader.Direction.DIRECTION_IN);
message.getHeaders().add(shead);
hel = DOMUtils.getNextElement(hel);
}
}
//advance to just outside the <soap:body> opening tag, but not
//to the nextTag as that may skip over white space that is
//important to keep for ws-security signature digests and stuff
int i = xmlReader.next();
while (i == XMLStreamReader.NAMESPACE
|| i == XMLStreamReader.ATTRIBUTE) {
i = xmlReader.next();
}
if (MessageUtils.getContextualBoolean(message,
SoapMessage.SCHEMA_VALIDATION_ENABLED,
false)) {
message.getInterceptorChain().add(new CheckClosingTagsInterceptor());
}
}
} catch (XMLStreamException e) {
throw new SoapFault(new Message("XML_STREAM_EXC", LOG), e, message.getVersion().getSender());
}
}