if (xmlReader == null) {
throw new NullPointerException("No xml reader found");
}
try {
QName name = xmlReader.getName();
SoapVersion soapVersion = this.soapVersion;
if (soapVersion == null) {
soapVersion = message.get(SoapVersion.class);
}
if (soapVersion == null) {
soapVersion = SoapVersionFactory.getInstance().getSoapVersion(name);
} else {
soapVersion = soapVersion.getDerivedVersion(name.getPrefix());
}
if (soapVersion == null) {
throw new SoapFault(SoapConstants.SOAP_12_CODE_VERSIONMISMATCH, "Unrecognized namespace: "
+ xmlReader.getNamespaceURI() + " at ["
+ xmlReader.getLocation().getLineNumber() + ","
+ xmlReader.getLocation().getColumnNumber()
+ "]. Expecting a Soap 1.1 or 1.2 namespace.");
}
message.put(SoapVersion.class, soapVersion);
if (!name.equals(soapVersion.getEnvelope())) {
if (name.getLocalPart().equals(soapVersion.getEnvelope().getLocalPart())) {
throw new SoapFault(SoapConstants.SOAP_12_CODE_VERSIONMISMATCH,
"Expected a SOAP " + soapVersion.getVersion() + " request");
}
throw new SoapFault(SoapConstants.SOAP_12_CODE_VERSIONMISMATCH, "Unrecognized element: "
+ xmlReader.getName() + " at ["
+ xmlReader.getLocation().getLineNumber() + ","
+ xmlReader.getLocation().getColumnNumber()
+ "]. Expecting 'Envelope'.");
}
xmlReader.nextTag();
if (xmlReader.getName().equals(soapVersion.getHeader())) {
Map<QName, DocumentFragment> headers = message.getSoapHeaders();
while (xmlReader.nextTag() != XMLStreamConstants.END_ELEMENT) {
QName hn = xmlReader.getName();
Element e = StaxUtil.createElement(xmlReader);
DocumentFragment df = headers.get(hn);
if (df == null) {
df = e.getOwnerDocument().createDocumentFragment();
}
e = (Element) df.getOwnerDocument().importNode(e, true);
df.appendChild(e);
headers.put(hn, df);
}
xmlReader.nextTag();
}
if (!xmlReader.getName().equals(soapVersion.getBody())) {
throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
+ xmlReader.getName() + ". Expecting 'Body'.");
}
if (xmlReader.nextTag() == XMLStreamConstants.END_ELEMENT) {
// Empty body