axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/test/saaj TestDOM.java
Date Tue, 29 Jun 2004 13:32:29 GMT
dims        2004/06/29 06:32:29

  Modified:    java/src/org/apache/axis/message RPCElement.java
                        SOAPEnvelope.java SOAPHeader.java
                        SOAPHeaderElement.java
               java/src/org/apache/axis/encoding
                        SerializationContextImpl.java
               java/test/saaj TestDOM.java
  Log:
  Fix for AXIS-1415 - some problem will isDirty flag
  
  Notes:
  - Basically ensure that if we use message.writeTo or XMLUtils.PrettyDocumentToString(message.getSOAPPart())
the results are the same.
  
  Revision  Changes    Path
  1.93      +14 -5     ws-axis/java/src/org/apache/axis/message/RPCElement.java
  
  Index: RPCElement.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/RPCElement.java,v
  retrieving revision 1.92
  retrieving revision 1.93
  diff -u -r1.92 -r1.93
  --- RPCElement.java	27 Jun 2004 12:28:31 -0000	1.92
  +++ RPCElement.java	29 Jun 2004 13:32:28 -0000	1.93
  @@ -40,6 +40,7 @@
   import java.util.ArrayList;
   import java.util.Enumeration;
   import java.util.Vector;
  +import java.util.Iterator;
   
   public class RPCElement extends SOAPBodyElement
   {
  @@ -342,12 +343,20 @@
               context.startElement(new QName(getNamespaceURI(), name), attributes);
           }
   
  -        for (int i = 0; i < params.size(); i++) {
  -            RPCParam param = (RPCParam)params.elementAt(i);
  -            if (!hasOperationElement && encodingStyle != null && encodingStyle.equals(""))
{
  -                context.registerPrefixForURI("", param.getQName().getNamespaceURI());
  +        if(noParams) {
  +            if (children != null) {
  +                for (Iterator it = children.iterator(); it.hasNext();) {
  +                    ((NodeImpl)it.next()).output(context);
  +                }
  +            }
  +        } else {
  +            for (int i = 0; i < params.size(); i++) {
  +                RPCParam param = (RPCParam)params.elementAt(i);
  +                if (!hasOperationElement && encodingStyle != null && encodingStyle.equals(""))
{
  +                    context.registerPrefixForURI("", param.getQName().getNamespaceURI());
  +                }
  +                param.serialize(context);
               }
  -            param.serialize(context);
           }
   
           if (hasOperationElement || noParams) {
  
  
  
  1.98      +6 -0      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.97
  retrieving revision 1.98
  diff -u -r1.97 -r1.98
  --- SOAPEnvelope.java	28 Jun 2004 09:46:34 -0000	1.97
  +++ SOAPEnvelope.java	29 Jun 2004 13:32:28 -0000	1.98
  @@ -260,6 +260,9 @@
        * @param hdr
        */ 
       public void setHeader(SOAPHeader hdr) {
  +        if(this.header != null) {
  +            removeChild(this.header);
  +        }
           header = hdr;
           try {
               header.setParentElement(this);
  @@ -296,6 +299,9 @@
        * @param body
        */ 
       public void setBody(SOAPBody body) {
  +        if(this.body != null) {
  +            removeChild(this.body);
  +        }
           this.body = body;
           try {
               body.setParentElement(this);
  
  
  
  1.84      +18 -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.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- SOAPHeader.java	27 Jun 2004 12:28:31 -0000	1.83
  +++ SOAPHeader.java	29 Jun 2004 13:32:28 -0000	1.84
  @@ -27,6 +27,9 @@
   import org.apache.axis.utils.Messages;
   import org.apache.commons.logging.Log;
   import org.xml.sax.Attributes;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.DOMException;
  +import org.w3c.dom.Element;
   
   import javax.xml.namespace.QName;
   import javax.xml.soap.Name;
  @@ -322,7 +325,7 @@
               Iterator enumeration = headers.iterator();
               while (enumeration.hasNext()) {
                   // Output this header element
  -                ((SOAPHeaderElement)enumeration.next()).output(context);
  +                ((NodeImpl)enumeration.next()).output(context);
               }
               // Output </SOAP-ENV:Header>
               context.endElement();
  @@ -382,5 +385,19 @@
           child.addNamespaceDeclaration(prefix, uri);
           addChildElement(child);
           return child;
  +    }
  +
  +    public Node appendChild(Node newChild) throws DOMException {
  +        SOAPHeaderElement headerElement = null;
  +        if(newChild instanceof SOAPHeaderElement)
  +            headerElement = (SOAPHeaderElement)newChild;
  +        else 
  +            headerElement = new SOAPHeaderElement((Element)newChild);
  +        try {
  +            addChildElement(headerElement);
  +        } catch (SOAPException e) {
  +            throw new DOMException(DOMException.INVALID_STATE_ERR,e.toString());
  +        }
  +        return headerElement;
       }
   }
  
  
  
  1.36      +48 -8     ws-axis/java/src/org/apache/axis/message/SOAPHeaderElement.java
  
  Index: SOAPHeaderElement.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPHeaderElement.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- SOAPHeaderElement.java	27 Jun 2004 12:28:31 -0000	1.35
  +++ SOAPHeaderElement.java	29 Jun 2004 13:32:28 -0000	1.36
  @@ -22,7 +22,9 @@
   import org.apache.axis.soap.SOAPConstants;
   import org.apache.axis.utils.Messages;
   import org.w3c.dom.Element;
  +import org.w3c.dom.NamedNodeMap;
   import org.xml.sax.Attributes;
  +import org.xml.sax.helpers.AttributesImpl;
   
   import javax.xml.namespace.QName;
   import javax.xml.soap.Name;
  @@ -78,10 +80,7 @@
   
           // FIXME : This needs to come from someplace reasonable, perhaps
           // TLS (SOAPConstants.getCurrentVersion() ?)
  -        SOAPConstants soapConstants = SOAPConstants.SOAP11_CONSTANTS;
  -
  -        if (getNamespaceURI() != null && getNamespaceURI().equals(SOAPConstants.SOAP12_CONSTANTS.getEnvelopeURI()))
  -            soapConstants = SOAPConstants.SOAP12_CONSTANTS;
  +        SOAPConstants soapConstants = getSOAPConstants();
   
           String val = elem.getAttributeNS(soapConstants.getEnvelopeURI(),
                                            Constants.ATTR_MUST_UNDERSTAND);
  @@ -134,9 +133,7 @@
       {
           super(namespace, localPart, prefix, attributes, context);
   
  -        SOAPConstants soapConstants = context.getMessageContext() == null ?
  -                                        SOAPConstants.SOAP11_CONSTANTS :
  -                                        context.getMessageContext().getSOAPConstants();
  +        SOAPConstants soapConstants = getSOAPConstants();
   
           // Check for mustUnderstand
           String val = attributes.getValue(soapConstants.getEnvelopeURI(),
  @@ -227,7 +224,7 @@
        */
       protected void outputImpl(SerializationContext context) throws Exception {
           if (!alreadySerialized) {
  -            SOAPConstants soapVer = getEnvelope().getSOAPConstants();
  +            SOAPConstants soapVer = getSOAPConstants();
               QName roleQName = soapVer.getRoleAttributeQName();
   
               if (actor != null) {
  @@ -252,5 +249,48 @@
           }
   
           super.outputImpl(context);
  +    }
  +
  +    public NamedNodeMap getAttributes() {
  +        makeAttributesEditable();
  +        SOAPConstants soapConstants = getSOAPConstants();
  +        String mustUnderstand = attributes.getValue(soapConstants.getEnvelopeURI(),
  +                                         Constants.ATTR_MUST_UNDERSTAND);
  +        QName roleQName = soapConstants.getRoleAttributeQName();
  +        String actor = attributes.getValue(roleQName.getNamespaceURI(),roleQName.getLocalPart());
  +        
  +        if(mustUnderstand == null){
  +            if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
  +                setAttributeNS(soapConstants.getEnvelopeURI(), 
  +                            Constants.ATTR_MUST_UNDERSTAND,"false");
  +            } else {
  +                setAttributeNS(soapConstants.getEnvelopeURI(), 
  +                            Constants.ATTR_MUST_UNDERSTAND,"0");
  +            }
  +        }
  +        if(actor == null){
  +            setAttributeNS(roleQName.getNamespaceURI(),
  +                         roleQName.getLocalPart(), this.actor);
  +        }
  +        return super.getAttributes();
  +    }
  +
  +    private SOAPConstants getSOAPConstants() {
  +        SOAPConstants soapConstants = null;
  +        if (getNamespaceURI() != null &&
  +                getNamespaceURI().equals(SOAPConstants.SOAP12_CONSTANTS.getEnvelopeURI()))
{
  +            soapConstants = SOAPConstants.SOAP12_CONSTANTS;
  +        }
  +        if (soapConstants == null && getEnvelope() != null) {
  +            soapConstants = getEnvelope().getSOAPConstants();
  +        }
  +        if (soapConstants == null && context != null &&
  +                context.getMessageContext() != null) {
  +            soapConstants = context.getMessageContext().getSOAPConstants();
  +        }
  +        if (soapConstants == null) {
  +            soapConstants = SOAPConstants.SOAP11_CONSTANTS;
  +        }
  +        return soapConstants;
       }
   }
  
  
  
  1.112     +16 -2     ws-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java
  
  Index: SerializationContextImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -r1.111 -r1.112
  --- SerializationContextImpl.java	24 Jun 2004 12:27:37 -0000	1.111
  +++ SerializationContextImpl.java	29 Jun 2004 13:32:29 -0000	1.112
  @@ -466,6 +466,20 @@
       {
           String prefix = null;
           String namespaceURI = qName.getNamespaceURI();
  +        String localPart = qName.getLocalPart();
  +        
  +        if(localPart != null && localPart.length() > 0) {
  +            int index = localPart.indexOf(':');
  +            if(index!=-1){
  +                prefix = localPart.substring(0,index);
  +                if(prefix.length()>0 && !prefix.equals("urn")){
  +                    registerPrefixForURI(prefix, namespaceURI);
  +                    localPart = localPart.substring(index+1);
  +                } else {
  +                    prefix = null;
  +                }
  +            }
  +        }
   
           if (namespaceURI.length() == 0) {
               if (writeNS) {
  @@ -481,9 +495,9 @@
           }
   
           if ((prefix == null) || (prefix.length() == 0))
  -           return qName.getLocalPart();
  +           return localPart;
   
  -        return prefix + ':' + qName.getLocalPart();
  +        return prefix + ':' + localPart;
       }
   
       public String qName2String(QName qName)
  
  
  
  1.2       +92 -1     ws-axis/java/test/saaj/TestDOM.java
  
  Index: TestDOM.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/saaj/TestDOM.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestDOM.java	28 Jun 2004 12:52:24 -0000	1.1
  +++ TestDOM.java	29 Jun 2004 13:32:29 -0000	1.2
  @@ -1,10 +1,24 @@
   package test.saaj;
   
  +import org.apache.axis.utils.XMLUtils;
  +import org.w3c.dom.Element;
  +import org.custommonkey.xmlunit.XMLUnit;
  +
   import javax.xml.soap.MessageFactory;
  +import javax.xml.soap.MimeHeaders;
  +import javax.xml.soap.Name;
  +import javax.xml.soap.SOAPEnvelope;
  +import javax.xml.soap.SOAPFactory;
  +import javax.xml.soap.SOAPHeader;
  +import javax.xml.soap.SOAPHeaderElement;
   import javax.xml.soap.SOAPMessage;
   import javax.xml.soap.SOAPPart;
  +import java.io.ByteArrayInputStream;
  +import java.io.ByteArrayOutputStream;
  +
  +import test.AxisTestBase;
   
  -public class TestDOM extends junit.framework.TestCase {
  +public class TestDOM extends AxisTestBase {
       public TestDOM(String name) {
           super(name);
       }
  @@ -20,4 +34,81 @@
                   "soap part's document element's owner document should not be null",
                   soapPart.getDocumentElement().getOwnerDocument());
       }
  +
  +    private static final String SAMPLE_1 = 
  +            "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "\n" +
  +                "<SOAP-ENV:Body> " + "\n" +
  +                    "<m:GetLastTradePrice xmlns:m=\"http://wombat.ztrade.com\">"
+ "\n" +
  +                        "<symbol>SUNW</symbol> " + "\n" +
  +                    "</m:GetLastTradePrice> " + "\n" +
  +                "</SOAP-ENV:Body> " + "\n" +
  +            "</SOAP-ENV:Envelope>";
  +
  +    private SOAPMessage getSOAPMessageFromString(String str) throws Exception {
  +        MimeHeaders mimeHeaders = new MimeHeaders();
  +        mimeHeaders.addHeader("content-type", "text/xml");
  +        SOAPMessage message = MessageFactory.newInstance().createMessage(
  +                mimeHeaders,
  +                new ByteArrayInputStream(str.getBytes()));
  +        SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
  +        SOAPHeader header = message.getSOAPHeader();
  +        if (header == null) {
  +            header = envelope.addHeader();
  +        }
  +        return message;
  +    }
  +    
  +    public void testSAAJSerialization() throws Exception {
  +        SOAPMessage message1 = this.getSOAPMessageFromString(SAMPLE_1);
  +        SOAPHeader header1 = message1.getSOAPHeader();
  +
  +        boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
  +        XMLUnit.setIgnoreWhitespace(true);
  +        try {
  +            //this is how header element is added in sun's example
  +            SOAPFactory soapFactory = SOAPFactory.newInstance();
  +            Name headerName = soapFactory.createName("Claim",
  +                    "wsi", "http://ws-i.org/schemas/conformanceClaim/");
  +            SOAPHeaderElement headerElement =
  +                    header1.addHeaderElement(headerName);
  +            headerElement.addAttribute(soapFactory.createName("conformsTo"), "http://ws-i.org/profiles/basic1.0/");
  +            final String domToString1 = XMLUtils.PrettyDocumentToString(
  +                    message1.getSOAPPart());
  +            final String messageToString1 = messageToString(message1);
  +    
  +            assertXMLEqual(domToString1, messageToString1);
  +        } finally {
  +            XMLUnit.setIgnoreWhitespace(oldIgnore);            
  +        }
  +    }
  +
  +    public void testSAAJSerialization2() throws Exception {
  +        SOAPMessage message2 = this.getSOAPMessageFromString(SAMPLE_1);
  +        SOAPHeader header2 = message2.getSOAPHeader();
  +
  +        boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
  +        XMLUnit.setIgnoreWhitespace(true);
  +        try {
  +            Element header2Element = header2.getOwnerDocument().createElementNS(
  +                    "http://ws-i.org/schemas/conformanceClaim/", "wsi:Claim");
  +            header2Element.setAttributeNS(
  +                    "http://ws-i.org/schemas/conformanceClaim/",
  +                    "wsi:conformsTo", "http://ws-i.org/profiles/basic1.0/");
  +            header2.appendChild(header2Element);
  +            final String domToString2 = XMLUtils.PrettyDocumentToString(
  +                    message2.getSOAPPart());
  +            final String messageToString2 = messageToString(message2);
  +
  +            assertXMLEqual(domToString2, messageToString2);
  +        } finally {
  +            XMLUnit.setIgnoreWhitespace(oldIgnore);            
  +        }
  +    }
  +
  +    private String messageToString(SOAPMessage message) throws Exception {
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
  +        message.writeTo(baos);
  +        return new String(baos.toByteArray());
  +    }
  +
   }
  
  
  

Mime
View raw message