Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 92063 invoked from network); 8 Jul 2004 14:13:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 8 Jul 2004 14:13:35 -0000 Received: (qmail 11626 invoked by uid 500); 8 Jul 2004 14:13:32 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 11599 invoked by uid 500); 8 Jul 2004 14:13:32 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 11583 invoked by uid 99); 8 Jul 2004 14:13:32 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Thu, 08 Jul 2004 07:13:30 -0700 Received: (qmail 91998 invoked by uid 1203); 8 Jul 2004 14:13:30 -0000 Date: 8 Jul 2004 14:13:30 -0000 Message-ID: <20040708141330.91995.qmail@minotaur.apache.org> From: dims@apache.org To: ws-axis-cvs@apache.org Subject: cvs commit: ws-axis/java/test/saaj TestDOM.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 = "\n" + + " \n" + + " \n" + + " 1234567890\n" + + " USD\n" + + " \n" + + " \n" + + ""; + 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 {