Project

Profile

Help

Issue using Saxon to parse soap envelope with signature element

Added by Sandro DOrazio almost 11 years ago

Hi,

Im usig Saxon He 9.4.0.7 as to parse SAAJ Soap messages. The soap message is signed ad it's header contains the following element :

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header xmlns:ec1="ec:schema:xsd:CommonAggregateComponents-2" xmlns:stan="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:ec="ec:services:wsdl:InboxRequest-2"> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" SOAP-ENV:mustUnderstand="1" wsu:Id="XWSSGID-1369143332378-552040088"> <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="XWSSGID-1369143331937-901713402">....

		<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
			*Id*="XWSSGID-1369143331937776557424">
                   ....

My issue is related with the <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="XWSSGID-1369143331937776557424"> element. The Id attribute seems to be problematic here. This attribute is valid according to the xsd however during the parsing by saxon the following error occurs :

15:38:09,690 ERROR [stderr] (http--127.0.0.1-8080-3) Error 15:38:09,690 ERROR [stderr] (http--127.0.0.1-8080-3) org.w3c.dom.DOMException: NOT_FOUND_ERR: An attempt is made to reference a node in a 15:38:09,690 ERROR [stderr] (http--127.0.0.1-8080-3) context where it does not exist. 15:38:09,690 SEVERE [com.sun.xml.messaging.saaj.soap] (http--127.0.0.1-8080-3) SAAJ0511: Unable to create envelope from given source 15:38:09,690 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/etrustex].[services]] (http--127.0.0.1-8080-3) Servlet.service() for servlet services threw exception: org.w3c.dom.DOMException: NOT_FOUND_ERR: An attempt is made to reference a node in a context where it d t exist. at org.apache.xerces.dom.ElementImpl.setIdAttributeNS(ElementImpl.java:1000) [xercesImpl-2.9.1.jar:] at net.sf.saxon.dom.DOMWriter.attribute(DOMWriter.java:154) [Saxon-HE-9.4.0.7.jar:] at net.sf.saxon.event.ProxyReceiver.attribute(ProxyReceiver.java:158) [Saxon-HE-9.4.0.7.jar:] at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:340) [Saxon-HE-9.4.0.7.jar:] at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527) [rt.jar:1.6.0_35] at com.sun.xml.messaging.saaj.util.RejectDoctypeSaxFilter.startElement(RejectDoctypeSaxFilter.java:192) at org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:496) [xercesImpl-2.9.1.jar:]

I have been debugging a bit the code and the issue is that the parser recognises the Id attribute as an "id" and calls the ElementImpl.setIdAttributeNS so that id attribute will be usable as parameter for the getElementById method call. In this specific case the namespace of the attribute is not determined by the ReceivingContentHandler and it causes the Not found error. Same mechanism happens with other attributes in the message the wsu:Id. In this case it works. If I manually change the xml before submitting it to prefix the Id attribute with ds: it also works.

I'm not an xml expert however i do think that prefixing the Id attribute inside the <ds:Signature is not mandatory and that it should work. Any advise or opinion on that behaviour would be really appreciated.

Thanks


Replies (3)

Please register to reply

RE: Issue using Saxon to parse soap envelope with signature element - Added by Michael Kay almost 11 years ago

I suspect the problem is that Saxon is passing "" (zero-length string) as the URI parameter to setIdAttributeNS() when the method is expecting null. The specification isn't explicit about what should be passed but the usual DOM convention is to use null.

I'm wondering a little bit what you are trying to achieve here.

(a) why are you constructing a DOM? It's the least efficient data structure you could use if all you want to do is run a transformation.

(b) why are you using Saxon to build it? To build a DOM from the events emitted by a SAX parser, you don't need Saxon in the loop. The ability of Saxon to write a DOM (which you are using) is primarily there so that the result of a transformation can be written to a DOM.

RE: Issue using Saxon to parse soap envelope with signature element - Added by Sandro DOrazio almost 11 years ago

Hi,

Indeed Saxon is passing the "" zero length string to the setIdAttributeNS.

I'm implementing web services using spring webservices framework. The incoming soap messages are transformed to javax.xml.soap.SOAPMessage messages by the framework. I'm not using Saxon explicitly for that, i'm using saxon to do queries and transformations inside my application so the library is in my class path. I was not even aware that Saxon was used for creating the soap message until I added signature to my endpoints an the problem with the Id element occurred. I guess that it is loaded because of the following service provider config file javax.xml.transform.TransformerFactory.

I've upgraded my Saxon version to 9.5.0.1 and it works perfectly fine now.

Thanks al lot

    (1-3/3)

    Please register to reply