axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jongjinc...@apache.org
Subject cvs commit: ws-axis/java/test/saaj TestEnvelope.java
Date Fri, 18 Feb 2005 13:03:58 GMT
jongjinchoi    2005/02/18 05:03:58

  Modified:    java/src/org/apache/axis/message SOAPEnvelope.java
                        SOAPHandler.java MessageElement.java
               java/test/message TestMessageElement.java
               java/test/saaj TestEnvelope.java
  Log:
  Fix for AXIS-1817, 1823.
  
  - SOAPEnvelope#outputImpl() is modified so that envelope's each children's output or outputImpl
methods is called in order. (What is the trailers in SOAPEnvelope?)
  
  - MessageElement#getValue() :
     TextSerializationContext is not sufficient for getting the exact text node.
     So, comment it.
  
  - MessageElement#getValue() looks for the first child text node among its children.  (not
to check if just first node is text node)
  
  - SOAPEnvelope's getValue() is removed. MessageElement#getValue() is used instead.
  
  - SOAPHandler :
       - Add text child to current deserialing element (myElemetn) in onStartChild() for mixed
contents.
       - To avoid appending text child for ignorable white spaces, the stripped string's length
is checked, but it is necessary to append the original unstripped text child to keep its non-igrnorable
white spaces.
  
  - test/message/TestMessageElement.java
     fixed invalid test case for mixed contents according to SAAJ-spec and SUN's RI.
  
  - test/saaj/TestEnvelope.java
     added test case for checking appended text node is position as expected (after soapbody)
  
  Revision  Changes    Path
  1.106     +15 -23    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.105
  retrieving revision 1.106
  diff -u -r1.105 -r1.106
  --- SOAPEnvelope.java	22 Nov 2004 17:57:08 -0000	1.105
  +++ SOAPEnvelope.java	18 Feb 2005 13:03:57 -0000	1.106
  @@ -465,26 +465,23 @@
           context.startElement(new QName(soapConstants.getEnvelopeURI(),
                                          Constants.ELEM_ENVELOPE), attributes);
   
  -        // Output non-SOAPHeader and non-SOAPBody stuff.
  +        
  +        // Output <SOAP-ENV:Envelope>'s each child as it appears.
           Iterator i = getChildElements();
  -        while (i.hasNext()) {
  -            NodeImpl element = (NodeImpl)i.next();
  -            if(element instanceof SOAPHeader ||
  -               element instanceof SOAPBody)
  -                continue;
  -            element.output(context);
  -        }
  -
  -        // Output headers
  -        if (header != null) {
  -            header.outputImpl(context);
  -        }
  -
  -        // Output body
  -        if (body != null) {
  -            body.outputImpl(context);
  +        while (i.hasNext()) {            
  +            NodeImpl node = (NodeImpl)i.next();
  +            
  +            if (node instanceof SOAPHeader) {
  +                header.outputImpl(context);
  +            } else if (node instanceof SOAPBody) {
  +                body.outputImpl(context);                
  +            } else if (node instanceof MessageElement) {
  +                ((MessageElement)node).output(context);
  +            } else {
  +                node.output(context);
  +            }    
           }
  -
  +        
           // Output trailers
           enumeration = trailers.elements();
           while (enumeration.hasMoreElements()) {
  @@ -675,9 +672,4 @@
               setOwnerDocumentForChildren(node.children, sp);  // recursively
       	}
       }
  -
  -    public String getValue() {
  -        return getValueDOM();
  -    }
  -    
   }
  
  
  
  1.20      +26 -12    ws-axis/java/src/org/apache/axis/message/SOAPHandler.java
  
  Index: SOAPHandler.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPHandler.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SOAPHandler.java	15 Nov 2004 19:03:01 -0000	1.19
  +++ SOAPHandler.java	18 Feb 2005 13:03:58 -0000	1.20
  @@ -109,18 +109,7 @@
           throws SAXException
       {
           if (myElement != null) {
  -
  -            if (val != null && val.size() > 0) {
  -                String s = StringUtils.strip(val.toString());
  -                val.reset();
  -                if(s.length()>0){
  -                    try {
  -                        myElement.addTextNode(s);
  -                    } catch (SOAPException e) {
  -                        throw new SAXException(e);
  -                    }
  -                }
  -            }
  +            addTextNode();	
   
               if (myElements != null) {
                   myElements[myIndex] = myElement;
  @@ -136,9 +125,34 @@
                                       DeserializationContext context)
           throws SAXException
       {
  +        addTextNode();
           SOAPHandler handler = new SOAPHandler();
           return handler;
       }
  +
  +    private void addTextNode() throws SAXException {
  +        if (myElement != null) {
  +            if (val != null && val.size() > 0) {
  +                String s = StringUtils.strip(val.toString());
  +                val.reset();
  +                
  +                // we need to check the length of STRIPPED string 
  +                // to avoid appending ignorable white spaces as 
  +                // message elmenet's child. 
  +                // (SOAPHeader and others does not accept text children...
  +                // but in SAAJ 1.2's DOM view, this could be incorrect.
  +                // we need to keep the ignorable white spaces later)
  +                if(s.length()>0){
  +                    try {
  +                        // add unstripped string as text child.
  +                        myElement.addTextNode(s);
  +                    } catch (SOAPException e) {
  +                        throw new SAXException(e);
  +                    }
  +                }
  +            }
  +        }
  +    }
       
       public void onEndChild(String namespace, String localName,
                              DeserializationContext context)
  
  
  
  1.195     +6 -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.194
  retrieving revision 1.195
  diff -u -r1.194 -r1.195
  --- MessageElement.java	8 Feb 2005 18:44:36 -0000	1.194
  +++ MessageElement.java	18 Feb 2005 13:03:58 -0000	1.195
  @@ -2055,6 +2055,7 @@
        * @see javax.xml.soap.Node#getValue() ;
        */
       public String getValue() {
  +        /*--- Fix for AXIS-1817
           if ((recorder != null) && (!_isDirty)) {
               StringWriter writer = new StringWriter();
               TextSerializationContext outputContext = 
  @@ -2070,6 +2071,7 @@
               String value = writer.toString();
               return (value.length() == 0) ? null : value;
           } 
  +        ---*/
   
           if (textRep != null) {
               // weird case: error?
  @@ -2080,9 +2082,10 @@
               return getValueDOM();
           }
   
  -        if (children != null && !children.isEmpty()) {
  -            if (children.get(0) instanceof org.apache.axis.message.Text) {
  -                return ((org.apache.axis.message.Text)children.get(0)).getNodeValue();
  +        for (Iterator i = getChildElements(); i.hasNext(); ) {
  +            NodeImpl n = (NodeImpl) i.next();
  +            if (n instanceof Text) {
  +                return ((Text)n).getNodeValue();
               }
           }
   
  
  
  
  1.19      +10 -2     ws-axis/java/test/message/TestMessageElement.java
  
  Index: TestMessageElement.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/message/TestMessageElement.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TestMessageElement.java	11 Nov 2004 00:29:26 -0000	1.18
  +++ TestMessageElement.java	18 Feb 2005 13:03:58 -0000	1.19
  @@ -392,6 +392,11 @@
           
           assertEquals("FooBar", getNodeValueContext(data));
           assertEquals("FooBar", getNodeValueDOM(data));
  +         
  +        data = "<anElement xmlns:ns1=\"aNamespace\">A&gt;B</anElement>";
  +        
  +        assertEquals("A>B", getNodeValueContext(data));
  +        assertEquals("A>B", getNodeValueDOM(data));
   
           data = "<anElement xmlns:ns1=\"aNamespace\"><bElement>FooBar</bElement></anElement>";
           
  @@ -400,8 +405,11 @@
   
           data = "<anElement xmlns:ns1=\"aNamespace\"><bElement>FooBar</bElement>Mixed</anElement>";
           
  -        assertTrue(getNodeValueContext(data) == null);
  -        assertTrue(getNodeValueDOM(data) == null);
  +        // SAAJ 1.2 requires "Mixed" for this case.
  +        assertEquals("Mixed", getNodeValueContext(data));
  +        assertEquals("Mixed", getNodeValueDOM(data));
  +//        assertTrue(getNodeValueContext(data) == null);
  +//        assertTrue(getNodeValueDOM(data) == null);
   
           data = "<anElement xmlns:ns1=\"aNamespace\">Foo<bElement>FooBar</bElement>Mixed</anElement>";
           
  
  
  
  1.9       +38 -0     ws-axis/java/test/saaj/TestEnvelope.java
  
  Index: TestEnvelope.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/saaj/TestEnvelope.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestEnvelope.java	2 Jul 2004 13:32:41 -0000	1.8
  +++ TestEnvelope.java	18 Feb 2005 13:03:58 -0000	1.9
  @@ -7,8 +7,10 @@
   import javax.xml.soap.SOAPBody;
   import javax.xml.soap.SOAPConnection;
   import javax.xml.soap.SOAPConnectionFactory;
  +import javax.xml.soap.SOAPConstants;
   import javax.xml.soap.SOAPElement;
   import javax.xml.soap.SOAPEnvelope;
  +import javax.xml.soap.SOAPException;
   import javax.xml.soap.SOAPFault;
   import javax.xml.soap.SOAPHeader;
   import javax.xml.soap.SOAPHeaderElement;
  @@ -19,7 +21,9 @@
   import javax.xml.soap.DetailEntry;
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
  +import java.io.IOException;
   import java.util.Iterator;
  +import junit.framework.AssertionFailedError;
   
   public class TestEnvelope extends junit.framework.TestCase {
   
  @@ -224,6 +228,40 @@
   		assertTrue(t.isComment());
       }
   
  +    public void testText4() throws SOAPException, IOException {
  +        MessageFactory mf = MessageFactory.newInstance();
  +        SOAPMessage smsg =
  +            mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
  +
  +        // Make some change to the message
  +        SOAPPart sp = smsg.getSOAPPart();
  +        SOAPEnvelope envelope = sp.getEnvelope();
  +        envelope.addTextNode("<!-- This is a comment -->");
  +        
  +        boolean passbody = false;
  +        for (Iterator i = envelope.getChildElements(); i.hasNext(); ) {
  +            Node n = (Node) i.next();
  +            if (n instanceof SOAPElement) {
  +                SOAPElement se = (SOAPElement) n;
  +                System.out.println("soap element = " + se.getNodeName());
  +                if (se.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_ENVELOPE) 
  +                    && se.getLocalName().equals("Body")) {
  +                    passbody = true;
  +                }
  +            }
  +            
  +            if (n instanceof Text) {
  +                Text t = (Text)n; 
  +                System.out.println("text = " + t.getValue());
  +                if (t.getValue().equals("<!-- This is a comment -->")) {
  +                    assertEquals(true, passbody);
  +                    return;
  +                }
  +            }            
  +        }
  +        throw new AssertionFailedError("Text is not added to expected position.");
  +    }
  +
       private int getIteratorCount(java.util.Iterator i) {
           int count = 0;
           while (i.hasNext()) {
  
  
  

Mime
View raw message