Axis2
  1. Axis2
  2. AXIS2-5071

Failure to populate all members of an xs:sequence in a SOAP header

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.5, 1.6.0
    • Fix Version/s: 1.5.6, 1.6.1, 1.7.0
    • Component/s: kernel
    • Labels:
      None
    • Environment:
      MacOSX Leopard, Apache AXIS 1.6.0, Java 1.6.0_24

      Description

      There is a soap header declared in the wsdl that points to an element:

      <xs:element name="authentication">
      <xs:complexType>
      <xs:sequence>
      <xs:element name="username" type="xs:string"/>
      <xs:element name="password" type="xs:string"/>
      </xs:sequence>
      <xs:anyAttribute namespace="##other"/>
      </xs:complexType>
      </xs:element>

      After running "sh wsdl2java.sh -uri <uri>" to create stubs, and I populate that element with:

      MyTestServiceStub stub = new MyTestServiceStub();
      MyTestServiceStub.Authentication auth = new MyTestServiceStub.Authentication();
      auth.setUsername( "username" );
      auth.setPassword( "password" );
      stub.operation( new MyTestServiceStub.Operation(), auth, null );

      The following SOAP envelope is sent:

      <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header><ns1:authentication xmlns:ns1="urn:mytest" soapenv:mustUnderstand="false"><ns1:username>username</ns1:username></ns1:authentication></soapenv:Header><soapenv:Body><ns1:operation xmlns:ns1="urn:mytest" /></soapenv:Body></soapenv:Envelope>

      Notice the supplied password element is missing.

      Screenshot attached.

      1. mytest.wsdl
        4 kB
        David Green-Lank
      2. Screen shot 2011-06-10 at 8.11.15 AM.png
        292 kB
        David Green-Lank

        Issue Links

          Activity

          Hide
          David Green-Lank added a comment - - edited

          After spending some time getting the AXIS source code and debugging this, I have narrowed it down to the following code in Stub#addHeader():

          OMNode omNode = null;

          // add child elements
          for (Iterator iter = omElementToadd.getChildren(); iter.hasNext()

          { omNode = (OMNode) iter.next(); // after this line executes, iter.hasNext() returns true (and unintentionally resolves the issue due to a side effect) soapHeaderBlock.addChild(omNode); // after this line executes, iter.hasNext() returns false }

          So adding the omNode to the SOAP header causes a side effect on the iterator, and the <password> element is never added.

          My guess is that when an omNode is added to a new parent, it's removed from the old parent, and therefore, when the <username> element is added to the header, the <password> element shifts to position #0, and therefore iter.hasNext() returns false since there is no child at index 1 anymore. But that's just a guess, I didn't download the axiom source code.

          The following replacement code resolves the issue:

          // add child elements. make a safe copy first, since adding the OMNode to the SOAP envelope causes a side
          // effect on the iterator
          List<OMNode> nodesToAdd = new ArrayList<OMNode>();
          for (Iterator iter = omElementToadd.getChildren(); iter.hasNext()

          { OMNode omNode = (OMNode) iter.next(); nodesToAdd.add( omNode ); }

          for ( OMNode omNode : nodesToAdd )

          { soapHeaderBlock.addChild( omNode ); }
          Show
          David Green-Lank added a comment - - edited After spending some time getting the AXIS source code and debugging this, I have narrowed it down to the following code in Stub#addHeader(): OMNode omNode = null; // add child elements for (Iterator iter = omElementToadd.getChildren(); iter.hasNext() { omNode = (OMNode) iter.next(); // after this line executes, iter.hasNext() returns true (and unintentionally resolves the issue due to a side effect) soapHeaderBlock.addChild(omNode); // after this line executes, iter.hasNext() returns false } So adding the omNode to the SOAP header causes a side effect on the iterator, and the <password> element is never added. My guess is that when an omNode is added to a new parent, it's removed from the old parent, and therefore, when the <username> element is added to the header, the <password> element shifts to position #0, and therefore iter.hasNext() returns false since there is no child at index 1 anymore. But that's just a guess, I didn't download the axiom source code. The following replacement code resolves the issue: // add child elements. make a safe copy first, since adding the OMNode to the SOAP envelope causes a side // effect on the iterator List<OMNode> nodesToAdd = new ArrayList<OMNode>(); for (Iterator iter = omElementToadd.getChildren(); iter.hasNext() { OMNode omNode = (OMNode) iter.next(); nodesToAdd.add( omNode ); } for ( OMNode omNode : nodesToAdd ) { soapHeaderBlock.addChild( omNode ); }
          Hide
          David Green-Lank added a comment - - edited

          Keep in mind that you can't actually check the value of iter.hasNext() before adding the node in the original code, without causing another side effect on the iterator to cache the next node of the iterator, thereby resolving the problem as a result of the side effect

          Show
          David Green-Lank added a comment - - edited Keep in mind that you can't actually check the value of iter.hasNext() before adding the node in the original code, without causing another side effect on the iterator to cache the next node of the iterator, thereby resolving the problem as a result of the side effect
          Hide
          David Green-Lank added a comment - - edited

          This problem doesn't seem to exist in 1.5.4, looks like a 1.6.0 regression

          Show
          David Green-Lank added a comment - - edited This problem doesn't seem to exist in 1.5.4, looks like a 1.6.0 regression
          Hide
          Andreas Veithen added a comment - - edited

          David,

          Thanks for the detailed analysis. The issue is actually a side effect of the changes introduced by AXIOM-333, which are explained in more details in the Axiom user guide [1]. This means that all Axis2 versions shipping with Axiom 1.2.11 are affected by this, i.e. 1.5.5 and 1.6.0. The best fix for this is to call Iterator#remove() before moving the node.

          I think that we should also improve Axiom so that it throws a ConcurrentModificationException in this case (exactly as the iterators from the Java 2 collection framework).

          [1] http://ws.apache.org/axiom/userguide/ch04.html#iterator-changes

          Show
          Andreas Veithen added a comment - - edited David, Thanks for the detailed analysis. The issue is actually a side effect of the changes introduced by AXIOM-333 , which are explained in more details in the Axiom user guide [1] . This means that all Axis2 versions shipping with Axiom 1.2.11 are affected by this, i.e. 1.5.5 and 1.6.0. The best fix for this is to call Iterator#remove() before moving the node. I think that we should also improve Axiom so that it throws a ConcurrentModificationException in this case (exactly as the iterators from the Java 2 collection framework). [1] http://ws.apache.org/axiom/userguide/ch04.html#iterator-changes
          Hide
          Hudson added a comment -

          Integrated in Axis2 #802 (See https://builds.apache.org/job/Axis2/802/)
          Fixed a couple of incorrect iterator usages, including AXIS2-5071.

          veithen :
          Files :

          • /axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/MultirefHelper.java
          • /axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/client/Stub.java
          Show
          Hudson added a comment - Integrated in Axis2 #802 (See https://builds.apache.org/job/Axis2/802/ ) Fixed a couple of incorrect iterator usages, including AXIS2-5071 . veithen : Files : /axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/MultirefHelper.java /axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/client/Stub.java
          Hide
          Hudson added a comment -

          Integrated in axis2-1.5 #148 (See https://builds.apache.org/job/axis2-1.5/148/)
          AXIS2-5071: Merged r1134438 to the 1.5 branch.

          veithen :
          Files :

          • /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module/pom.xml
          • /axis/axis2/java/core/branches/1_5/modules/kernel/src/org/apache/axis2/client/Stub.java
          • /axis/axis2/java/core/branches/1_5/modules/transport/http/pom.xml
          • /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module/src/main/java/org/apache/axis2/handlers
          • /axis/axis2/java/core/branches/1_5
          • /axis/axis2/java/core/branches/1_5/modules/saaj/test/org/apache/axis2/saaj/TestUtils.java
          • /axis/axis2/java/core/branches/1_5/modules/kernel/src/org/apache/axis2/transport/http/util/QueryStringParser.java
          • /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module/src/main/resources/META-INF/module.xml
          • /axis/axis2/java/core/branches/1_5/modules/kernel/test/org/apache/axis2/transport/http/util/QueryStringParserTest.java
          • /axis/axis2/java/core/branches/1_5/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet
          • /axis/axis2/java/core/branches/1_5/modules/adb/src/org/apache/axis2/databinding/utils/MultirefHelper.java
          • /axis/axis2/java/core/branches/1_5/modules/tool/axis2-repo-maven-plugin
          • /axis/axis2/java/core/branches/1_5/modules/transport/http/src
          • /axis/axis2/java/core/branches/1_5/modules/distribution
          • /axis/axis2/java/core/branches/1_5/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/applet
          • /axis/axis2/java/core/branches/1_5/modules/transport/local
          • /axis/axis2/java/core/branches/1_5/modules/webapp/src/main/java/org/apache/axis2/webapp/AxisAdminServlet.java
          • /axis/axis2/java/core/branches/1_5/modules/soapmonitor/servlet
          • /axis/axis2/java/core/branches/1_5/modules/webapp/src/main/java/org/apache/axis2/webapp/AdminAgent.java
          • /axis/axis2/java/core/branches/1_5/modules/parent
          • /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module
          Show
          Hudson added a comment - Integrated in axis2-1.5 #148 (See https://builds.apache.org/job/axis2-1.5/148/ ) AXIS2-5071 : Merged r1134438 to the 1.5 branch. veithen : Files : /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module/pom.xml /axis/axis2/java/core/branches/1_5/modules/kernel/src/org/apache/axis2/client/Stub.java /axis/axis2/java/core/branches/1_5/modules/transport/http/pom.xml /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module/src/main/java/org/apache/axis2/handlers /axis/axis2/java/core/branches/1_5 /axis/axis2/java/core/branches/1_5/modules/saaj/test/org/apache/axis2/saaj/TestUtils.java /axis/axis2/java/core/branches/1_5/modules/kernel/src/org/apache/axis2/transport/http/util/QueryStringParser.java /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module/src/main/resources/META-INF/module.xml /axis/axis2/java/core/branches/1_5/modules/kernel/test/org/apache/axis2/transport/http/util/QueryStringParserTest.java /axis/axis2/java/core/branches/1_5/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/servlet /axis/axis2/java/core/branches/1_5/modules/adb/src/org/apache/axis2/databinding/utils/MultirefHelper.java /axis/axis2/java/core/branches/1_5/modules/tool/axis2-repo-maven-plugin /axis/axis2/java/core/branches/1_5/modules/transport/http/src /axis/axis2/java/core/branches/1_5/modules/distribution /axis/axis2/java/core/branches/1_5/modules/soapmonitor/servlet/src/main/java/org/apache/axis2/soapmonitor/applet /axis/axis2/java/core/branches/1_5/modules/transport/local /axis/axis2/java/core/branches/1_5/modules/webapp/src/main/java/org/apache/axis2/webapp/AxisAdminServlet.java /axis/axis2/java/core/branches/1_5/modules/soapmonitor/servlet /axis/axis2/java/core/branches/1_5/modules/webapp/src/main/java/org/apache/axis2/webapp/AdminAgent.java /axis/axis2/java/core/branches/1_5/modules/parent /axis/axis2/java/core/branches/1_5/modules/soapmonitor/module

            People

            • Assignee:
              Andreas Veithen
              Reporter:
              David Green-Lank
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development