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 di...@apache.org on 2005/08/20 22:49:29 UTC

cvs commit: ws-axis/java/test/utils TestNSStack.java TestXMLUtils.java

dims        2005/08/20 13:49:29

  Modified:    java/src/org/apache/axis/message EnvelopeBuilder.java
                        MessageElement.java NodeImpl.java SOAPBody.java
                        SOAPEnvelope.java SOAPHeader.java Text.java
               java/test/encoding TestDOM.java
               java/test/utils TestNSStack.java TestXMLUtils.java
  Log:
  Fix for AXIS-2139 - SAX recorder is dirty after deserialization
  
  - we now call envelope's reset() in EnvelopeBuilder
  - adding a setDirty(). setDirty(true) as behaves weirdly (JIT problem?)
  - use setIgnoreWhitespace for some unit tests
  - adding a test case for this problem
  
  Revision  Changes    Path
  1.38      +7 -5      ws-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java
  
  Index: EnvelopeBuilder.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/EnvelopeBuilder.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- EnvelopeBuilder.java	20 Jun 2005 22:49:44 -0000	1.37
  +++ EnvelopeBuilder.java	20 Aug 2005 20:49:28 -0000	1.38
  @@ -25,6 +25,7 @@
   import org.apache.axis.MessageContext;
   
   import javax.xml.namespace.QName;
  +import javax.xml.soap.SOAPException;
   
   /**
    * The EnvelopeBuilder is responsible for parsing the top-level
  @@ -69,13 +70,13 @@
           if (!localName.equals(Constants.ELEM_ENVELOPE))
               throw new SAXException(
                       Messages.getMessage("badTag00", localName));
  -        
  +
           // See if we're only supporting a single SOAP version at this endpoint
           MessageContext msgContext = context.getMessageContext();
           SOAPConstants singleVersion = null;
           if (msgContext != null) {
               singleVersion = (SOAPConstants)msgContext.getProperty(
  -                                            Constants.MC_SINGLE_SOAP_VERSION); 
  +                                            Constants.MC_SINGLE_SOAP_VERSION);
           }
   
           if (namespace.equals(Constants.URI_SOAP11_ENV)) {
  @@ -87,17 +88,17 @@
           } else {
               soapConstants = null;
           }
  -        
  +
           if ((soapConstants == null) ||
                   (singleVersion != null && soapConstants != singleVersion)) {
               // Mismatch of some sort, either an unknown namespace or not
               // the one we want.  Send back an appropriate fault.
  -            
  +
               // Right now we only send back SOAP 1.1 faults for this case.  Do
               // we want to send SOAP 1.2 faults back to SOAP 1.2 endpoints?
               soapConstants = SOAPConstants.SOAP11_CONSTANTS;
               if (singleVersion == null) singleVersion = soapConstants;
  -            
  +
               try {
                   AxisFault fault = new AxisFault(soapConstants.getVerMismatchFaultCodeQName(),
                       null, Messages.getMessage("versionMissmatch00"), null, null, null);
  @@ -201,5 +202,6 @@
           // Envelope isn't dirty yet by default...
           envelope.setDirty(false);
           envelope.setRecorded(true);
  +        envelope.reset();
       }
   }
  
  
  
  1.201     +3 -3      ws-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.200
  retrieving revision 1.201
  diff -u -r1.200 -r1.201
  --- MessageElement.java	1 Aug 2005 13:33:23 -0000	1.200
  +++ MessageElement.java	20 Aug 2005 20:49:28 -0000	1.201
  @@ -667,7 +667,7 @@
               }
               // empty the collection
               children.clear();
  -            setDirty(true);
  +            setDirty();
           }
       }
   
  @@ -1031,7 +1031,7 @@
        */
       public void setEnvelope(SOAPEnvelope env)
       {
  -        env.setDirty(true);
  +        env.setDirty();
           message = env;
       }
   
  @@ -1371,7 +1371,7 @@
           throws SOAPException {
           try {
               addChild((MessageElement)element);
  -            setDirty(true);
  +            setDirty();
               return element;
           } catch (ClassCastException e) {
               throw new SOAPException(e);
  
  
  
  1.18      +16 -7     ws-axis/java/src/org/apache/axis/message/NodeImpl.java
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/NodeImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- NodeImpl.java	3 Aug 2005 10:26:28 -0000	1.17
  +++ NodeImpl.java	20 Aug 2005 20:49:28 -0000	1.18
  @@ -493,7 +493,7 @@
           ((NodeImpl) newChild).detachNode();
           children.add(newChild);
           ((NodeImpl) newChild).parent = this;
  -        setDirty(true);
  +        setDirty();
           return newChild;
       }
   
  @@ -509,7 +509,7 @@
        */
       public Node removeChild(Node oldChild) throws DOMException {
           if (removeNodeFromChildList((NodeImpl) oldChild)) {
  -            setDirty(true);
  +            setDirty();
               return oldChild;
           }
           throw new DOMException(DOMException.NOT_FOUND_ERR,
  @@ -561,7 +561,7 @@
               position = 0;
           }
           children.add(position, newChild);
  -        setDirty(true);
  +        setDirty();
           return newChild;
       }
   
  @@ -597,7 +597,7 @@
           }
           children.remove(position);
           children.add(position, newChild);
  -        setDirty(true);
  +        setDirty();
           return oldChild;
       }
   
  @@ -656,7 +656,7 @@
        * application references to it.
        */
       public void detachNode() {
  -        setDirty(true);
  +        setDirty();
           if (parent != null) {
               parent.removeChild(this);
               parent = null;
  @@ -791,7 +791,7 @@
           if (parent != null) {
               parent.appendChild(this);
           }
  -        this.setDirty(true);
  +        this.setDirty();
           this.parent = parent;
       }
   
  @@ -836,9 +836,18 @@
       {
           _isDirty = dirty;
           if (_isDirty && parent != null) {
  -            ((NodeImpl) parent).setDirty(true);
  +            ((NodeImpl) parent).setDirty();
           }
       }
  +
  +    public void setDirty()
  +    {
  +        _isDirty = true;
  +        if (parent != null) {
  +            ((NodeImpl) parent).setDirty();
  +        }
  +    }
  +
       /* clear dirty flag recursively */
       public void reset() {
           if (children != null) {
  
  
  
  1.57      +1 -1      ws-axis/java/src/org/apache/axis/message/SOAPBody.java
  
  Index: SOAPBody.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPBody.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- SOAPBody.java	2 Feb 2005 17:58:26 -0000	1.56
  +++ SOAPBody.java	20 Aug 2005 20:49:28 -0000	1.57
  @@ -266,7 +266,7 @@
   //        throw new SOAPException(Messages.getMessage("badSOAPBodyElement00"));
   //      }
           SOAPElement child = super.addChildElement(element);
  -        setDirty(true);
  +        setDirty();
           return child;
       }
   
  
  
  
  1.108     +2 -2      ws-axis/java/src/org/apache/axis/message/SOAPEnvelope.java
  
  Index: SOAPEnvelope.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPEnvelope.java,v
  retrieving revision 1.107
  retrieving revision 1.108
  diff -u -r1.107 -r1.108
  --- SOAPEnvelope.java	20 Jun 2005 22:49:44 -0000	1.107
  +++ SOAPEnvelope.java	20 Aug 2005 20:49:28 -0000	1.108
  @@ -120,7 +120,7 @@
                                          Constants.NS_PREFIX_SCHEMA_XSI));
           }
   
  -        setDirty(true);
  +        setDirty();
       }
       
       public SOAPEnvelope(InputStream input) throws SAXException {
  @@ -687,6 +687,6 @@
               recorder.clear();
               recorder = null;
           }
  -        super.setDirty(dirty);
  +        setDirty();
       }
   }
  
  
  
  1.86      +1 -1      ws-axis/java/src/org/apache/axis/message/SOAPHeader.java
  
  Index: SOAPHeader.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPHeader.java,v
  retrieving revision 1.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- SOAPHeader.java	1 Mar 2005 00:13:36 -0000	1.85
  +++ SOAPHeader.java	20 Aug 2005 20:49:28 -0000	1.86
  @@ -350,7 +350,7 @@
               throw new SOAPException(Messages.getMessage("badSOAPHeader00"));
           }
           SOAPElement child = super.addChildElement(element);
  -        setDirty(true);
  +        setDirty();
           return child;
       }
   
  
  
  
  1.14      +1 -1      ws-axis/java/src/org/apache/axis/message/Text.java
  
  Index: Text.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/Text.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Text.java	26 Jan 2005 00:52:48 -0000	1.13
  +++ Text.java	20 Aug 2005 20:49:28 -0000	1.14
  @@ -76,7 +76,7 @@
   
       // Overriding the MessageElement Method, where it throws exeptions.
       public void setNodeValue(String nodeValue) throws DOMException{
  -        setDirty(true);
  +        setDirty();
           textRep.setNodeValue(nodeValue);
       }
   
  
  
  
  1.20      +44 -1     ws-axis/java/test/encoding/TestDOM.java
  
  Index: TestDOM.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/encoding/TestDOM.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TestDOM.java	24 Jun 2004 12:27:38 -0000	1.19
  +++ TestDOM.java	20 Aug 2005 20:49:29 -0000	1.20
  @@ -4,13 +4,21 @@
   import org.apache.axis.AxisEngine;
   import org.apache.axis.Message;
   import org.apache.axis.MessageContext;
  +import org.apache.axis.encoding.DeserializationContext;
  +import org.apache.axis.encoding.SerializationContext;
   import org.apache.axis.message.MessageElement;
   import org.apache.axis.message.SOAPBodyElement;
   import org.apache.axis.message.SOAPEnvelope;
   import org.apache.axis.message.SOAPHeaderElement;
  +import org.apache.axis.message.SOAPBody;
   import org.apache.axis.server.AxisServer;
   import org.apache.axis.utils.XMLUtils;
   import org.custommonkey.xmlunit.XMLTestCase;
  +import org.custommonkey.xmlunit.Diff;
  +import org.xml.sax.InputSource;
  +
  +import java.io.StringReader;
  +import java.io.StringWriter;
   
   /**
   
  @@ -127,7 +135,7 @@
           assertXMLEqual("<tmp/>",body.toString());
       }
   
  -    public void testNodeWithAttribute() throws Exception 
  +    public void testNodeWithAttribute() throws Exception
       {
           org.w3c.dom.Element element = XMLUtils.newDocument().createElementNS(null,"tmp");
           element.setAttributeNS(null,"attrib", "foo");
  @@ -135,6 +143,41 @@
           assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
       }
   
  +    public void testDOM2() throws Exception
  +    {
  +        // Simulate receiving a signed message.
  +        //
  +        String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
  +            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
  +            "  <soapenv:Body>\n";
  +        String xml2 = "    <SASLResponse xmlns=\"urn:liberty:sa:2004-04\">\n" +
  +            "      <Status code=\"OK\" comment=\"Authenticated\"/>\n" +
  +            "    </SASLResponse>\n";
  +        String xml3 =
  +            "  </soapenv:Body>\n" +
  +            "</soapenv:Envelope>";
  +
  +        DeserializationContext ctx = new DeserializationContext(new InputSource(new StringReader(xml1 + xml2 + xml3)), null, "response");
  +        ctx.parse();
  +
  +        SOAPEnvelope env = ctx.getEnvelope();
  +        SOAPBody body = (SOAPBody) env.getBody();
  +
  +        // I am using the body child as my "token".  The basic idea is that
  +        // this element must be serialized _exactly_ as it was received.
  +        MessageElement elt = (MessageElement) body.getFirstChild();
  +        assertTrue(!elt.isDirty());
  +
  +        StringWriter writer = new StringWriter();
  +        SerializationContext serializeContext = new SerializationContext(writer, null);
  +        serializeContext.setSendDecl(false);
  +        elt.output(serializeContext);
  +        writer.close();
  +
  +        assertXMLIdentical("Deserialization invalidated XML",
  +                new Diff(xml2, writer.getBuffer().toString()), true);
  +    }
  +
       public static void main(String [] args) throws Exception
       {
           TestDOM tester = new TestDOM("TestDOM");
  
  
  
  1.2       +18 -5     ws-axis/java/test/utils/TestNSStack.java
  
  Index: TestNSStack.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/utils/TestNSStack.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestNSStack.java	10 Feb 2005 18:14:39 -0000	1.1
  +++ TestNSStack.java	20 Aug 2005 20:49:29 -0000	1.2
  @@ -6,6 +6,7 @@
   import org.apache.axis.AxisProperties;
   import org.apache.axis.AxisEngine;
   import org.custommonkey.xmlunit.Diff;
  +import org.custommonkey.xmlunit.XMLUnit;
   import org.xml.sax.InputSource;
   import test.AxisTestBase;
   
  @@ -24,7 +25,7 @@
       protected void setUp() throws Exception {
           AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"false");
       }
  -    
  +
       protected void tearDown() throws Exception {
           AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"true");
       }
  @@ -52,8 +53,14 @@
           dser.parse();
           org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
           String xml = env.toString();
  -        assertXMLIdentical("NSStack invalidated XML canonicalization",
  -                new Diff(msg, xml), true);
  +        boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
  +        XMLUnit.setIgnoreWhitespace(true);
  +        try {
  +            assertXMLIdentical("NSStack invalidated XML canonicalization",
  +                    new Diff(msg, xml), true);
  +        } finally {
  +            XMLUnit.setIgnoreWhitespace(oldIgnore);
  +        }
       }
   
       public void testNSStack2() throws Exception
  @@ -66,8 +73,14 @@
           dser.parse();
           org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
           String xml = env.toString();
  -        assertXMLIdentical("NSStack invalidated XML canonicalization",
  -                new Diff(msg, xml), true);
  +        boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
  +        XMLUnit.setIgnoreWhitespace(true);
  +        try {
  +            assertXMLIdentical("NSStack invalidated XML canonicalization",
  +                    new Diff(msg, xml), true);
  +        } finally {
  +            XMLUnit.setIgnoreWhitespace(oldIgnore);
  +        }
       }
   
       public static void main(String[] args) throws Exception
  
  
  
  1.22      +16 -9     ws-axis/java/test/utils/TestXMLUtils.java
  
  Index: TestXMLUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/utils/TestXMLUtils.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- TestXMLUtils.java	29 Jul 2004 21:40:29 -0000	1.21
  +++ TestXMLUtils.java	20 Aug 2005 20:49:29 -0000	1.22
  @@ -12,6 +12,7 @@
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
   import org.xml.sax.InputSource;
  +import org.custommonkey.xmlunit.XMLUnit;
   
   import javax.xml.parsers.SAXParser;
   import javax.xml.soap.SOAPEnvelope;
  @@ -288,7 +289,7 @@
           String output = org.apache.axis.utils.DOM2Writer.nodeToString(doc,false);
           assertTrue(output.indexOf("http://www.w3.org/XML/1998/namespace")==-1);
       }
  -    
  +
       public void testDOMXXE() throws Exception
       {
           StringBuffer sb = new StringBuffer();
  @@ -327,7 +328,7 @@
           "<symbol>IBM</symbol>\n" +
           "</echo:Echo>\n" +
           "</SOAP-ENV:Body></SOAP-ENV:Envelope>\n";
  -    
  +
       public void testSAXXXE1() throws Exception
       {
           StringReader strReader = new StringReader(msg);
  @@ -343,7 +344,7 @@
           SAXParser parser2 = XMLUtils.getSAXParser();
           parser2.getXMLReader().parse(inputsrc2);
       }
  -        
  +
       // If we are using DeserializationContext, we do not allow
       // a DOCTYPE to be specified to prevent denial of service attacks
       // via the ENTITY processing intstruction.
  @@ -356,13 +357,13 @@
           "<symbol xml:lang=\"en\">IBM</symbol>\n" +
           "</echo:Echo>\n" +
           "</SOAP-ENV:Body></SOAP-ENV:Envelope>\n";
  -    
  +
       /**
        * Confirm we can parse a SOAP Envelope, and make sure that the
        * xml:lang attribute is handled OK while we're at it.
  -     * 
  +     *
        * @throws Exception
  -     */ 
  +     */
       public void testSAXXXE3() throws Exception
       {
           StringReader strReader3 = new StringReader(msg2);
  @@ -400,11 +401,11 @@
               "         <EchoString>asdadsf</EchoString>" +
               "   </soapenv:Body>" +
               "</soapenv:Envelope>";
  -    
  +
       /**
        * Test for Bug 22980
        * @throws Exception
  -     */ 
  +     */
       public void testNSStack() throws Exception
       {
           StringReader strReader3 = new StringReader(msg3);
  @@ -413,7 +414,13 @@
           dser.parse();
           org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
           String xml = env.toString();
  -        assertXMLEqual(xml,msg3);
  +        boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
  +        XMLUnit.setIgnoreWhitespace(true);
  +        try {
  +            assertXMLEqual(xml,msg3);
  +        } finally {
  +            XMLUnit.setIgnoreWhitespace(oldIgnore);
  +        }
       }
       
       public static void main(String[] args) throws Exception