Axiom
  1. Axiom
  2. AXIOM-376

Axiom should report conflicting namespace declarations

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.2.12
    • Fix Version/s: 1.2.16
    • Component/s: None
    • Labels:
      None

      Description

      Consider the following code:

      OMFactory factory = OMAbstractFactory.getOMFactory();
      OMNamespace ns = factory.createOMNamespace("urn:ns1", "p");
      OMElement parent = factory.createOMElement("parent", ns);
      OMElement child = factory.createOMElement("child", ns, parent);
      child.declareNamespace("urn:ns2", "p");
      System.out.println("XML = " + parent);
      System.out.println("URI = " + child.getNamespaceURI());

      Both elements are created in the urn:ns1 namespace. An attempt is made to add a namespace declaration that binds the prefix to a different namespace. No error occurs and the output is as follows:

      XML = <p:parent xmlns="urn:ns1"><p:child xmlns="urn:ns2" /></p:parent>
      URI = urn:ns1

      This means that in the serialized document, the namespace of the child element is different than in the object model. This situation (which is expected to be accidental in most cases) will lead to subtle issues later.

      Axiom should make sure that the namespaces of element and attribute information items are always preserved and trigger an exception if this constraint is violated by a conflicting namespace declaration.

      These checks can be implemented at two levels:

      • In the serializer. This is the most robust solution, but makes it more difficult to identify the code that is responsible for the conflicting declaration (because it is only detected later).
      • In the declareNamespace and declareDefaultNamespace methods.

        Issue Links

          Activity

          Andreas Veithen created issue -
          Andreas Veithen made changes -
          Field Original Value New Value
          Link This issue is related to AXIOM-28 [ AXIOM-28 ]
          Andreas Veithen made changes -
          Fix Version/s 1.2.14 [ 12318340 ]
          Andreas Veithen made changes -
          Summary The serializer should report conflicting namespace declarations Axiom should report conflicting namespace declarations
          Description Consider the following code:

          OMFactory factory = OMAbstractFactory.getOMFactory();
          OMNamespace ns = factory.createOMNamespace("urn:ns1", "p");
          OMElement parent = factory.createOMElement("parent", ns);
          OMElement child = factory.createOMElement("child", ns, parent);
          child.declareNamespace("urn:ns2", "p");
          System.out.println("XML = " + parent);
          System.out.println("URI = " + child.getNamespaceURI());

          Both elements are created in the urn:ns1 namespace. An attempt is made to add a namespace declaration that binds the prefix to a different namespace. No error occurs and the output is as follows:

          XML = <p:parent xmlns:p="urn:ns1"><p:child xmlns:p="urn:ns2" /></p:parent>
          URI = urn:ns1

          This means that in the serialized document, the namespace of the child element is different than in the object model. This situation (which is expected to be accidental in most cases) will lead to subtle issues later.

          The serializer should make sure that the namespaces of element and attribute information items are always preserved and trigger an exception if this constraint is violated by a conflicting namespace declaration.
          Consider the following code:

          OMFactory factory = OMAbstractFactory.getOMFactory();
          OMNamespace ns = factory.createOMNamespace("urn:ns1", "p");
          OMElement parent = factory.createOMElement("parent", ns);
          OMElement child = factory.createOMElement("child", ns, parent);
          child.declareNamespace("urn:ns2", "p");
          System.out.println("XML = " + parent);
          System.out.println("URI = " + child.getNamespaceURI());

          Both elements are created in the urn:ns1 namespace. An attempt is made to add a namespace declaration that binds the prefix to a different namespace. No error occurs and the output is as follows:

          XML = <p:parent xmlns:p="urn:ns1"><p:child xmlns:p="urn:ns2" /></p:parent>
          URI = urn:ns1

          This means that in the serialized document, the namespace of the child element is different than in the object model. This situation (which is expected to be accidental in most cases) will lead to subtle issues later.

          Axiom should make sure that the namespaces of element and attribute information items are always preserved and trigger an exception if this constraint is violated by a conflicting namespace declaration.

          These checks can be implemented at two levels:
          * In the serializer. This is the most robust solution, but makes it more difficult to identify the code that is responsible for the conflicting declaration (because it is only detected later).
          * In the declareNamespace and declareDefaultNamespace methods.
          Hide
          Hudson added a comment -

          Integrated in ws-axiom-trunk #690 (See https://builds.apache.org/job/ws-axiom-trunk/690/)

          • AXIOM-28: Don't allow declareDefaultNamespace to change the namespace of the element.
          • AXIOM-376: Throw an exception if an attempt is made to use declareDefaultNamespace to add a conflicting namespace declaration (in particular in the case considered in AXIOM-28).
          • Changed the code in the builder to bypass these checks internally (so that they only apply when manipulating the OM tree programmatically).
          • Fixed a couple of test cases that were attempting to create conflicting namespace declarations.

          veithen :
          Files :

          • /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringGrandParentsDefaultNSWithPrefix.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringParentsDefaultNSWithPrefix.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespace1.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.java
          • /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestMultipleDefaultNS.java
          Show
          Hudson added a comment - Integrated in ws-axiom-trunk #690 (See https://builds.apache.org/job/ws-axiom-trunk/690/ ) AXIOM-28 : Don't allow declareDefaultNamespace to change the namespace of the element. AXIOM-376 : Throw an exception if an attempt is made to use declareDefaultNamespace to add a conflicting namespace declaration (in particular in the case considered in AXIOM-28 ). Changed the code in the builder to bypass these checks internally (so that they only apply when manipulating the OM tree programmatically). Fixed a couple of test cases that were attempting to create conflicting namespace declarations. veithen : Files : /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMElementEx.java /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAPBuilderHelper.java /webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java /webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java /webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringGrandParentsDefaultNSWithPrefix.java /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestChildReDeclaringParentsDefaultNSWithPrefix.java /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespace1.java /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict1.java /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareDefaultNamespaceConflict2.java /webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestMultipleDefaultNS.java
          Hide
          Hudson added a comment -

          Integrated in Axis2 #1107 (See https://builds.apache.org/job/Axis2/1107/)
          Fixed an issue in SAAJ revealed by AXIOM-376.

          veithen :
          Files :

          • /axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java
          • /axis/axis2/java/core/trunk/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
          Show
          Hudson added a comment - Integrated in Axis2 #1107 (See https://builds.apache.org/job/Axis2/1107/ ) Fixed an issue in SAAJ revealed by AXIOM-376 . veithen : Files : /axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java /axis/axis2/java/core/trunk/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
          Andreas Veithen made changes -
          Fix Version/s 1.2.15 [ 12318876 ]
          Fix Version/s 1.2.14 [ 12318340 ]
          Andreas Veithen made changes -
          Fix Version/s 1.2.16 [ 12323263 ]
          Fix Version/s 1.2.15 [ 12318876 ]

            People

            • Assignee:
              Andreas Veithen
              Reporter:
              Andreas Veithen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development