You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Andreas Veithen (JIRA)" <ji...@apache.org> on 2008/12/18 15:47:44 UTC

[jira] Updated: (AXIS2-3555) Axis 2 SAAJ + java XPath expressions (javax.xml.xpath)

     [ https://issues.apache.org/jira/browse/AXIS2-3555?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Veithen updated AXIS2-3555:
-----------------------------------

    Attachment: AXIS2-3555-incomplete.patch.txt

I tested this and the root cause is an inconsistency in the DOM tree produced by axis2-saaj. Normally, one would expect that the owner document of a DOM node is the same as the root of the DOM tree to which it is attached. This is exactly the assumption that Xalan makes and that's why it fails. With a DOM tree produced by axis2-saaj the situation is as follows:

* The root of the tree is a SOAPPartImpl (SAAJ's SOAPPart interface indeed extends org.w3c.dom.Document).
* When calling getOwnerDocument on a DOM node in the tree, a bare org.apache.axiom.om.impl.dom.DocumentImpl is returned.

There are two ways to solve this:

1) Change getOwnerDocument so that it returns a reference to the SOAPPart.
2) Change SOAPEnvelopeImpl so that getParentNode returns the same reference as getOwnerDocument.

I tried to implement solution 1, which seems the natural solution (though I don't know what the SAAJ specs say about this). I succeeded in making XPath work, but the patch (see the attached AXIS2-3555-incomplete.patch.txt) causes several regressions in the unit tests.

After that I cross-checked with Sun's SAAJ implementation to see how they do it, and surprisingly the behavior is equivalent to solution 2. This can be checked using the following code:

        SOAPMessage msg = MessageFactory.newInstance().createMessage();
        SOAPPart part = msg.getSOAPPart();
        SOAPEnvelope env = part.getEnvelope();
        System.out.println(part.createElement("test").getOwnerDocument().getClass());
        System.out.println(env.getParentNode().getClass());
        System.out.println(env.getOwnerDocument().getClass());

With Sun's SAAJ implementation, the output is:

class com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl
class com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl
class com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl

This shows that the DOM tree is consistent, but that the root and owner document is not the SOAPPart, but some other SOAPDocument instance.

Maybe some SAAJ specialist can comment?

> Axis 2 SAAJ + java XPath expressions (javax.xml.xpath)
> ------------------------------------------------------
>
>                 Key: AXIS2-3555
>                 URL: https://issues.apache.org/jira/browse/AXIS2-3555
>             Project: Axis 2.0 (Axis2)
>          Issue Type: Bug
>    Affects Versions: 1.3
>         Environment: jdk5
>            Reporter: Nikita Rybak
>         Attachments: AXIS2-3555-incomplete.patch.txt
>
>
> Any attemp to use axis 2 with XPath expressions from javax.xml.xpath leads to an error like this:
> java.lang.ClassCastException: org.apache.axiom.om.impl.dom.DocumentImpl
>         at org.apache.axis2.saaj.NodeImplEx.toSAAJNode2(NodeImplEx.java:260)
>         at org.apache.axis2.saaj.NodeImplEx.toSAAJNode(NodeImplEx.java:181)
>         at org.apache.axis2.saaj.SOAPElementImpl.getParentElement(SOAPElementImpl.java:723)
>         at org.apache.axis2.saaj.SOAPElementImpl.getParentNode(SOAPElementImpl.java:778)
>         at com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault.getDTMHandleFromNode(DTMManagerDefault.java:534)
>         at com.sun.org.apache.xpath.internal.XPathContext.getDTMHandleFromNode(XPathContext.java:154)
>         at com.sun.org.apache.xpath.internal.XPath.execute(XPath.java:234)
>         at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:123)
>         at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:97)
>         at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:178)
>         at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:223)
>         at Demo.test2(Demo.java:207)
> Sample you can try:
> message = MessageFactory.newInstance().createMessage();
> soapBody = message.getSOAPBody().addBodyElement(new QName("namespace", "root"));
> path = "name(.)";
> xp = XPathFactory.newInstance().newXPath().compile(path);
> System.out.println("|" + xp.evaluate(soapBody) + "|");
> If you think empty body may cause this, fill it: nothing will change. Of use not body, usual SOAPElement: all the same.  No need to say, XPath works fine with java's native DOM.
> Thank you.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.