Axiom
  1. Axiom
  2. AXIOM-357

org.apache.axiom.om.util.CopyUtils throws NPE when used to copy a SOAPEnvelope containing a SOAP 1.1 SOAPFault

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.11
    • Fix Version/s: 1.2.14
    • Component/s: API
    • Labels:
      None
    • Environment:
      All

      Description

      NPE when using CopyUtils.copy on a SOAPEnvelope containing a SOAP 1.1 SOAPFault.
      This is because the copySOAPFaultCode method assumes that the SOAPFaultCode has a Value child element, but that's only true for SOAP 1.2.
      In SOAP 1.1 the SOAPFault contains a text element, not a Value element.

      I have a patch available where I copy the text or Value based on the namespace of the SOAPFactory.

        Issue Links

          Activity

          Daniel James Matthews created issue -
          Daniel James Matthews made changes -
          Field Original Value New Value
          Link This issue blocks SANDESHA2-208 [ SANDESHA2-208 ]
          Hide
          Andreas Veithen added a comment -

          Daniel, can you provide a unit test that reproduces the issue?

          Show
          Andreas Veithen added a comment - Daniel, can you provide a unit test that reproduces the issue?
          Hide
          Daniel James Matthews added a comment -

          Andreas, the following method can be added to org.apache.axiom.om.util.CopyUtilsTest.java in axiom\modules\axiom-tests\src\test\java\org\apache\axiom\om\util...

          public void testSoap11fault() throws Exception

          { copyAndCheck(createEnvelope(getTestResource("soap/soap11/soap11fault.xml")), true); }

          This will show the bug.

          A possible fix for the bug is to update the copySOAPFaultCode method in CopyUtils.java as follows...

          private static void copySOAPFaultCode(SOAPFactory factory,
          SOAPFault targetFault,
          SOAPFaultCode sourceCode) {
          SOAPFaultCode targetCode = factory.createSOAPFaultCode(targetFault);
          copyTagData(sourceCode, targetCode);

          if(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(factory.getSoapVersionURI()))

          { targetCode.setText(sourceCode.getText()); }

          else {
          // Create the Value
          SOAPFaultValue sourceValue = sourceCode.getValue();
          if(sourceValue != null) {
          SOAPFaultValue targetValue = factory.createSOAPFaultValue(targetCode);
          copyTagData(sourceValue, targetValue);

          // There should only be a text node for the value, but in case there is more
          Iterator i = sourceValue.getChildren();
          while (i.hasNext())

          { OMNode node = (OMNode) i.next(); copy(factory, targetValue, node); }

          }
          }

          // Now get process the SubCode
          SOAPFaultSubCode sourceSubCode = sourceCode.getSubCode();
          if (sourceSubCode != null)

          { copySOAPFaultSubCode(factory, targetCode, sourceSubCode); }

          }

          Show
          Daniel James Matthews added a comment - Andreas, the following method can be added to org.apache.axiom.om.util.CopyUtilsTest.java in axiom\modules\axiom-tests\src\test\java\org\apache\axiom\om\util... public void testSoap11fault() throws Exception { copyAndCheck(createEnvelope(getTestResource("soap/soap11/soap11fault.xml")), true); } This will show the bug. A possible fix for the bug is to update the copySOAPFaultCode method in CopyUtils.java as follows... private static void copySOAPFaultCode(SOAPFactory factory, SOAPFault targetFault, SOAPFaultCode sourceCode) { SOAPFaultCode targetCode = factory.createSOAPFaultCode(targetFault); copyTagData(sourceCode, targetCode); if(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(factory.getSoapVersionURI())) { targetCode.setText(sourceCode.getText()); } else { // Create the Value SOAPFaultValue sourceValue = sourceCode.getValue(); if(sourceValue != null) { SOAPFaultValue targetValue = factory.createSOAPFaultValue(targetCode); copyTagData(sourceValue, targetValue); // There should only be a text node for the value, but in case there is more Iterator i = sourceValue.getChildren(); while (i.hasNext()) { OMNode node = (OMNode) i.next(); copy(factory, targetValue, node); } } } // Now get process the SubCode SOAPFaultSubCode sourceSubCode = sourceCode.getSubCode(); if (sourceSubCode != null) { copySOAPFaultSubCode(factory, targetCode, sourceSubCode); } }
          Andreas Veithen made changes -
          Assignee Andreas Veithen [ veithen ]
          Fix Version/s 1.2.12 [ 12316132 ]
          Affects Version/s 1.2.11 [ 12315534 ]
          Component/s API [ 12313878 ]
          Hide
          David Illsley added a comment -

          Hi Dan, I'm a little concerned about just copying the string across in case the prefix is different, unless elsewhere in the copy cope it's guaranteed to be the same?

          Show
          David Illsley added a comment - Hi Dan, I'm a little concerned about just copying the string across in case the prefix is different, unless elsewhere in the copy cope it's guaranteed to be the same?
          Andreas Veithen made changes -
          Fix Version/s 1.2.13 [ 12316677 ]
          Fix Version/s 1.2.12 [ 12316132 ]
          Andreas Veithen made changes -
          Fix Version/s 1.2.14 [ 12318340 ]
          Fix Version/s 1.2.13 [ 12316677 ]
          Andreas Veithen made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          Hudson added a comment -

          Integrated in ws-axiom-trunk #967 (See https://builds.apache.org/job/ws-axiom-trunk/967/)
          Added unit test provided by Daniel James Matthews for AXIOM-357. With the changes in r1339012 the issue no longer occurs. (Revision 1339023)

          Result = SUCCESS
          veithen :
          Files :

          • /webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/CopyUtilsTest.java
          Show
          Hudson added a comment - Integrated in ws-axiom-trunk #967 (See https://builds.apache.org/job/ws-axiom-trunk/967/ ) Added unit test provided by Daniel James Matthews for AXIOM-357 . With the changes in r1339012 the issue no longer occurs. (Revision 1339023) Result = SUCCESS veithen : Files : /webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/CopyUtilsTest.java
          Andreas Veithen made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Gavin made changes -
          Link This issue blocks SANDESHA2-208 [ SANDESHA2-208 ]
          Gavin made changes -
          Link This issue is depended upon by SANDESHA2-208 [ SANDESHA2-208 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open In Progress In Progress
          445d 17h 6m 1 Andreas Veithen 16/May/12 07:10
          In Progress In Progress Resolved Resolved
          32m 48s 1 Andreas Veithen 16/May/12 07:43

            People

            • Assignee:
              Andreas Veithen
              Reporter:
              Daniel James Matthews
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 4h
                4h
                Remaining:
                Remaining Estimate - 4h
                4h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development