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 Thu, 08 Jul 2004 14:13:30 GMT
dims        2004/07/08 07:13:29

  Modified:    java/src/org/apache/axis/message MessageElement.java
                        SOAPBody.java
               java/test/saaj TestDOM.java
  Log:
  Fix and test case for AXIS-1436 - SOAPBody.addDocument ClassCastException
  
  Revision  Changes    Path
  1.176     +11 -4     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.175
  retrieving revision 1.176
  diff -u -r1.175 -r1.176
  --- MessageElement.java	29 Jun 2004 13:18:40 -0000	1.175
  +++ MessageElement.java	8 Jul 2004 14:13:28 -0000	1.176
  @@ -1415,10 +1415,17 @@
                   Mapping map = new Mapping(att.getNodeValue(), att.getLocalName());
                   addMapping(map);
               }
  -            parent.addAttribute(att.getPrefix(),
  -                    att.getNamespaceURI(),
  -                    att.getLocalName(),
  -                    att.getNodeValue());
  +            if(att.getLocalName() != null) {
  +                parent.addAttribute(att.getPrefix(),
  +                        att.getNamespaceURI(),
  +                        att.getLocalName(),
  +                        att.getNodeValue());
  +            } else if (att.getNodeName() != null) {
  +                parent.addAttribute(att.getPrefix(),
  +                        att.getNamespaceURI(),
  +                        att.getNodeName(),
  +                        att.getNodeValue());
  +            }
           }
   
           org.w3c.dom.NodeList children = element.getChildNodes();
  
  
  
  1.54      +3 -63     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.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- SOAPBody.java	27 Jun 2004 12:28:31 -0000	1.53
  +++ SOAPBody.java	8 Jul 2004 14:13:28 -0000	1.54
  @@ -217,7 +217,9 @@
       }
   
       public javax.xml.soap.SOAPBodyElement addDocument(Document document) throws SOAPException
{
  -        return importBodyElement(this, document.getDocumentElement());
  +        SOAPBodyElement bodyElement = new SOAPBodyElement(document.getDocumentElement());
  +        addChildElement(bodyElement);
  +        return bodyElement;
       }
   
       public javax.xml.soap.SOAPFault addFault() throws SOAPException {
  @@ -303,67 +305,5 @@
   
       public void setSAAJEncodingCompliance(boolean comply) {
           this.doSAAJEncodingCompliance = true;
  -    }
  -
  -    /**
  -     * Recursive function
  -     * @todo: handle Attributes not yet finished
  -     * @param parent
  -     * @param element
  -     */
  -
  -    private static SOAPBodyElement importBodyElement(MessageElement parent, org.w3c.dom.Node
element)
  -    {
  -        try{
  -            PrefixedQName name  = new PrefixedQName(element.getNamespaceURI(),
  -                    element.getLocalName(),
  -                    element.getPrefix());
  -            SOAPBodyElement bodyElement = null;
  -            bodyElement = new SOAPBodyElement(name);
  -            if(element instanceof org.w3c.dom.Element){
  -                org.w3c.dom.NamedNodeMap attrs = ((Element)element).getAttributes();
  -                for(int i = 0; i < attrs.getLength(); i++){
  -                    org.w3c.dom.Node att = attrs.item(i);
  -                    bodyElement.setAttribute(att.getNamespaceURI(), att.getLocalName(),
att.getPrefix());
  -                }
  -            }
  -            parent.appendChild(bodyElement);
  -
  -            org.w3c.dom.NodeList children = element.getChildNodes();
  -            for(int i = 0; i < children.getLength(); i++){
  -                org.w3c.dom.Node child = children.item(i);
  -                importMessageElement((MessageElement)element, child);
  -            }
  -            return bodyElement;
  -        }
  -        catch(Exception e)
  -        {
  -            return null;
  -        }
  -    }
  -
  -    private static void importMessageElement(org.w3c.dom.Node parent, org.w3c.dom.Node
element)
  -    {
  -
  -        PrefixedQName name  = new PrefixedQName(element.getNamespaceURI(),
  -                element.getLocalName(),
  -                element.getPrefix());
  -        MessageElement bodyElement = new MessageElement(name);
  -        org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
  -        for(int i = 0; i < attrs.getLength(); i++){
  -            org.w3c.dom.Node att = attrs.item(i);
  -            bodyElement.setAttribute(att.getNamespaceURI(),
  -                    att.getLocalName(),
  -                    att.getPrefix());
  -        }
  -        // do we have to set some more for importing.....?
  -        parent.appendChild(bodyElement);
  -
  -        org.w3c.dom.NodeList children = element.getChildNodes();
  -        for(int i = 0; i < children.getLength(); i++){
  -            org.w3c.dom.Node child = children.item(i);
  -            importMessageElement(element, child);
  -        }
  -
       }
   }
  
  
  
  1.4       +22 -0     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestDOM.java	8 Jul 2004 08:51:58 -0000	1.3
  +++ TestDOM.java	8 Jul 2004 14:13:29 -0000	1.4
  @@ -4,6 +4,7 @@
   import org.apache.axis.message.RPCParam;
   import org.apache.axis.message.RPCElement;
   import org.w3c.dom.Element;
  +import org.w3c.dom.Document;
   import org.custommonkey.xmlunit.XMLUnit;
   
   import javax.xml.soap.MessageFactory;
  @@ -17,6 +18,7 @@
   import javax.xml.soap.SOAPPart;
   import javax.xml.soap.SOAPBody;
   import javax.xml.soap.SOAPElement;
  +import javax.xml.soap.SOAPBodyElement;
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.util.Iterator;
  @@ -142,6 +144,26 @@
               SOAPElement elem3 = (SOAPElement) it3.next();
               System.out.println("child = " + elem3);
           }
  +    }
  +    
  +    public void testAddDocument() throws Exception {
  +        String xml = "<bank:getBalance xmlns:bank=\"http://myservice.test.com/banking/\">\n"
+
  +                     "    <gb:getBalanceReq xmlns:gb=\"http://myservice.test.com/banking/getBalance\">\n"
+
  +                     "        <bt:account acctType=\"domestic\" customerId=\"654321\"
xmlns:bt=\"http://myservice.test.com/banking/bankTypes\">\n" +
  +                     "            <bt:accountNumber>1234567890</bt:accountNumber>\n"
+
  +                     "            <bt:currency>USD</bt:currency>\n" +
  +                     "        </bt:account>\n" +
  +                     "    </gb:getBalanceReq>\n" +
  +                     "</bank:getBalance>";
  +        Document document = XMLUtils.newDocument(new ByteArrayInputStream(xml.getBytes()));
  +        
  +        MessageFactory factory = new org.apache.axis.soap.MessageFactoryImpl();
  +        SOAPMessage msg = factory.createMessage();
  +        msg.getSOAPBody();
  +        SOAPBody body = msg.getSOAPBody();
  +        
  +        SOAPBodyElement soapBodyElt = body.addDocument(document);
  +        assertXMLEqual(xml, soapBodyElt.toString());
       }
   
       private String messageToString(SOAPMessage message) throws Exception {
  
  
  

Mime
View raw message