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 Jongjin Choi <gu...@hotmail.com> on 2004/07/05 16:38:58 UTC
RE: cvs commit: ws-axis/java/test/message TestMessageElement.java
Hi, dims.
I looked into the following MessageElement changes and ran a test.
Does this change resolve the problem RPCParam <-> SOAP Element mapping
addressed in http://nagoya.apache.org/jira/browse/AXIS-1416?
I made a simple test and found that the problem is remaining.
Without resolving the AXIS-1416,
the standard JAX-RPC handler under Axis can not read or modify
the second and below level SOAP body elements.
Thanks.
-----Original Message-----
From: dims@apache.org [mailto:dims@apache.org]
Sent: Thursday, June 24, 2004 9:28 PM
To: ws-axis-cvs@apache.org
Subject: cvs commit: ws-axis/java/test/message TestMessageElement.java
dims 2004/06/24 05:27:38
Modified: java/test/wsdl/faults FaultServiceSoapBindingImpl.java
java/src/org/apache/axis/message MessageElement.java
java/test/wsdl/sequence SequenceService.java
java/src/org/apache/axis/encoding
SerializationContextImpl.java
java/test/encoding TestDOM.java
java/test/message TestMessageElement.java
Log:
Fix for AXIS-1350 - new MessageElement(new Element()) does not behave like
an Element
Fix for AXIS-616 - MessageElement is not for mortals
Fix for AXIS-1054 - No way to non-default namespace prefixes when creating
MessageElements from DOM elements
Fix for AXIS-1403 - calling MessageElement#getChildren with a Text-Only
content returns an empty list
Notes:
- traverse all the nodes recursively and create new MessageElement's for
each node.
Revision Changes Path
1.5 +1 -1
ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java
Index: FaultServiceSoapBindingImpl.java
===================================================================
RCS file:
/home/cvs/ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FaultServiceSoapBindingImpl.java 11 Dec 2002 22:40:20 -0000 1.4
+++ FaultServiceSoapBindingImpl.java 24 Jun 2004 12:27:37 -0000 1.5
@@ -23,7 +23,7 @@
public int throwExtensionFault(java.lang.String description) throws
java.rmi.RemoteException, test.wsdl.faults.ExtensionFault {
ExtensionType extension = new ExtensionType();
try {
- extension.set_any(new MessageElement[] {new
MessageElement(XMLUtils.newDocument().createElement(description))});
+ extension.set_any(new MessageElement[] {new
MessageElement(XMLUtils.newDocument().createElementNS(null,description))});
} catch (Exception e) {
throw new java.rmi.RemoteException(e.getMessage());
}
1.173 +85 -36
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.172
retrieving revision 1.173
diff -u -r1.172 -r1.173
--- MessageElement.java 23 Jun 2004 04:14:31 -0000 1.172
+++ MessageElement.java 24 Jun 2004 12:27:37 -0000 1.173
@@ -16,22 +16,6 @@
package org.apache.axis.message;
-import java.io.Reader;
-import java.io.Serializable;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Vector;
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-import javax.xml.rpc.encoding.TypeMapping;
-import javax.xml.soap.Name;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPException;
-
import org.apache.axis.AxisFault;
import org.apache.axis.Constants;
import org.apache.axis.MessageContext;
@@ -48,6 +32,9 @@
import org.apache.axis.utils.XMLUtils;
import org.apache.commons.logging.Log;
import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -61,6 +48,21 @@
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.encoding.TypeMapping;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
/*
* MessageElement is the base type of nodes of the SOAP message parse
tree.
*
@@ -106,8 +108,7 @@
protected int endEventIndex = -1;
// ...or as DOM
- protected Element elementRep = null;
- protected Text textRep = null;
+ protected CharacterData textRep = null;
protected MessageElement parent = null;
@@ -163,12 +164,12 @@
public MessageElement(Element elem)
{
- elementRep = elem;
namespaceURI = elem.getNamespaceURI();
name = elem.getLocalName();
+ copyNode(elem);
}
- public MessageElement(Text text)
+ public MessageElement(CharacterData text)
{
textRep = text;
namespaceURI = text.getNamespaceURI();
@@ -399,8 +400,7 @@
* protected int startEventIndex = 0; N?
* protected int startContentsIndex = 0; N?
* protected int endEventIndex = -1; N?
- * protected Element elementRep = null; N?
- * protected Text textRep = null; Y?
+ * protected CharacterData textRep = null; Y?
* protected MessageElement parent = null; N
* public ArrayList namespaces = null; Y
* protected String encodingStyle = null; N?
@@ -608,7 +608,13 @@
public short getNodeType() {
if(this.textRep != null) {
+ if(textRep instanceof Comment) {
+ return COMMENT_NODE;
+ } else if(textRep instanceof CDATASection) {
+ return CDATA_SECTION_NODE;
+ } else {
return TEXT_NODE;
+ }
}else if(false){
return DOCUMENT_FRAGMENT_NODE;
}else if(false){
@@ -908,11 +914,6 @@
log.error(Messages.getMessage("childPresent"), exc);
throw exc;
}
- if (elementRep != null) {
- SOAPException exc = new
SOAPException(Messages.getMessage("xmlPresent"));
- log.error(Messages.getMessage("xmlPresent"), exc);
- throw exc;
- }
if (textRep != null) {
SOAPException exc = new
SOAPException(Messages.getMessage("xmlPresent"));
log.error(Messages.getMessage("xmlPresent"), exc);
@@ -1165,18 +1166,20 @@
*/
protected void outputImpl(SerializationContext context) throws
Exception
{
- if (elementRep != null) {
- boolean oldPretty = context.getPretty();
- context.setPretty(false);
- context.writeDOMElement(elementRep);
- context.setPretty(oldPretty);
- return;
- }
-
if (textRep != null) {
boolean oldPretty = context.getPretty();
context.setPretty(false);
- context.writeSafeString(textRep.getData());
+ if (textRep instanceof CDATASection) {
+ context.writeString("<![CDATA[");
+ context.writeString(((Text)textRep).getData());
+ context.writeString("]]>");
+ } else if (textRep instanceof Comment) {
+ context.writeString("<!--");
+ context.writeString(((CharacterData)textRep).getData());
+ context.writeString("-->");
+ } else if (textRep instanceof Text) {
+ context.writeSafeString(((Text)textRep).getData());
+ }
context.setPretty(oldPretty);
return;
}
@@ -1727,5 +1730,51 @@
if (obj == null || !(obj instanceof MessageElement))
return false;
return toString().equals(obj.toString());
+ }
+
+ private void copyNode(org.w3c.dom.Node element) {
+ copyNode(this, element);
+ }
+
+ private void copyNode(MessageElement parent, org.w3c.dom.Node
element)
+ {
+ parent.setPrefix(element.getPrefix());
+ if(element.getLocalName() != null) {
+ parent.setQName(new QName(element.getNamespaceURI(),
element.getLocalName()));
+ }
+
+ org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
+ for(int i = 0; i < attrs.getLength(); i++){
+ org.w3c.dom.Node att = attrs.item(i);
+ if (att.getNamespaceURI() != null &&
+ att.getPrefix() != null &&
+ att.getNamespaceURI().equals(Constants.NS_URI_XMLNS) &&
+ att.getPrefix().equals("xmlns")) {
+ Mapping map = new Mapping(att.getNodeValue(),
att.getLocalName());
+ addMapping(map);
+ }
+ parent.addAttribute(att.getPrefix(),
+ att.getNamespaceURI(),
+ att.getLocalName(),
+ att.getNodeValue());
+ }
+
+ org.w3c.dom.NodeList children = element.getChildNodes();
+ for(int i = 0; i < children.getLength(); i++){
+ org.w3c.dom.Node child = children.item(i);
+ if(child.getNodeType()==TEXT_NODE ||
+ child.getNodeType()==CDATA_SECTION_NODE ||
+ child.getNodeType()==COMMENT_NODE ) {
+ MessageElement childElement = new
MessageElement((CharacterData)child);
+ parent.appendChild(childElement);
+ } else {
+ PrefixedQName qname = new
PrefixedQName(child.getNamespaceURI(),
+ child.getLocalName(),
+ child.getPrefix());
+ MessageElement childElement = new MessageElement(qname);
+ parent.appendChild(childElement);
+ copyNode(childElement, child);
+ }
+ }
}
}
1.8 +1 -1 ws-axis/java/test/wsdl/sequence/SequenceService.java
Index: SequenceService.java
===================================================================
RCS file: /home/cvs/ws-axis/java/test/wsdl/sequence/SequenceService.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SequenceService.java 25 Feb 2004 14:03:05 -0000 1.7
+++ SequenceService.java 24 Jun 2004 12:27:37 -0000 1.8
@@ -78,7 +78,7 @@
success = true;
}
- resultElement = retDoc.createElement("return");
+ resultElement = retDoc.createElementNS(null,"return");
String resultStr = "false";
if (success) {
1.111 +3 -0
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.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- SerializationContextImpl.java 8 Jun 2004 19:45:48 -0000
1.110
+++ SerializationContextImpl.java 24 Jun 2004 12:27:37 -0000
1.111
@@ -403,6 +403,9 @@
if (prefix == null) {
if (defaultPrefix == null) {
prefix = "ns" + lastPrefixIndex++;
+ while(nsStack.getNamespaceURI(prefix)!=null) {
+ prefix = "ns" + lastPrefixIndex++;
+ }
} else {
prefix = defaultPrefix;
}
1.19 +3 -3 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- TestDOM.java 18 Nov 2003 22:36:37 -0000 1.18
+++ TestDOM.java 24 Jun 2004 12:27:38 -0000 1.19
@@ -123,14 +123,14 @@
public void testEmptyNode() throws Exception
{
- SOAPBodyElement body = new
SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
+ SOAPBodyElement body = new
SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
assertXMLEqual("<tmp/>",body.toString());
}
public void testNodeWithAttribute() throws Exception
{
- org.w3c.dom.Element element =
XMLUtils.newDocument().createElement("tmp");
- element.setAttribute("attrib", "foo");
+ org.w3c.dom.Element element =
XMLUtils.newDocument().createElementNS(null,"tmp");
+ element.setAttributeNS(null,"attrib", "foo");
SOAPBodyElement body = new SOAPBodyElement(element);
assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
}
1.15 +75 -10 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- TestMessageElement.java 10 Apr 2004 21:12:06 -0000 1.14
+++ TestMessageElement.java 24 Jun 2004 12:27:38 -0000 1.15
@@ -16,7 +16,6 @@
package test.message;
-import junit.framework.TestCase;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.client.AxisClient;
@@ -26,30 +25,37 @@
import org.apache.axis.message.MessageElement;
import org.apache.axis.message.PrefixedQName;
import org.apache.axis.soap.SOAPConstants;
+import org.apache.axis.utils.XMLUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.CDATASection;
import org.xml.sax.Attributes;
+import test.AxisTestBase;
import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
-import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPBodyElement;
-import java.util.Iterator;
-import java.io.StringReader;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectOutputStream;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringReader;
+import java.util.Iterator;
/**
* Test MessageElement class.
*
* @author Glyn Normington (glyn@apache.org)
*/
-public class TestMessageElement extends TestCase {
+public class TestMessageElement extends AxisTestBase {
public TestMessageElement(String name) {
super(name);
@@ -241,6 +247,65 @@
assertEquals("m1 is not the same as m2", m1, m2);
assertEquals("m2 is not the same as m1", m2, m1);
+ }
+
+ public void testElementConstructor() throws Exception {
+ String xmlIn = "<h:html xmlns:xdc=\"http://www.xml.com/books\"\n"
+
+ "
xmlns:h=\"http://www.w3.org/HTML/1998/html4\">\n" +
+ " <h:head><h:title>Book
Review</h:title></h:head>\n" +
+ " <h:body>\n" +
+ " <xdc:bookreview>\n" +
+ " <xdc:title>XML: A Primer</xdc:title>\n" +
+ " <h:table>\n" +
+ " <h:tr align=\"center\">\n" +
+ " <h:td>Author</h:td><h:td>Price</h:td>\n" +
+ "
<h:td>Pages</h:td><h:td>Date</h:td></h:tr>\n" +
+ " <!-- here is a comment -->\n" +
+ " <h:tr align=\"left\">\n" +
+ " <h:td><xdc:author>Simon St.
Laurent</xdc:author></h:td>\n" +
+ " <h:td><xdc:price>31.98</xdc:price></h:td>\n"
+
+ " <h:td><xdc:pages>352</xdc:pages></h:td>\n" +
+ " <h:td><xdc:date>1998/01</xdc:date></h:td>\n"
+
+ " <h:td><![CDATA[text content]]></h:td>\n" +
+ " </h:tr>\n" +
+ " </h:table>\n" +
+ " </xdc:bookreview>\n" +
+ " </h:body>\n" +
+ "</h:html>";
+
+ Document doc = XMLUtils.newDocument(new
ByteArrayInputStream(xmlIn.getBytes()));
+ MessageElement me = new MessageElement(doc.getDocumentElement());
+ String xmlOut = me.getAsString();
+ this.assertXMLEqual(xmlIn,xmlOut);
+ }
+
+ public void testElementConstructor2() throws Exception {
+ String xmlIn = "<!-- This file can be used to deploy the
echoAttachments sample -->\n" +
+ "<!-- using this command: java
org.apache.axis.client.AdminClient attachdeploy.wsdd -->\n" +
+ "\n" +
+ "<!-- This deploys the echo attachment service. -->\n" +
+ "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\"
xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\"
xmlns:ns1=\"urn:EchoAttachmentsService\" >\n" +
+ " <service name=\"urn:EchoAttachmentsService\"
provider=\"java:RPC\" >\n" +
+ " <parameter name=\"className\"
value=\"samples.attachments.EchoAttachmentsService\"/>\n" +
+ " <parameter name=\"allowedMethods\" value=\"echo
echoDir\"/>\n" +
+ " <operation name=\"echo\" returnQName=\"returnqname\"
returnType=\"ns1:DataHandler\" >\n" +
+ " <parameter name=\"dh\"
type=\"ns1:DataHandler\"/>\n" +
+ " </operation>\n" +
+ "\n" +
+ " <typeMapping
deserializer=\"org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactor
y\"\n" +
+ "
languageSpecificType=\"java:javax.activation.DataHandler\"
qname=\"ns1:DataHandler\"\n" +
+ "
serializer=\"org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory\"\
n" +
+ "
encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
+ " />\n" +
+ " </service>\n" +
+ "\n" +
+ "</deployment>";
+
+ Document doc = XMLUtils.newDocument(new
ByteArrayInputStream(xmlIn.getBytes()));
+ MessageElement me = new MessageElement(doc.getDocumentElement());
+ String xmlOut = me.getAsString();
+ System.out.println(xmlOut);
+ this.assertXMLEqual(xmlIn,xmlOut);
}
public static void main(String[] args) throws Exception {
Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
Posted by Davanum Srinivas <da...@gmail.com>.
don't worry about it...just send me the test case :)
-- dims
On Wed, 7 Jul 2004 10:38:15 +0900, Jongjin Choi <gu...@hotmail.com> wrote:
> Hi, dims.
>
> Sorry for late response.
>
> I have a very simple test case for this probelm.
> From yesterday, I am checking some other SAAJ issue you refactored that may
> be related to this problem,
> so I was going to put off opening a JIRA bug report for this until I have an
> idea for the SAAJ issue.
>
> But it seems to take some time so I will open an JIRA report for the test
> case.
> I think the other SAAJ issues may be resolved if you fix it.
>
> /Jongjin
>
>
>
> -----Original Message-----
> From: Davanum Srinivas [mailto:davanum@gmail.com]
> Sent: Wednesday, July 07, 2004 6:19 AM
> To: Jongjin Choi
> Cc: axis-dev@ws.apache.org
> Subject: Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
>
> Jongjin,
>
> I'd REALLY like to take a stab at fixing this before the next cut. i'd be
> grateful if you can help me with a test case to recreate the problem :)
>
> -- dims
>
> On Mon, 5 Jul 2004 14:50:30 -0400, Davanum Srinivas <da...@gmail.com>
> wrote:
> > Jongjin,
> >
> > I was hunting for a test case...can u please add it to JIRA? That's
> > exactly i had not marked the bug as closed :)
> >
> > thanks,
> > dims
> >
> >
> >
> >
> > On Mon, 5 Jul 2004 23:38:58 +0900, Jongjin Choi <gu...@hotmail.com>
> wrote:
> > > Hi, dims.
> > >
> > > I looked into the following MessageElement changes and ran a test.
> > > Does this change resolve the problem RPCParam <-> SOAP Element
> > > mapping addressed in http://nagoya.apache.org/jira/browse/AXIS-1416?
> > >
> > > I made a simple test and found that the problem is remaining.
> > >
> > > Without resolving the AXIS-1416,
> > > the standard JAX-RPC handler under Axis can not read or modify the
> > > second and below level SOAP body elements.
> > >
> > > Thanks.
> > >
> > > -----Original Message-----
> > > From: dims@apache.org [mailto:dims@apache.org]
> > > Sent: Thursday, June 24, 2004 9:28 PM
> > > To: ws-axis-cvs@apache.org
> > > Subject: cvs commit: ws-axis/java/test/message
> > > TestMessageElement.java
> > >
> > > dims 2004/06/24 05:27:38
> > >
> > > Modified: java/test/wsdl/faults FaultServiceSoapBindingImpl.java
> > > java/src/org/apache/axis/message MessageElement.java
> > > java/test/wsdl/sequence SequenceService.java
> > > java/src/org/apache/axis/encoding
> > > SerializationContextImpl.java
> > > java/test/encoding TestDOM.java
> > > java/test/message TestMessageElement.java
> > > Log:
> > > Fix for AXIS-1350 - new MessageElement(new Element()) does not
> > > behave like an Element
> > > Fix for AXIS-616 - MessageElement is not for mortals
> > > Fix for AXIS-1054 - No way to non-default namespace prefixes when
> > > creating MessageElements from DOM elements
> > > Fix for AXIS-1403 - calling MessageElement#getChildren with a
> > > Text-Only content returns an empty list
> > >
> > > Notes:
> > > - traverse all the nodes recursively and create new
> > > MessageElement's for each node.
> > >
> > > Revision Changes Path
> > > 1.5 +1 -1
> > > ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java
> > >
> > > Index: FaultServiceSoapBindingImpl.java
> > > ===================================================================
> > > RCS file:
> > >
> /home/cvs/ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java,v
> > > retrieving revision 1.4
> > > retrieving revision 1.5
> > > diff -u -r1.4 -r1.5
> > > --- FaultServiceSoapBindingImpl.java 11 Dec 2002 22:40:20 -0000
> 1.4
> > > +++ FaultServiceSoapBindingImpl.java 24 Jun 2004 12:27:37 -0000
> 1.5
> > > @@ -23,7 +23,7 @@
> > > public int throwExtensionFault(java.lang.String description)
> > > throws java.rmi.RemoteException, test.wsdl.faults.ExtensionFault {
> > > ExtensionType extension = new ExtensionType();
> > > try {
> > > - extension.set_any(new MessageElement[] {new
> > > MessageElement(XMLUtils.newDocument().createElement(description))});
> > > + extension.set_any(new MessageElement[] {new
> > >
> MessageElement(XMLUtils.newDocument().createElementNS(null,description))});
> > > } catch (Exception e) {
> > > throw new java.rmi.RemoteException(e.getMessage());
> > > }
> > >
> > > 1.173 +85 -36
> > > 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.172
> > > retrieving revision 1.173
> > > diff -u -r1.172 -r1.173
> > > --- MessageElement.java 23 Jun 2004 04:14:31 -0000 1.172
> > > +++ MessageElement.java 24 Jun 2004 12:27:37 -0000 1.173
> > > @@ -16,22 +16,6 @@
> > >
> > > package org.apache.axis.message;
> > >
> > > -import java.io.Reader;
> > > -import java.io.Serializable;
> > > -import java.io.StringReader;
> > > -import java.io.StringWriter;
> > > -import java.util.ArrayList;
> > > -import java.util.Iterator;
> > > -import java.util.Vector;
> > > -import java.util.Enumeration;
> > > -import java.util.List;
> > > -
> > > -import javax.xml.namespace.QName;
> > > -import javax.xml.rpc.encoding.TypeMapping;
> > > -import javax.xml.soap.Name;
> > > -import javax.xml.soap.SOAPElement;
> > > -import javax.xml.soap.SOAPException;
> > > -
> > > import org.apache.axis.AxisFault;
> > > import org.apache.axis.Constants;
> > > import org.apache.axis.MessageContext;
> > > @@ -48,6 +32,9 @@
> > > import org.apache.axis.utils.XMLUtils;
> > > import org.apache.commons.logging.Log;
> > > import org.w3c.dom.Attr;
> > > +import org.w3c.dom.CDATASection;
> > > +import org.w3c.dom.CharacterData;
> > > +import org.w3c.dom.Comment;
> > > import org.w3c.dom.DOMException;
> > > import org.w3c.dom.Document;
> > > import org.w3c.dom.Element;
> > > @@ -61,6 +48,21 @@
> > > import org.xml.sax.SAXException;
> > > import org.xml.sax.helpers.AttributesImpl;
> > >
> > > +import javax.xml.namespace.QName;
> > > +import javax.xml.rpc.encoding.TypeMapping;
> > > +import javax.xml.soap.Name;
> > > +import javax.xml.soap.SOAPElement;
> > > +import javax.xml.soap.SOAPException;
> > > +import java.io.Reader;
> > > +import java.io.Serializable;
> > > +import java.io.StringReader;
> > > +import java.io.StringWriter;
> > > +import java.util.ArrayList;
> > > +import java.util.Enumeration;
> > > +import java.util.Iterator;
> > > +import java.util.List;
> > > +import java.util.Vector;
> > > +
> > > /*
> > > * MessageElement is the base type of nodes of the SOAP message
> > > parse tree.
> > > *
> > > @@ -106,8 +108,7 @@
> > > protected int endEventIndex = -1;
> > >
> > > // ...or as DOM
> > > - protected Element elementRep = null;
> > > - protected Text textRep = null;
> > > + protected CharacterData textRep = null;
> > >
> > > protected MessageElement parent = null;
> > >
> > > @@ -163,12 +164,12 @@
> > >
> > > public MessageElement(Element elem)
> > > {
> > > - elementRep = elem;
> > > namespaceURI = elem.getNamespaceURI();
> > > name = elem.getLocalName();
> > > + copyNode(elem);
> > > }
> > >
> > > - public MessageElement(Text text)
> > > + public MessageElement(CharacterData text)
> > > {
> > > textRep = text;
> > > namespaceURI = text.getNamespaceURI();
> > > @@ -399,8 +400,7 @@
> > > * protected int startEventIndex = 0; N?
> > > * protected int startContentsIndex = 0; N?
> > > * protected int endEventIndex = -1; N?
> > > - * protected Element elementRep = null; N?
> > > - * protected Text textRep = null; Y?
> > > + * protected CharacterData textRep = null; Y?
> > > * protected MessageElement parent = null; N
> > > * public ArrayList namespaces = null; Y
> > > * protected String encodingStyle = null; N?
> > > @@ -608,7 +608,13 @@
> > >
> > > public short getNodeType() {
> > > if(this.textRep != null) {
> > > + if(textRep instanceof Comment) {
> > > + return COMMENT_NODE;
> > > + } else if(textRep instanceof CDATASection) {
> > > + return CDATA_SECTION_NODE;
> > > + } else {
> > > return TEXT_NODE;
> > > + }
> > > }else if(false){
> > > return DOCUMENT_FRAGMENT_NODE;
> > > }else if(false){
> > > @@ -908,11 +914,6 @@
> > > log.error(Messages.getMessage("childPresent"), exc);
> > > throw exc;
> > > }
> > > - if (elementRep != null) {
> > > - SOAPException exc = new
> > > SOAPException(Messages.getMessage("xmlPresent"));
> > > - log.error(Messages.getMessage("xmlPresent"), exc);
> > > - throw exc;
> > > - }
> > > if (textRep != null) {
> > > SOAPException exc = new
> > > SOAPException(Messages.getMessage("xmlPresent"));
> > > log.error(Messages.getMessage("xmlPresent"), exc);
> > > @@ -1165,18 +1166,20 @@
> > > */
> > > protected void outputImpl(SerializationContext context)
> > > throws Exception
> > > {
> > > - if (elementRep != null) {
> > > - boolean oldPretty = context.getPretty();
> > > - context.setPretty(false);
> > > - context.writeDOMElement(elementRep);
> > > - context.setPretty(oldPretty);
> > > - return;
> > > - }
> > > -
> > > if (textRep != null) {
> > > boolean oldPretty = context.getPretty();
> > > context.setPretty(false);
> > > - context.writeSafeString(textRep.getData());
> > > + if (textRep instanceof CDATASection) {
> > > + context.writeString("<![CDATA[");
> > > + context.writeString(((Text)textRep).getData());
> > > + context.writeString("]]>");
> > > + } else if (textRep instanceof Comment) {
> > > + context.writeString("<!--");
> > > +
> context.writeString(((CharacterData)textRep).getData());
> > > + context.writeString("-->");
> > > + } else if (textRep instanceof Text) {
> > > + context.writeSafeString(((Text)textRep).getData());
> > > + }
> > > context.setPretty(oldPretty);
> > > return;
> > > }
> > > @@ -1727,5 +1730,51 @@
> > > if (obj == null || !(obj instanceof MessageElement))
> > > return false;
> > > return toString().equals(obj.toString());
> > > + }
> > > +
> > > + private void copyNode(org.w3c.dom.Node element) {
> > > + copyNode(this, element);
> > > + }
> > > +
> > > + private void copyNode(MessageElement parent, org.w3c.dom.Node
> > > element)
> > > + {
> > > + parent.setPrefix(element.getPrefix());
> > > + if(element.getLocalName() != null) {
> > > + parent.setQName(new QName(element.getNamespaceURI(),
> > > element.getLocalName()));
> > > + }
> > > +
> > > + org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
> > > + for(int i = 0; i < attrs.getLength(); i++){
> > > + org.w3c.dom.Node att = attrs.item(i);
> > > + if (att.getNamespaceURI() != null &&
> > > + att.getPrefix() != null &&
> > > + att.getNamespaceURI().equals(Constants.NS_URI_XMLNS)
> &&
> > > + att.getPrefix().equals("xmlns")) {
> > > + Mapping map = new Mapping(att.getNodeValue(),
> > > att.getLocalName());
> > > + addMapping(map);
> > > + }
> > > + parent.addAttribute(att.getPrefix(),
> > > + att.getNamespaceURI(),
> > > + att.getLocalName(),
> > > + att.getNodeValue());
> > > + }
> > > +
> > > + org.w3c.dom.NodeList children = element.getChildNodes();
> > > + for(int i = 0; i < children.getLength(); i++){
> > > + org.w3c.dom.Node child = children.item(i);
> > > + if(child.getNodeType()==TEXT_NODE ||
> > > + child.getNodeType()==CDATA_SECTION_NODE ||
> > > + child.getNodeType()==COMMENT_NODE ) {
> > > + MessageElement childElement = new
> > > MessageElement((CharacterData)child);
> > > + parent.appendChild(childElement);
> > > + } else {
> > > + PrefixedQName qname = new
> > > PrefixedQName(child.getNamespaceURI(),
> > > + child.getLocalName(),
> > > + child.getPrefix());
> > > + MessageElement childElement = new
> MessageElement(qname);
> > > + parent.appendChild(childElement);
> > > + copyNode(childElement, child);
> > > + }
> > > + }
> > > }
> > > }
> > >
> > > 1.8 +1 -1
> ws-axis/java/test/wsdl/sequence/SequenceService.java
> > >
> > > Index: SequenceService.java
> > > ===================================================================
> > > RCS file:
> /home/cvs/ws-axis/java/test/wsdl/sequence/SequenceService.java,v
> > > retrieving revision 1.7
> > > retrieving revision 1.8
> > > diff -u -r1.7 -r1.8
> > > --- SequenceService.java 25 Feb 2004 14:03:05 -0000 1.7
> > > +++ SequenceService.java 24 Jun 2004 12:27:37 -0000 1.8
> > > @@ -78,7 +78,7 @@
> > > success = true;
> > > }
> > >
> > > - resultElement = retDoc.createElement("return");
> > > + resultElement = retDoc.createElementNS(null,"return");
> > >
> > > String resultStr = "false";
> > > if (success) {
> > >
> > > 1.111 +3 -0
> > > ws-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.j
> > > ava
> > >
> > > Index: SerializationContextImpl.java
> > > ===================================================================
> > > RCS file:
> > > /home/cvs/ws-axis/java/src/org/apache/axis/encoding/SerializationCon
> > > textImpl
> > > java,v
> > > retrieving revision 1.110
> > > retrieving revision 1.111
> > > diff -u -r1.110 -r1.111
> > > --- SerializationContextImpl.java 8 Jun 2004 19:45:48 -0000
> > > 1.110
> > > +++ SerializationContextImpl.java 24 Jun 2004 12:27:37 -0000
> > > 1.111
> > > @@ -403,6 +403,9 @@
> > > if (prefix == null) {
> > > if (defaultPrefix == null) {
> > > prefix = "ns" + lastPrefixIndex++;
> > > + while(nsStack.getNamespaceURI(prefix)!=null) {
> > > + prefix = "ns" + lastPrefixIndex++;
> > > + }
> > > } else {
> > > prefix = defaultPrefix;
> > > }
> > >
> > > 1.19 +3 -3 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.18
> > > retrieving revision 1.19
> > > diff -u -r1.18 -r1.19
> > > --- TestDOM.java 18 Nov 2003 22:36:37 -0000 1.18
> > > +++ TestDOM.java 24 Jun 2004 12:27:38 -0000 1.19
> > > @@ -123,14 +123,14 @@
> > >
> > > public void testEmptyNode() throws Exception
> > > {
> > > - SOAPBodyElement body = new
> > > SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
> > > + SOAPBodyElement body = new
> > > SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
> > > assertXMLEqual("<tmp/>",body.toString());
> > > }
> > >
> > > public void testNodeWithAttribute() throws Exception
> > > {
> > > - org.w3c.dom.Element element =
> > > XMLUtils.newDocument().createElement("tmp");
> > > - element.setAttribute("attrib", "foo");
> > > + org.w3c.dom.Element element =
> > > XMLUtils.newDocument().createElementNS(null,"tmp");
> > > + element.setAttributeNS(null,"attrib", "foo");
> > > SOAPBodyElement body = new SOAPBodyElement(element);
> > > assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
> > > }
> > >
> > > 1.15 +75 -10 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.14
> > > retrieving revision 1.15
> > > diff -u -r1.14 -r1.15
> > > --- TestMessageElement.java 10 Apr 2004 21:12:06 -0000 1.14
> > > +++ TestMessageElement.java 24 Jun 2004 12:27:38 -0000 1.15
> > > @@ -16,7 +16,6 @@
> > >
> > > package test.message;
> > >
> > > -import junit.framework.TestCase;
> > > import org.apache.axis.Message;
> > > import org.apache.axis.MessageContext;
> > > import org.apache.axis.client.AxisClient;
> > > @@ -26,30 +25,37 @@
> > > import org.apache.axis.message.MessageElement;
> > > import org.apache.axis.message.PrefixedQName;
> > > import org.apache.axis.soap.SOAPConstants;
> > > +import org.apache.axis.utils.XMLUtils;
> > > +import org.w3c.dom.Document;
> > > +import org.w3c.dom.Element;
> > > +import org.w3c.dom.CDATASection;
> > > import org.xml.sax.Attributes;
> > > +import test.AxisTestBase;
> > >
> > > import javax.xml.namespace.QName;
> > > +import javax.xml.soap.MessageFactory;
> > > import javax.xml.soap.Name;
> > > +import javax.xml.soap.SOAPBody;
> > > +import javax.xml.soap.SOAPBodyElement;
> > > import javax.xml.soap.SOAPElement;
> > > -import javax.xml.soap.MessageFactory;
> > > +import javax.xml.soap.SOAPEnvelope;
> > > import javax.xml.soap.SOAPMessage;
> > > import javax.xml.soap.SOAPPart;
> > > -import javax.xml.soap.SOAPEnvelope;
> > > -import javax.xml.soap.SOAPBody;
> > > -import javax.xml.soap.SOAPBodyElement;
> > > -import java.util.Iterator;
> > > -import java.io.StringReader;
> > > -import java.io.ByteArrayOutputStream;
> > > -import java.io.ObjectOutputStream;
> > > +import javax.xml.parsers.DocumentBuilderFactory;
> > > +import javax.xml.parsers.DocumentBuilder;
> > > import java.io.ByteArrayInputStream;
> > > +import java.io.ByteArrayOutputStream;
> > > import java.io.ObjectInputStream;
> > > +import java.io.ObjectOutputStream;
> > > +import java.io.StringReader;
> > > +import java.util.Iterator;
> > >
> > > /**
> > > * Test MessageElement class.
> > > *
> > > * @author Glyn Normington (glyn@apache.org)
> > > */
> > > -public class TestMessageElement extends TestCase {
> > > +public class TestMessageElement extends AxisTestBase {
> > >
> > > public TestMessageElement(String name) {
> > > super(name);
> > > @@ -241,6 +247,65 @@
> > >
> > > assertEquals("m1 is not the same as m2", m1, m2);
> > > assertEquals("m2 is not the same as m1", m2, m1);
> > > + }
> > > +
> > > + public void testElementConstructor() throws Exception {
> > > + String xmlIn = "<h:html
> xmlns:xdc=\"http://www.xml.com/books\"\n"
> > > +
> > > + "
> > > xmlns:h=\"http://www.w3.org/HTML/1998/html4\">\n" +
> > > + " <h:head><h:title>Book
> > > Review</h:title></h:head>\n" +
> > > + " <h:body>\n" +
> > > + " <xdc:bookreview>\n" +
> > > + " <xdc:title>XML: A Primer</xdc:title>\n" +
> > > + " <h:table>\n" +
> > > + " <h:tr align=\"center\">\n" +
> > > + " <h:td>Author</h:td><h:td>Price</h:td>\n"
> +
> > > + "
> > > <h:td>Pages</h:td><h:td>Date</h:td></h:tr>\n" +
> > > + " <!-- here is a comment -->\n" +
> > > + " <h:tr align=\"left\">\n" +
> > > + " <h:td><xdc:author>Simon St.
> > > Laurent</xdc:author></h:td>\n" +
> > > + "
> <h:td><xdc:price>31.98</xdc:price></h:td>\n"
> > > +
> > > + "
> <h:td><xdc:pages>352</xdc:pages></h:td>\n" +
> > > + "
> <h:td><xdc:date>1998/01</xdc:date></h:td>\n"
> > > +
> > > + " <h:td><![CDATA[text content]]></h:td>\n"
> +
> > > + " </h:tr>\n" +
> > > + " </h:table>\n" +
> > > + " </xdc:bookreview>\n" +
> > > + " </h:body>\n" +
> > > + "</h:html>";
> > > +
> > > + Document doc = XMLUtils.newDocument(new
> > > ByteArrayInputStream(xmlIn.getBytes()));
> > > + MessageElement me = new
> MessageElement(doc.getDocumentElement());
> > > + String xmlOut = me.getAsString();
> > > + this.assertXMLEqual(xmlIn,xmlOut);
> > > + }
> > > +
> > > + public void testElementConstructor2() throws Exception {
> > > + String xmlIn = "<!-- This file can be used to deploy the
> > > echoAttachments sample -->\n" +
> > > + "<!-- using this command: java
> > > org.apache.axis.client.AdminClient attachdeploy.wsdd -->\n" +
> > > + "\n" +
> > > + "<!-- This deploys the echo attachment service.
> -->\n" +
> > > + "<deployment
> xmlns=\"http://xml.apache.org/axis/wsdd/\"
> > > xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\"
> > > xmlns:ns1=\"urn:EchoAttachmentsService\" >\n" +
> > > + " <service name=\"urn:EchoAttachmentsService\"
> > > provider=\"java:RPC\" >\n" +
> > > + " <parameter name=\"className\"
> > > value=\"samples.attachments.EchoAttachmentsService\"/>\n" +
> > > + " <parameter name=\"allowedMethods\" value=\"echo
> > > echoDir\"/>\n" +
> > > + " <operation name=\"echo\"
> returnQName=\"returnqname\"
> > > returnType=\"ns1:DataHandler\" >\n" +
> > > + " <parameter name=\"dh\"
> > > type=\"ns1:DataHandler\"/>\n" +
> > > + " </operation>\n" +
> > > + "\n" +
> > > + " <typeMapping
> > > deserializer=\"org.apache.axis.encoding.ser.JAFDataHandlerDeserializ
> > > erFactor
> > > y\"\n" +
> > > + "
> > > languageSpecificType=\"java:javax.activation.DataHandler\"
> > > qname=\"ns1:DataHandler\"\n" +
> > > + "
> > > serializer=\"org.apache.axis.encoding.ser.JAFDataHandlerSerializerFa
> > > ctory\"\
> > > n" +
> > > + "
> > > encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
> > > + " />\n" +
> > > + " </service>\n" +
> > > + "\n" +
> > > + "</deployment>";
> > > +
> > > + Document doc = XMLUtils.newDocument(new
> > > ByteArrayInputStream(xmlIn.getBytes()));
> > > + MessageElement me = new
> MessageElement(doc.getDocumentElement());
> > > + String xmlOut = me.getAsString();
> > > + System.out.println(xmlOut);
> > > + this.assertXMLEqual(xmlIn,xmlOut);
> > > }
> > >
> > > public static void main(String[] args) throws Exception {
> > >
> > >
> >
> >
> > --
> > Davanum Srinivas - http://webservices.apache.org/~dims/
> >
>
> --
> Davanum Srinivas - http://webservices.apache.org/~dims/
>
--
Davanum Srinivas - http://webservices.apache.org/~dims/
Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
Posted by Davanum Srinivas <da...@gmail.com>.
Jongin,
Fixed this problem. Please try latest CVS.
thanks,
dims
On Wed, 7 Jul 2004 10:38:15 +0900, Jongjin Choi <gu...@hotmail.com> wrote:
> Hi, dims.
>
> Sorry for late response.
>
> I have a very simple test case for this probelm.
> From yesterday, I am checking some other SAAJ issue you refactored that may
> be related to this problem,
> so I was going to put off opening a JIRA bug report for this until I have an
> idea for the SAAJ issue.
>
> But it seems to take some time so I will open an JIRA report for the test
> case.
> I think the other SAAJ issues may be resolved if you fix it.
>
> /Jongjin
>
>
>
> -----Original Message-----
> From: Davanum Srinivas [mailto:davanum@gmail.com]
> Sent: Wednesday, July 07, 2004 6:19 AM
> To: Jongjin Choi
> Cc: axis-dev@ws.apache.org
> Subject: Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
>
> Jongjin,
>
> I'd REALLY like to take a stab at fixing this before the next cut. i'd be
> grateful if you can help me with a test case to recreate the problem :)
>
> -- dims
>
> On Mon, 5 Jul 2004 14:50:30 -0400, Davanum Srinivas <da...@gmail.com>
> wrote:
> > Jongjin,
> >
> > I was hunting for a test case...can u please add it to JIRA? That's
> > exactly i had not marked the bug as closed :)
> >
> > thanks,
> > dims
> >
> >
> >
> >
> > On Mon, 5 Jul 2004 23:38:58 +0900, Jongjin Choi <gu...@hotmail.com>
> wrote:
> > > Hi, dims.
> > >
> > > I looked into the following MessageElement changes and ran a test.
> > > Does this change resolve the problem RPCParam <-> SOAP Element
> > > mapping addressed in http://nagoya.apache.org/jira/browse/AXIS-1416?
> > >
> > > I made a simple test and found that the problem is remaining.
> > >
> > > Without resolving the AXIS-1416,
> > > the standard JAX-RPC handler under Axis can not read or modify the
> > > second and below level SOAP body elements.
> > >
> > > Thanks.
> > >
> > > -----Original Message-----
> > > From: dims@apache.org [mailto:dims@apache.org]
> > > Sent: Thursday, June 24, 2004 9:28 PM
> > > To: ws-axis-cvs@apache.org
> > > Subject: cvs commit: ws-axis/java/test/message
> > > TestMessageElement.java
> > >
> > > dims 2004/06/24 05:27:38
> > >
> > > Modified: java/test/wsdl/faults FaultServiceSoapBindingImpl.java
> > > java/src/org/apache/axis/message MessageElement.java
> > > java/test/wsdl/sequence SequenceService.java
> > > java/src/org/apache/axis/encoding
> > > SerializationContextImpl.java
> > > java/test/encoding TestDOM.java
> > > java/test/message TestMessageElement.java
> > > Log:
> > > Fix for AXIS-1350 - new MessageElement(new Element()) does not
> > > behave like an Element
> > > Fix for AXIS-616 - MessageElement is not for mortals
> > > Fix for AXIS-1054 - No way to non-default namespace prefixes when
> > > creating MessageElements from DOM elements
> > > Fix for AXIS-1403 - calling MessageElement#getChildren with a
> > > Text-Only content returns an empty list
> > >
> > > Notes:
> > > - traverse all the nodes recursively and create new
> > > MessageElement's for each node.
> > >
> > > Revision Changes Path
> > > 1.5 +1 -1
> > > ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java
> > >
> > > Index: FaultServiceSoapBindingImpl.java
> > > ===================================================================
> > > RCS file:
> > >
> /home/cvs/ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java,v
> > > retrieving revision 1.4
> > > retrieving revision 1.5
> > > diff -u -r1.4 -r1.5
> > > --- FaultServiceSoapBindingImpl.java 11 Dec 2002 22:40:20 -0000
> 1.4
> > > +++ FaultServiceSoapBindingImpl.java 24 Jun 2004 12:27:37 -0000
> 1.5
> > > @@ -23,7 +23,7 @@
> > > public int throwExtensionFault(java.lang.String description)
> > > throws java.rmi.RemoteException, test.wsdl.faults.ExtensionFault {
> > > ExtensionType extension = new ExtensionType();
> > > try {
> > > - extension.set_any(new MessageElement[] {new
> > > MessageElement(XMLUtils.newDocument().createElement(description))});
> > > + extension.set_any(new MessageElement[] {new
> > >
> MessageElement(XMLUtils.newDocument().createElementNS(null,description))});
> > > } catch (Exception e) {
> > > throw new java.rmi.RemoteException(e.getMessage());
> > > }
> > >
> > > 1.173 +85 -36
> > > 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.172
> > > retrieving revision 1.173
> > > diff -u -r1.172 -r1.173
> > > --- MessageElement.java 23 Jun 2004 04:14:31 -0000 1.172
> > > +++ MessageElement.java 24 Jun 2004 12:27:37 -0000 1.173
> > > @@ -16,22 +16,6 @@
> > >
> > > package org.apache.axis.message;
> > >
> > > -import java.io.Reader;
> > > -import java.io.Serializable;
> > > -import java.io.StringReader;
> > > -import java.io.StringWriter;
> > > -import java.util.ArrayList;
> > > -import java.util.Iterator;
> > > -import java.util.Vector;
> > > -import java.util.Enumeration;
> > > -import java.util.List;
> > > -
> > > -import javax.xml.namespace.QName;
> > > -import javax.xml.rpc.encoding.TypeMapping;
> > > -import javax.xml.soap.Name;
> > > -import javax.xml.soap.SOAPElement;
> > > -import javax.xml.soap.SOAPException;
> > > -
> > > import org.apache.axis.AxisFault;
> > > import org.apache.axis.Constants;
> > > import org.apache.axis.MessageContext;
> > > @@ -48,6 +32,9 @@
> > > import org.apache.axis.utils.XMLUtils;
> > > import org.apache.commons.logging.Log;
> > > import org.w3c.dom.Attr;
> > > +import org.w3c.dom.CDATASection;
> > > +import org.w3c.dom.CharacterData;
> > > +import org.w3c.dom.Comment;
> > > import org.w3c.dom.DOMException;
> > > import org.w3c.dom.Document;
> > > import org.w3c.dom.Element;
> > > @@ -61,6 +48,21 @@
> > > import org.xml.sax.SAXException;
> > > import org.xml.sax.helpers.AttributesImpl;
> > >
> > > +import javax.xml.namespace.QName;
> > > +import javax.xml.rpc.encoding.TypeMapping;
> > > +import javax.xml.soap.Name;
> > > +import javax.xml.soap.SOAPElement;
> > > +import javax.xml.soap.SOAPException;
> > > +import java.io.Reader;
> > > +import java.io.Serializable;
> > > +import java.io.StringReader;
> > > +import java.io.StringWriter;
> > > +import java.util.ArrayList;
> > > +import java.util.Enumeration;
> > > +import java.util.Iterator;
> > > +import java.util.List;
> > > +import java.util.Vector;
> > > +
> > > /*
> > > * MessageElement is the base type of nodes of the SOAP message
> > > parse tree.
> > > *
> > > @@ -106,8 +108,7 @@
> > > protected int endEventIndex = -1;
> > >
> > > // ...or as DOM
> > > - protected Element elementRep = null;
> > > - protected Text textRep = null;
> > > + protected CharacterData textRep = null;
> > >
> > > protected MessageElement parent = null;
> > >
> > > @@ -163,12 +164,12 @@
> > >
> > > public MessageElement(Element elem)
> > > {
> > > - elementRep = elem;
> > > namespaceURI = elem.getNamespaceURI();
> > > name = elem.getLocalName();
> > > + copyNode(elem);
> > > }
> > >
> > > - public MessageElement(Text text)
> > > + public MessageElement(CharacterData text)
> > > {
> > > textRep = text;
> > > namespaceURI = text.getNamespaceURI();
> > > @@ -399,8 +400,7 @@
> > > * protected int startEventIndex = 0; N?
> > > * protected int startContentsIndex = 0; N?
> > > * protected int endEventIndex = -1; N?
> > > - * protected Element elementRep = null; N?
> > > - * protected Text textRep = null; Y?
> > > + * protected CharacterData textRep = null; Y?
> > > * protected MessageElement parent = null; N
> > > * public ArrayList namespaces = null; Y
> > > * protected String encodingStyle = null; N?
> > > @@ -608,7 +608,13 @@
> > >
> > > public short getNodeType() {
> > > if(this.textRep != null) {
> > > + if(textRep instanceof Comment) {
> > > + return COMMENT_NODE;
> > > + } else if(textRep instanceof CDATASection) {
> > > + return CDATA_SECTION_NODE;
> > > + } else {
> > > return TEXT_NODE;
> > > + }
> > > }else if(false){
> > > return DOCUMENT_FRAGMENT_NODE;
> > > }else if(false){
> > > @@ -908,11 +914,6 @@
> > > log.error(Messages.getMessage("childPresent"), exc);
> > > throw exc;
> > > }
> > > - if (elementRep != null) {
> > > - SOAPException exc = new
> > > SOAPException(Messages.getMessage("xmlPresent"));
> > > - log.error(Messages.getMessage("xmlPresent"), exc);
> > > - throw exc;
> > > - }
> > > if (textRep != null) {
> > > SOAPException exc = new
> > > SOAPException(Messages.getMessage("xmlPresent"));
> > > log.error(Messages.getMessage("xmlPresent"), exc);
> > > @@ -1165,18 +1166,20 @@
> > > */
> > > protected void outputImpl(SerializationContext context)
> > > throws Exception
> > > {
> > > - if (elementRep != null) {
> > > - boolean oldPretty = context.getPretty();
> > > - context.setPretty(false);
> > > - context.writeDOMElement(elementRep);
> > > - context.setPretty(oldPretty);
> > > - return;
> > > - }
> > > -
> > > if (textRep != null) {
> > > boolean oldPretty = context.getPretty();
> > > context.setPretty(false);
> > > - context.writeSafeString(textRep.getData());
> > > + if (textRep instanceof CDATASection) {
> > > + context.writeString("<![CDATA[");
> > > + context.writeString(((Text)textRep).getData());
> > > + context.writeString("]]>");
> > > + } else if (textRep instanceof Comment) {
> > > + context.writeString("<!--");
> > > +
> context.writeString(((CharacterData)textRep).getData());
> > > + context.writeString("-->");
> > > + } else if (textRep instanceof Text) {
> > > + context.writeSafeString(((Text)textRep).getData());
> > > + }
> > > context.setPretty(oldPretty);
> > > return;
> > > }
> > > @@ -1727,5 +1730,51 @@
> > > if (obj == null || !(obj instanceof MessageElement))
> > > return false;
> > > return toString().equals(obj.toString());
> > > + }
> > > +
> > > + private void copyNode(org.w3c.dom.Node element) {
> > > + copyNode(this, element);
> > > + }
> > > +
> > > + private void copyNode(MessageElement parent, org.w3c.dom.Node
> > > element)
> > > + {
> > > + parent.setPrefix(element.getPrefix());
> > > + if(element.getLocalName() != null) {
> > > + parent.setQName(new QName(element.getNamespaceURI(),
> > > element.getLocalName()));
> > > + }
> > > +
> > > + org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
> > > + for(int i = 0; i < attrs.getLength(); i++){
> > > + org.w3c.dom.Node att = attrs.item(i);
> > > + if (att.getNamespaceURI() != null &&
> > > + att.getPrefix() != null &&
> > > + att.getNamespaceURI().equals(Constants.NS_URI_XMLNS)
> &&
> > > + att.getPrefix().equals("xmlns")) {
> > > + Mapping map = new Mapping(att.getNodeValue(),
> > > att.getLocalName());
> > > + addMapping(map);
> > > + }
> > > + parent.addAttribute(att.getPrefix(),
> > > + att.getNamespaceURI(),
> > > + att.getLocalName(),
> > > + att.getNodeValue());
> > > + }
> > > +
> > > + org.w3c.dom.NodeList children = element.getChildNodes();
> > > + for(int i = 0; i < children.getLength(); i++){
> > > + org.w3c.dom.Node child = children.item(i);
> > > + if(child.getNodeType()==TEXT_NODE ||
> > > + child.getNodeType()==CDATA_SECTION_NODE ||
> > > + child.getNodeType()==COMMENT_NODE ) {
> > > + MessageElement childElement = new
> > > MessageElement((CharacterData)child);
> > > + parent.appendChild(childElement);
> > > + } else {
> > > + PrefixedQName qname = new
> > > PrefixedQName(child.getNamespaceURI(),
> > > + child.getLocalName(),
> > > + child.getPrefix());
> > > + MessageElement childElement = new
> MessageElement(qname);
> > > + parent.appendChild(childElement);
> > > + copyNode(childElement, child);
> > > + }
> > > + }
> > > }
> > > }
> > >
> > > 1.8 +1 -1
> ws-axis/java/test/wsdl/sequence/SequenceService.java
> > >
> > > Index: SequenceService.java
> > > ===================================================================
> > > RCS file:
> /home/cvs/ws-axis/java/test/wsdl/sequence/SequenceService.java,v
> > > retrieving revision 1.7
> > > retrieving revision 1.8
> > > diff -u -r1.7 -r1.8
> > > --- SequenceService.java 25 Feb 2004 14:03:05 -0000 1.7
> > > +++ SequenceService.java 24 Jun 2004 12:27:37 -0000 1.8
> > > @@ -78,7 +78,7 @@
> > > success = true;
> > > }
> > >
> > > - resultElement = retDoc.createElement("return");
> > > + resultElement = retDoc.createElementNS(null,"return");
> > >
> > > String resultStr = "false";
> > > if (success) {
> > >
> > > 1.111 +3 -0
> > > ws-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.j
> > > ava
> > >
> > > Index: SerializationContextImpl.java
> > > ===================================================================
> > > RCS file:
> > > /home/cvs/ws-axis/java/src/org/apache/axis/encoding/SerializationCon
> > > textImpl
> > > java,v
> > > retrieving revision 1.110
> > > retrieving revision 1.111
> > > diff -u -r1.110 -r1.111
> > > --- SerializationContextImpl.java 8 Jun 2004 19:45:48 -0000
> > > 1.110
> > > +++ SerializationContextImpl.java 24 Jun 2004 12:27:37 -0000
> > > 1.111
> > > @@ -403,6 +403,9 @@
> > > if (prefix == null) {
> > > if (defaultPrefix == null) {
> > > prefix = "ns" + lastPrefixIndex++;
> > > + while(nsStack.getNamespaceURI(prefix)!=null) {
> > > + prefix = "ns" + lastPrefixIndex++;
> > > + }
> > > } else {
> > > prefix = defaultPrefix;
> > > }
> > >
> > > 1.19 +3 -3 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.18
> > > retrieving revision 1.19
> > > diff -u -r1.18 -r1.19
> > > --- TestDOM.java 18 Nov 2003 22:36:37 -0000 1.18
> > > +++ TestDOM.java 24 Jun 2004 12:27:38 -0000 1.19
> > > @@ -123,14 +123,14 @@
> > >
> > > public void testEmptyNode() throws Exception
> > > {
> > > - SOAPBodyElement body = new
> > > SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
> > > + SOAPBodyElement body = new
> > > SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
> > > assertXMLEqual("<tmp/>",body.toString());
> > > }
> > >
> > > public void testNodeWithAttribute() throws Exception
> > > {
> > > - org.w3c.dom.Element element =
> > > XMLUtils.newDocument().createElement("tmp");
> > > - element.setAttribute("attrib", "foo");
> > > + org.w3c.dom.Element element =
> > > XMLUtils.newDocument().createElementNS(null,"tmp");
> > > + element.setAttributeNS(null,"attrib", "foo");
> > > SOAPBodyElement body = new SOAPBodyElement(element);
> > > assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
> > > }
> > >
> > > 1.15 +75 -10 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.14
> > > retrieving revision 1.15
> > > diff -u -r1.14 -r1.15
> > > --- TestMessageElement.java 10 Apr 2004 21:12:06 -0000 1.14
> > > +++ TestMessageElement.java 24 Jun 2004 12:27:38 -0000 1.15
> > > @@ -16,7 +16,6 @@
> > >
> > > package test.message;
> > >
> > > -import junit.framework.TestCase;
> > > import org.apache.axis.Message;
> > > import org.apache.axis.MessageContext;
> > > import org.apache.axis.client.AxisClient;
> > > @@ -26,30 +25,37 @@
> > > import org.apache.axis.message.MessageElement;
> > > import org.apache.axis.message.PrefixedQName;
> > > import org.apache.axis.soap.SOAPConstants;
> > > +import org.apache.axis.utils.XMLUtils;
> > > +import org.w3c.dom.Document;
> > > +import org.w3c.dom.Element;
> > > +import org.w3c.dom.CDATASection;
> > > import org.xml.sax.Attributes;
> > > +import test.AxisTestBase;
> > >
> > > import javax.xml.namespace.QName;
> > > +import javax.xml.soap.MessageFactory;
> > > import javax.xml.soap.Name;
> > > +import javax.xml.soap.SOAPBody;
> > > +import javax.xml.soap.SOAPBodyElement;
> > > import javax.xml.soap.SOAPElement;
> > > -import javax.xml.soap.MessageFactory;
> > > +import javax.xml.soap.SOAPEnvelope;
> > > import javax.xml.soap.SOAPMessage;
> > > import javax.xml.soap.SOAPPart;
> > > -import javax.xml.soap.SOAPEnvelope;
> > > -import javax.xml.soap.SOAPBody;
> > > -import javax.xml.soap.SOAPBodyElement;
> > > -import java.util.Iterator;
> > > -import java.io.StringReader;
> > > -import java.io.ByteArrayOutputStream;
> > > -import java.io.ObjectOutputStream;
> > > +import javax.xml.parsers.DocumentBuilderFactory;
> > > +import javax.xml.parsers.DocumentBuilder;
> > > import java.io.ByteArrayInputStream;
> > > +import java.io.ByteArrayOutputStream;
> > > import java.io.ObjectInputStream;
> > > +import java.io.ObjectOutputStream;
> > > +import java.io.StringReader;
> > > +import java.util.Iterator;
> > >
> > > /**
> > > * Test MessageElement class.
> > > *
> > > * @author Glyn Normington (glyn@apache.org)
> > > */
> > > -public class TestMessageElement extends TestCase {
> > > +public class TestMessageElement extends AxisTestBase {
> > >
> > > public TestMessageElement(String name) {
> > > super(name);
> > > @@ -241,6 +247,65 @@
> > >
> > > assertEquals("m1 is not the same as m2", m1, m2);
> > > assertEquals("m2 is not the same as m1", m2, m1);
> > > + }
> > > +
> > > + public void testElementConstructor() throws Exception {
> > > + String xmlIn = "<h:html
> xmlns:xdc=\"http://www.xml.com/books\"\n"
> > > +
> > > + "
> > > xmlns:h=\"http://www.w3.org/HTML/1998/html4\">\n" +
> > > + " <h:head><h:title>Book
> > > Review</h:title></h:head>\n" +
> > > + " <h:body>\n" +
> > > + " <xdc:bookreview>\n" +
> > > + " <xdc:title>XML: A Primer</xdc:title>\n" +
> > > + " <h:table>\n" +
> > > + " <h:tr align=\"center\">\n" +
> > > + " <h:td>Author</h:td><h:td>Price</h:td>\n"
> +
> > > + "
> > > <h:td>Pages</h:td><h:td>Date</h:td></h:tr>\n" +
> > > + " <!-- here is a comment -->\n" +
> > > + " <h:tr align=\"left\">\n" +
> > > + " <h:td><xdc:author>Simon St.
> > > Laurent</xdc:author></h:td>\n" +
> > > + "
> <h:td><xdc:price>31.98</xdc:price></h:td>\n"
> > > +
> > > + "
> <h:td><xdc:pages>352</xdc:pages></h:td>\n" +
> > > + "
> <h:td><xdc:date>1998/01</xdc:date></h:td>\n"
> > > +
> > > + " <h:td><![CDATA[text content]]></h:td>\n"
> +
> > > + " </h:tr>\n" +
> > > + " </h:table>\n" +
> > > + " </xdc:bookreview>\n" +
> > > + " </h:body>\n" +
> > > + "</h:html>";
> > > +
> > > + Document doc = XMLUtils.newDocument(new
> > > ByteArrayInputStream(xmlIn.getBytes()));
> > > + MessageElement me = new
> MessageElement(doc.getDocumentElement());
> > > + String xmlOut = me.getAsString();
> > > + this.assertXMLEqual(xmlIn,xmlOut);
> > > + }
> > > +
> > > + public void testElementConstructor2() throws Exception {
> > > + String xmlIn = "<!-- This file can be used to deploy the
> > > echoAttachments sample -->\n" +
> > > + "<!-- using this command: java
> > > org.apache.axis.client.AdminClient attachdeploy.wsdd -->\n" +
> > > + "\n" +
> > > + "<!-- This deploys the echo attachment service.
> -->\n" +
> > > + "<deployment
> xmlns=\"http://xml.apache.org/axis/wsdd/\"
> > > xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\"
> > > xmlns:ns1=\"urn:EchoAttachmentsService\" >\n" +
> > > + " <service name=\"urn:EchoAttachmentsService\"
> > > provider=\"java:RPC\" >\n" +
> > > + " <parameter name=\"className\"
> > > value=\"samples.attachments.EchoAttachmentsService\"/>\n" +
> > > + " <parameter name=\"allowedMethods\" value=\"echo
> > > echoDir\"/>\n" +
> > > + " <operation name=\"echo\"
> returnQName=\"returnqname\"
> > > returnType=\"ns1:DataHandler\" >\n" +
> > > + " <parameter name=\"dh\"
> > > type=\"ns1:DataHandler\"/>\n" +
> > > + " </operation>\n" +
> > > + "\n" +
> > > + " <typeMapping
> > > deserializer=\"org.apache.axis.encoding.ser.JAFDataHandlerDeserializ
> > > erFactor
> > > y\"\n" +
> > > + "
> > > languageSpecificType=\"java:javax.activation.DataHandler\"
> > > qname=\"ns1:DataHandler\"\n" +
> > > + "
> > > serializer=\"org.apache.axis.encoding.ser.JAFDataHandlerSerializerFa
> > > ctory\"\
> > > n" +
> > > + "
> > > encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
> > > + " />\n" +
> > > + " </service>\n" +
> > > + "\n" +
> > > + "</deployment>";
> > > +
> > > + Document doc = XMLUtils.newDocument(new
> > > ByteArrayInputStream(xmlIn.getBytes()));
> > > + MessageElement me = new
> MessageElement(doc.getDocumentElement());
> > > + String xmlOut = me.getAsString();
> > > + System.out.println(xmlOut);
> > > + this.assertXMLEqual(xmlIn,xmlOut);
> > > }
> > >
> > > public static void main(String[] args) throws Exception {
> > >
> > >
> >
> >
> > --
> > Davanum Srinivas - http://webservices.apache.org/~dims/
> >
>
> --
> Davanum Srinivas - http://webservices.apache.org/~dims/
>
--
Davanum Srinivas - http://webservices.apache.org/~dims/
RE: cvs commit: ws-axis/java/test/message TestMessageElement.java
Posted by Jongjin Choi <gu...@hotmail.com>.
Hi, dims.
Sorry for late response.
I have a very simple test case for this probelm.
>From yesterday, I am checking some other SAAJ issue you refactored that may
be related to this problem,
so I was going to put off opening a JIRA bug report for this until I have an
idea for the SAAJ issue.
But it seems to take some time so I will open an JIRA report for the test
case.
I think the other SAAJ issues may be resolved if you fix it.
/Jongjin
-----Original Message-----
From: Davanum Srinivas [mailto:davanum@gmail.com]
Sent: Wednesday, July 07, 2004 6:19 AM
To: Jongjin Choi
Cc: axis-dev@ws.apache.org
Subject: Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
Jongjin,
I'd REALLY like to take a stab at fixing this before the next cut. i'd be
grateful if you can help me with a test case to recreate the problem :)
-- dims
On Mon, 5 Jul 2004 14:50:30 -0400, Davanum Srinivas <da...@gmail.com>
wrote:
> Jongjin,
>
> I was hunting for a test case...can u please add it to JIRA? That's
> exactly i had not marked the bug as closed :)
>
> thanks,
> dims
>
>
>
>
> On Mon, 5 Jul 2004 23:38:58 +0900, Jongjin Choi <gu...@hotmail.com>
wrote:
> > Hi, dims.
> >
> > I looked into the following MessageElement changes and ran a test.
> > Does this change resolve the problem RPCParam <-> SOAP Element
> > mapping addressed in http://nagoya.apache.org/jira/browse/AXIS-1416?
> >
> > I made a simple test and found that the problem is remaining.
> >
> > Without resolving the AXIS-1416,
> > the standard JAX-RPC handler under Axis can not read or modify the
> > second and below level SOAP body elements.
> >
> > Thanks.
> >
> > -----Original Message-----
> > From: dims@apache.org [mailto:dims@apache.org]
> > Sent: Thursday, June 24, 2004 9:28 PM
> > To: ws-axis-cvs@apache.org
> > Subject: cvs commit: ws-axis/java/test/message
> > TestMessageElement.java
> >
> > dims 2004/06/24 05:27:38
> >
> > Modified: java/test/wsdl/faults FaultServiceSoapBindingImpl.java
> > java/src/org/apache/axis/message MessageElement.java
> > java/test/wsdl/sequence SequenceService.java
> > java/src/org/apache/axis/encoding
> > SerializationContextImpl.java
> > java/test/encoding TestDOM.java
> > java/test/message TestMessageElement.java
> > Log:
> > Fix for AXIS-1350 - new MessageElement(new Element()) does not
> > behave like an Element
> > Fix for AXIS-616 - MessageElement is not for mortals
> > Fix for AXIS-1054 - No way to non-default namespace prefixes when
> > creating MessageElements from DOM elements
> > Fix for AXIS-1403 - calling MessageElement#getChildren with a
> > Text-Only content returns an empty list
> >
> > Notes:
> > - traverse all the nodes recursively and create new
> > MessageElement's for each node.
> >
> > Revision Changes Path
> > 1.5 +1 -1
> > ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java
> >
> > Index: FaultServiceSoapBindingImpl.java
> > ===================================================================
> > RCS file:
> >
/home/cvs/ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java,v
> > retrieving revision 1.4
> > retrieving revision 1.5
> > diff -u -r1.4 -r1.5
> > --- FaultServiceSoapBindingImpl.java 11 Dec 2002 22:40:20 -0000
1.4
> > +++ FaultServiceSoapBindingImpl.java 24 Jun 2004 12:27:37 -0000
1.5
> > @@ -23,7 +23,7 @@
> > public int throwExtensionFault(java.lang.String description)
> > throws java.rmi.RemoteException, test.wsdl.faults.ExtensionFault {
> > ExtensionType extension = new ExtensionType();
> > try {
> > - extension.set_any(new MessageElement[] {new
> > MessageElement(XMLUtils.newDocument().createElement(description))});
> > + extension.set_any(new MessageElement[] {new
> >
MessageElement(XMLUtils.newDocument().createElementNS(null,description))});
> > } catch (Exception e) {
> > throw new java.rmi.RemoteException(e.getMessage());
> > }
> >
> > 1.173 +85 -36
> > 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.172
> > retrieving revision 1.173
> > diff -u -r1.172 -r1.173
> > --- MessageElement.java 23 Jun 2004 04:14:31 -0000 1.172
> > +++ MessageElement.java 24 Jun 2004 12:27:37 -0000 1.173
> > @@ -16,22 +16,6 @@
> >
> > package org.apache.axis.message;
> >
> > -import java.io.Reader;
> > -import java.io.Serializable;
> > -import java.io.StringReader;
> > -import java.io.StringWriter;
> > -import java.util.ArrayList;
> > -import java.util.Iterator;
> > -import java.util.Vector;
> > -import java.util.Enumeration;
> > -import java.util.List;
> > -
> > -import javax.xml.namespace.QName;
> > -import javax.xml.rpc.encoding.TypeMapping;
> > -import javax.xml.soap.Name;
> > -import javax.xml.soap.SOAPElement;
> > -import javax.xml.soap.SOAPException;
> > -
> > import org.apache.axis.AxisFault;
> > import org.apache.axis.Constants;
> > import org.apache.axis.MessageContext;
> > @@ -48,6 +32,9 @@
> > import org.apache.axis.utils.XMLUtils;
> > import org.apache.commons.logging.Log;
> > import org.w3c.dom.Attr;
> > +import org.w3c.dom.CDATASection;
> > +import org.w3c.dom.CharacterData;
> > +import org.w3c.dom.Comment;
> > import org.w3c.dom.DOMException;
> > import org.w3c.dom.Document;
> > import org.w3c.dom.Element;
> > @@ -61,6 +48,21 @@
> > import org.xml.sax.SAXException;
> > import org.xml.sax.helpers.AttributesImpl;
> >
> > +import javax.xml.namespace.QName;
> > +import javax.xml.rpc.encoding.TypeMapping;
> > +import javax.xml.soap.Name;
> > +import javax.xml.soap.SOAPElement;
> > +import javax.xml.soap.SOAPException;
> > +import java.io.Reader;
> > +import java.io.Serializable;
> > +import java.io.StringReader;
> > +import java.io.StringWriter;
> > +import java.util.ArrayList;
> > +import java.util.Enumeration;
> > +import java.util.Iterator;
> > +import java.util.List;
> > +import java.util.Vector;
> > +
> > /*
> > * MessageElement is the base type of nodes of the SOAP message
> > parse tree.
> > *
> > @@ -106,8 +108,7 @@
> > protected int endEventIndex = -1;
> >
> > // ...or as DOM
> > - protected Element elementRep = null;
> > - protected Text textRep = null;
> > + protected CharacterData textRep = null;
> >
> > protected MessageElement parent = null;
> >
> > @@ -163,12 +164,12 @@
> >
> > public MessageElement(Element elem)
> > {
> > - elementRep = elem;
> > namespaceURI = elem.getNamespaceURI();
> > name = elem.getLocalName();
> > + copyNode(elem);
> > }
> >
> > - public MessageElement(Text text)
> > + public MessageElement(CharacterData text)
> > {
> > textRep = text;
> > namespaceURI = text.getNamespaceURI();
> > @@ -399,8 +400,7 @@
> > * protected int startEventIndex = 0; N?
> > * protected int startContentsIndex = 0; N?
> > * protected int endEventIndex = -1; N?
> > - * protected Element elementRep = null; N?
> > - * protected Text textRep = null; Y?
> > + * protected CharacterData textRep = null; Y?
> > * protected MessageElement parent = null; N
> > * public ArrayList namespaces = null; Y
> > * protected String encodingStyle = null; N?
> > @@ -608,7 +608,13 @@
> >
> > public short getNodeType() {
> > if(this.textRep != null) {
> > + if(textRep instanceof Comment) {
> > + return COMMENT_NODE;
> > + } else if(textRep instanceof CDATASection) {
> > + return CDATA_SECTION_NODE;
> > + } else {
> > return TEXT_NODE;
> > + }
> > }else if(false){
> > return DOCUMENT_FRAGMENT_NODE;
> > }else if(false){
> > @@ -908,11 +914,6 @@
> > log.error(Messages.getMessage("childPresent"), exc);
> > throw exc;
> > }
> > - if (elementRep != null) {
> > - SOAPException exc = new
> > SOAPException(Messages.getMessage("xmlPresent"));
> > - log.error(Messages.getMessage("xmlPresent"), exc);
> > - throw exc;
> > - }
> > if (textRep != null) {
> > SOAPException exc = new
> > SOAPException(Messages.getMessage("xmlPresent"));
> > log.error(Messages.getMessage("xmlPresent"), exc);
> > @@ -1165,18 +1166,20 @@
> > */
> > protected void outputImpl(SerializationContext context)
> > throws Exception
> > {
> > - if (elementRep != null) {
> > - boolean oldPretty = context.getPretty();
> > - context.setPretty(false);
> > - context.writeDOMElement(elementRep);
> > - context.setPretty(oldPretty);
> > - return;
> > - }
> > -
> > if (textRep != null) {
> > boolean oldPretty = context.getPretty();
> > context.setPretty(false);
> > - context.writeSafeString(textRep.getData());
> > + if (textRep instanceof CDATASection) {
> > + context.writeString("<![CDATA[");
> > + context.writeString(((Text)textRep).getData());
> > + context.writeString("]]>");
> > + } else if (textRep instanceof Comment) {
> > + context.writeString("<!--");
> > +
context.writeString(((CharacterData)textRep).getData());
> > + context.writeString("-->");
> > + } else if (textRep instanceof Text) {
> > + context.writeSafeString(((Text)textRep).getData());
> > + }
> > context.setPretty(oldPretty);
> > return;
> > }
> > @@ -1727,5 +1730,51 @@
> > if (obj == null || !(obj instanceof MessageElement))
> > return false;
> > return toString().equals(obj.toString());
> > + }
> > +
> > + private void copyNode(org.w3c.dom.Node element) {
> > + copyNode(this, element);
> > + }
> > +
> > + private void copyNode(MessageElement parent, org.w3c.dom.Node
> > element)
> > + {
> > + parent.setPrefix(element.getPrefix());
> > + if(element.getLocalName() != null) {
> > + parent.setQName(new QName(element.getNamespaceURI(),
> > element.getLocalName()));
> > + }
> > +
> > + org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
> > + for(int i = 0; i < attrs.getLength(); i++){
> > + org.w3c.dom.Node att = attrs.item(i);
> > + if (att.getNamespaceURI() != null &&
> > + att.getPrefix() != null &&
> > + att.getNamespaceURI().equals(Constants.NS_URI_XMLNS)
&&
> > + att.getPrefix().equals("xmlns")) {
> > + Mapping map = new Mapping(att.getNodeValue(),
> > att.getLocalName());
> > + addMapping(map);
> > + }
> > + parent.addAttribute(att.getPrefix(),
> > + att.getNamespaceURI(),
> > + att.getLocalName(),
> > + att.getNodeValue());
> > + }
> > +
> > + org.w3c.dom.NodeList children = element.getChildNodes();
> > + for(int i = 0; i < children.getLength(); i++){
> > + org.w3c.dom.Node child = children.item(i);
> > + if(child.getNodeType()==TEXT_NODE ||
> > + child.getNodeType()==CDATA_SECTION_NODE ||
> > + child.getNodeType()==COMMENT_NODE ) {
> > + MessageElement childElement = new
> > MessageElement((CharacterData)child);
> > + parent.appendChild(childElement);
> > + } else {
> > + PrefixedQName qname = new
> > PrefixedQName(child.getNamespaceURI(),
> > + child.getLocalName(),
> > + child.getPrefix());
> > + MessageElement childElement = new
MessageElement(qname);
> > + parent.appendChild(childElement);
> > + copyNode(childElement, child);
> > + }
> > + }
> > }
> > }
> >
> > 1.8 +1 -1
ws-axis/java/test/wsdl/sequence/SequenceService.java
> >
> > Index: SequenceService.java
> > ===================================================================
> > RCS file:
/home/cvs/ws-axis/java/test/wsdl/sequence/SequenceService.java,v
> > retrieving revision 1.7
> > retrieving revision 1.8
> > diff -u -r1.7 -r1.8
> > --- SequenceService.java 25 Feb 2004 14:03:05 -0000 1.7
> > +++ SequenceService.java 24 Jun 2004 12:27:37 -0000 1.8
> > @@ -78,7 +78,7 @@
> > success = true;
> > }
> >
> > - resultElement = retDoc.createElement("return");
> > + resultElement = retDoc.createElementNS(null,"return");
> >
> > String resultStr = "false";
> > if (success) {
> >
> > 1.111 +3 -0
> > ws-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.j
> > ava
> >
> > Index: SerializationContextImpl.java
> > ===================================================================
> > RCS file:
> > /home/cvs/ws-axis/java/src/org/apache/axis/encoding/SerializationCon
> > textImpl
> > java,v
> > retrieving revision 1.110
> > retrieving revision 1.111
> > diff -u -r1.110 -r1.111
> > --- SerializationContextImpl.java 8 Jun 2004 19:45:48 -0000
> > 1.110
> > +++ SerializationContextImpl.java 24 Jun 2004 12:27:37 -0000
> > 1.111
> > @@ -403,6 +403,9 @@
> > if (prefix == null) {
> > if (defaultPrefix == null) {
> > prefix = "ns" + lastPrefixIndex++;
> > + while(nsStack.getNamespaceURI(prefix)!=null) {
> > + prefix = "ns" + lastPrefixIndex++;
> > + }
> > } else {
> > prefix = defaultPrefix;
> > }
> >
> > 1.19 +3 -3 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.18
> > retrieving revision 1.19
> > diff -u -r1.18 -r1.19
> > --- TestDOM.java 18 Nov 2003 22:36:37 -0000 1.18
> > +++ TestDOM.java 24 Jun 2004 12:27:38 -0000 1.19
> > @@ -123,14 +123,14 @@
> >
> > public void testEmptyNode() throws Exception
> > {
> > - SOAPBodyElement body = new
> > SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
> > + SOAPBodyElement body = new
> > SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
> > assertXMLEqual("<tmp/>",body.toString());
> > }
> >
> > public void testNodeWithAttribute() throws Exception
> > {
> > - org.w3c.dom.Element element =
> > XMLUtils.newDocument().createElement("tmp");
> > - element.setAttribute("attrib", "foo");
> > + org.w3c.dom.Element element =
> > XMLUtils.newDocument().createElementNS(null,"tmp");
> > + element.setAttributeNS(null,"attrib", "foo");
> > SOAPBodyElement body = new SOAPBodyElement(element);
> > assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
> > }
> >
> > 1.15 +75 -10 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.14
> > retrieving revision 1.15
> > diff -u -r1.14 -r1.15
> > --- TestMessageElement.java 10 Apr 2004 21:12:06 -0000 1.14
> > +++ TestMessageElement.java 24 Jun 2004 12:27:38 -0000 1.15
> > @@ -16,7 +16,6 @@
> >
> > package test.message;
> >
> > -import junit.framework.TestCase;
> > import org.apache.axis.Message;
> > import org.apache.axis.MessageContext;
> > import org.apache.axis.client.AxisClient;
> > @@ -26,30 +25,37 @@
> > import org.apache.axis.message.MessageElement;
> > import org.apache.axis.message.PrefixedQName;
> > import org.apache.axis.soap.SOAPConstants;
> > +import org.apache.axis.utils.XMLUtils;
> > +import org.w3c.dom.Document;
> > +import org.w3c.dom.Element;
> > +import org.w3c.dom.CDATASection;
> > import org.xml.sax.Attributes;
> > +import test.AxisTestBase;
> >
> > import javax.xml.namespace.QName;
> > +import javax.xml.soap.MessageFactory;
> > import javax.xml.soap.Name;
> > +import javax.xml.soap.SOAPBody;
> > +import javax.xml.soap.SOAPBodyElement;
> > import javax.xml.soap.SOAPElement;
> > -import javax.xml.soap.MessageFactory;
> > +import javax.xml.soap.SOAPEnvelope;
> > import javax.xml.soap.SOAPMessage;
> > import javax.xml.soap.SOAPPart;
> > -import javax.xml.soap.SOAPEnvelope;
> > -import javax.xml.soap.SOAPBody;
> > -import javax.xml.soap.SOAPBodyElement;
> > -import java.util.Iterator;
> > -import java.io.StringReader;
> > -import java.io.ByteArrayOutputStream;
> > -import java.io.ObjectOutputStream;
> > +import javax.xml.parsers.DocumentBuilderFactory;
> > +import javax.xml.parsers.DocumentBuilder;
> > import java.io.ByteArrayInputStream;
> > +import java.io.ByteArrayOutputStream;
> > import java.io.ObjectInputStream;
> > +import java.io.ObjectOutputStream;
> > +import java.io.StringReader;
> > +import java.util.Iterator;
> >
> > /**
> > * Test MessageElement class.
> > *
> > * @author Glyn Normington (glyn@apache.org)
> > */
> > -public class TestMessageElement extends TestCase {
> > +public class TestMessageElement extends AxisTestBase {
> >
> > public TestMessageElement(String name) {
> > super(name);
> > @@ -241,6 +247,65 @@
> >
> > assertEquals("m1 is not the same as m2", m1, m2);
> > assertEquals("m2 is not the same as m1", m2, m1);
> > + }
> > +
> > + public void testElementConstructor() throws Exception {
> > + String xmlIn = "<h:html
xmlns:xdc=\"http://www.xml.com/books\"\n"
> > +
> > + "
> > xmlns:h=\"http://www.w3.org/HTML/1998/html4\">\n" +
> > + " <h:head><h:title>Book
> > Review</h:title></h:head>\n" +
> > + " <h:body>\n" +
> > + " <xdc:bookreview>\n" +
> > + " <xdc:title>XML: A Primer</xdc:title>\n" +
> > + " <h:table>\n" +
> > + " <h:tr align=\"center\">\n" +
> > + " <h:td>Author</h:td><h:td>Price</h:td>\n"
+
> > + "
> > <h:td>Pages</h:td><h:td>Date</h:td></h:tr>\n" +
> > + " <!-- here is a comment -->\n" +
> > + " <h:tr align=\"left\">\n" +
> > + " <h:td><xdc:author>Simon St.
> > Laurent</xdc:author></h:td>\n" +
> > + "
<h:td><xdc:price>31.98</xdc:price></h:td>\n"
> > +
> > + "
<h:td><xdc:pages>352</xdc:pages></h:td>\n" +
> > + "
<h:td><xdc:date>1998/01</xdc:date></h:td>\n"
> > +
> > + " <h:td><![CDATA[text content]]></h:td>\n"
+
> > + " </h:tr>\n" +
> > + " </h:table>\n" +
> > + " </xdc:bookreview>\n" +
> > + " </h:body>\n" +
> > + "</h:html>";
> > +
> > + Document doc = XMLUtils.newDocument(new
> > ByteArrayInputStream(xmlIn.getBytes()));
> > + MessageElement me = new
MessageElement(doc.getDocumentElement());
> > + String xmlOut = me.getAsString();
> > + this.assertXMLEqual(xmlIn,xmlOut);
> > + }
> > +
> > + public void testElementConstructor2() throws Exception {
> > + String xmlIn = "<!-- This file can be used to deploy the
> > echoAttachments sample -->\n" +
> > + "<!-- using this command: java
> > org.apache.axis.client.AdminClient attachdeploy.wsdd -->\n" +
> > + "\n" +
> > + "<!-- This deploys the echo attachment service.
-->\n" +
> > + "<deployment
xmlns=\"http://xml.apache.org/axis/wsdd/\"
> > xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\"
> > xmlns:ns1=\"urn:EchoAttachmentsService\" >\n" +
> > + " <service name=\"urn:EchoAttachmentsService\"
> > provider=\"java:RPC\" >\n" +
> > + " <parameter name=\"className\"
> > value=\"samples.attachments.EchoAttachmentsService\"/>\n" +
> > + " <parameter name=\"allowedMethods\" value=\"echo
> > echoDir\"/>\n" +
> > + " <operation name=\"echo\"
returnQName=\"returnqname\"
> > returnType=\"ns1:DataHandler\" >\n" +
> > + " <parameter name=\"dh\"
> > type=\"ns1:DataHandler\"/>\n" +
> > + " </operation>\n" +
> > + "\n" +
> > + " <typeMapping
> > deserializer=\"org.apache.axis.encoding.ser.JAFDataHandlerDeserializ
> > erFactor
> > y\"\n" +
> > + "
> > languageSpecificType=\"java:javax.activation.DataHandler\"
> > qname=\"ns1:DataHandler\"\n" +
> > + "
> > serializer=\"org.apache.axis.encoding.ser.JAFDataHandlerSerializerFa
> > ctory\"\
> > n" +
> > + "
> > encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
> > + " />\n" +
> > + " </service>\n" +
> > + "\n" +
> > + "</deployment>";
> > +
> > + Document doc = XMLUtils.newDocument(new
> > ByteArrayInputStream(xmlIn.getBytes()));
> > + MessageElement me = new
MessageElement(doc.getDocumentElement());
> > + String xmlOut = me.getAsString();
> > + System.out.println(xmlOut);
> > + this.assertXMLEqual(xmlIn,xmlOut);
> > }
> >
> > public static void main(String[] args) throws Exception {
> >
> >
>
>
> --
> Davanum Srinivas - http://webservices.apache.org/~dims/
>
--
Davanum Srinivas - http://webservices.apache.org/~dims/
Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
Posted by Davanum Srinivas <da...@gmail.com>.
Jongjin,
I'd REALLY like to take a stab at fixing this before the next cut. i'd
be grateful if you can help me with a test case to recreate the
problem :)
-- dims
On Mon, 5 Jul 2004 14:50:30 -0400, Davanum Srinivas <da...@gmail.com> wrote:
> Jongjin,
>
> I was hunting for a test case...can u please add it to JIRA? That's
> exactly i had not marked the bug as closed :)
>
> thanks,
> dims
>
>
>
>
> On Mon, 5 Jul 2004 23:38:58 +0900, Jongjin Choi <gu...@hotmail.com> wrote:
> > Hi, dims.
> >
> > I looked into the following MessageElement changes and ran a test.
> > Does this change resolve the problem RPCParam <-> SOAP Element mapping
> > addressed in http://nagoya.apache.org/jira/browse/AXIS-1416?
> >
> > I made a simple test and found that the problem is remaining.
> >
> > Without resolving the AXIS-1416,
> > the standard JAX-RPC handler under Axis can not read or modify
> > the second and below level SOAP body elements.
> >
> > Thanks.
> >
> > -----Original Message-----
> > From: dims@apache.org [mailto:dims@apache.org]
> > Sent: Thursday, June 24, 2004 9:28 PM
> > To: ws-axis-cvs@apache.org
> > Subject: cvs commit: ws-axis/java/test/message TestMessageElement.java
> >
> > dims 2004/06/24 05:27:38
> >
> > Modified: java/test/wsdl/faults FaultServiceSoapBindingImpl.java
> > java/src/org/apache/axis/message MessageElement.java
> > java/test/wsdl/sequence SequenceService.java
> > java/src/org/apache/axis/encoding
> > SerializationContextImpl.java
> > java/test/encoding TestDOM.java
> > java/test/message TestMessageElement.java
> > Log:
> > Fix for AXIS-1350 - new MessageElement(new Element()) does not behave like
> > an Element
> > Fix for AXIS-616 - MessageElement is not for mortals
> > Fix for AXIS-1054 - No way to non-default namespace prefixes when creating
> > MessageElements from DOM elements
> > Fix for AXIS-1403 - calling MessageElement#getChildren with a Text-Only
> > content returns an empty list
> >
> > Notes:
> > - traverse all the nodes recursively and create new MessageElement's for
> > each node.
> >
> > Revision Changes Path
> > 1.5 +1 -1
> > ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java
> >
> > Index: FaultServiceSoapBindingImpl.java
> > ===================================================================
> > RCS file:
> > /home/cvs/ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java,v
> > retrieving revision 1.4
> > retrieving revision 1.5
> > diff -u -r1.4 -r1.5
> > --- FaultServiceSoapBindingImpl.java 11 Dec 2002 22:40:20 -0000 1.4
> > +++ FaultServiceSoapBindingImpl.java 24 Jun 2004 12:27:37 -0000 1.5
> > @@ -23,7 +23,7 @@
> > public int throwExtensionFault(java.lang.String description) throws
> > java.rmi.RemoteException, test.wsdl.faults.ExtensionFault {
> > ExtensionType extension = new ExtensionType();
> > try {
> > - extension.set_any(new MessageElement[] {new
> > MessageElement(XMLUtils.newDocument().createElement(description))});
> > + extension.set_any(new MessageElement[] {new
> > MessageElement(XMLUtils.newDocument().createElementNS(null,description))});
> > } catch (Exception e) {
> > throw new java.rmi.RemoteException(e.getMessage());
> > }
> >
> > 1.173 +85 -36
> > 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.172
> > retrieving revision 1.173
> > diff -u -r1.172 -r1.173
> > --- MessageElement.java 23 Jun 2004 04:14:31 -0000 1.172
> > +++ MessageElement.java 24 Jun 2004 12:27:37 -0000 1.173
> > @@ -16,22 +16,6 @@
> >
> > package org.apache.axis.message;
> >
> > -import java.io.Reader;
> > -import java.io.Serializable;
> > -import java.io.StringReader;
> > -import java.io.StringWriter;
> > -import java.util.ArrayList;
> > -import java.util.Iterator;
> > -import java.util.Vector;
> > -import java.util.Enumeration;
> > -import java.util.List;
> > -
> > -import javax.xml.namespace.QName;
> > -import javax.xml.rpc.encoding.TypeMapping;
> > -import javax.xml.soap.Name;
> > -import javax.xml.soap.SOAPElement;
> > -import javax.xml.soap.SOAPException;
> > -
> > import org.apache.axis.AxisFault;
> > import org.apache.axis.Constants;
> > import org.apache.axis.MessageContext;
> > @@ -48,6 +32,9 @@
> > import org.apache.axis.utils.XMLUtils;
> > import org.apache.commons.logging.Log;
> > import org.w3c.dom.Attr;
> > +import org.w3c.dom.CDATASection;
> > +import org.w3c.dom.CharacterData;
> > +import org.w3c.dom.Comment;
> > import org.w3c.dom.DOMException;
> > import org.w3c.dom.Document;
> > import org.w3c.dom.Element;
> > @@ -61,6 +48,21 @@
> > import org.xml.sax.SAXException;
> > import org.xml.sax.helpers.AttributesImpl;
> >
> > +import javax.xml.namespace.QName;
> > +import javax.xml.rpc.encoding.TypeMapping;
> > +import javax.xml.soap.Name;
> > +import javax.xml.soap.SOAPElement;
> > +import javax.xml.soap.SOAPException;
> > +import java.io.Reader;
> > +import java.io.Serializable;
> > +import java.io.StringReader;
> > +import java.io.StringWriter;
> > +import java.util.ArrayList;
> > +import java.util.Enumeration;
> > +import java.util.Iterator;
> > +import java.util.List;
> > +import java.util.Vector;
> > +
> > /*
> > * MessageElement is the base type of nodes of the SOAP message parse
> > tree.
> > *
> > @@ -106,8 +108,7 @@
> > protected int endEventIndex = -1;
> >
> > // ...or as DOM
> > - protected Element elementRep = null;
> > - protected Text textRep = null;
> > + protected CharacterData textRep = null;
> >
> > protected MessageElement parent = null;
> >
> > @@ -163,12 +164,12 @@
> >
> > public MessageElement(Element elem)
> > {
> > - elementRep = elem;
> > namespaceURI = elem.getNamespaceURI();
> > name = elem.getLocalName();
> > + copyNode(elem);
> > }
> >
> > - public MessageElement(Text text)
> > + public MessageElement(CharacterData text)
> > {
> > textRep = text;
> > namespaceURI = text.getNamespaceURI();
> > @@ -399,8 +400,7 @@
> > * protected int startEventIndex = 0; N?
> > * protected int startContentsIndex = 0; N?
> > * protected int endEventIndex = -1; N?
> > - * protected Element elementRep = null; N?
> > - * protected Text textRep = null; Y?
> > + * protected CharacterData textRep = null; Y?
> > * protected MessageElement parent = null; N
> > * public ArrayList namespaces = null; Y
> > * protected String encodingStyle = null; N?
> > @@ -608,7 +608,13 @@
> >
> > public short getNodeType() {
> > if(this.textRep != null) {
> > + if(textRep instanceof Comment) {
> > + return COMMENT_NODE;
> > + } else if(textRep instanceof CDATASection) {
> > + return CDATA_SECTION_NODE;
> > + } else {
> > return TEXT_NODE;
> > + }
> > }else if(false){
> > return DOCUMENT_FRAGMENT_NODE;
> > }else if(false){
> > @@ -908,11 +914,6 @@
> > log.error(Messages.getMessage("childPresent"), exc);
> > throw exc;
> > }
> > - if (elementRep != null) {
> > - SOAPException exc = new
> > SOAPException(Messages.getMessage("xmlPresent"));
> > - log.error(Messages.getMessage("xmlPresent"), exc);
> > - throw exc;
> > - }
> > if (textRep != null) {
> > SOAPException exc = new
> > SOAPException(Messages.getMessage("xmlPresent"));
> > log.error(Messages.getMessage("xmlPresent"), exc);
> > @@ -1165,18 +1166,20 @@
> > */
> > protected void outputImpl(SerializationContext context) throws
> > Exception
> > {
> > - if (elementRep != null) {
> > - boolean oldPretty = context.getPretty();
> > - context.setPretty(false);
> > - context.writeDOMElement(elementRep);
> > - context.setPretty(oldPretty);
> > - return;
> > - }
> > -
> > if (textRep != null) {
> > boolean oldPretty = context.getPretty();
> > context.setPretty(false);
> > - context.writeSafeString(textRep.getData());
> > + if (textRep instanceof CDATASection) {
> > + context.writeString("<![CDATA[");
> > + context.writeString(((Text)textRep).getData());
> > + context.writeString("]]>");
> > + } else if (textRep instanceof Comment) {
> > + context.writeString("<!--");
> > + context.writeString(((CharacterData)textRep).getData());
> > + context.writeString("-->");
> > + } else if (textRep instanceof Text) {
> > + context.writeSafeString(((Text)textRep).getData());
> > + }
> > context.setPretty(oldPretty);
> > return;
> > }
> > @@ -1727,5 +1730,51 @@
> > if (obj == null || !(obj instanceof MessageElement))
> > return false;
> > return toString().equals(obj.toString());
> > + }
> > +
> > + private void copyNode(org.w3c.dom.Node element) {
> > + copyNode(this, element);
> > + }
> > +
> > + private void copyNode(MessageElement parent, org.w3c.dom.Node
> > element)
> > + {
> > + parent.setPrefix(element.getPrefix());
> > + if(element.getLocalName() != null) {
> > + parent.setQName(new QName(element.getNamespaceURI(),
> > element.getLocalName()));
> > + }
> > +
> > + org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
> > + for(int i = 0; i < attrs.getLength(); i++){
> > + org.w3c.dom.Node att = attrs.item(i);
> > + if (att.getNamespaceURI() != null &&
> > + att.getPrefix() != null &&
> > + att.getNamespaceURI().equals(Constants.NS_URI_XMLNS) &&
> > + att.getPrefix().equals("xmlns")) {
> > + Mapping map = new Mapping(att.getNodeValue(),
> > att.getLocalName());
> > + addMapping(map);
> > + }
> > + parent.addAttribute(att.getPrefix(),
> > + att.getNamespaceURI(),
> > + att.getLocalName(),
> > + att.getNodeValue());
> > + }
> > +
> > + org.w3c.dom.NodeList children = element.getChildNodes();
> > + for(int i = 0; i < children.getLength(); i++){
> > + org.w3c.dom.Node child = children.item(i);
> > + if(child.getNodeType()==TEXT_NODE ||
> > + child.getNodeType()==CDATA_SECTION_NODE ||
> > + child.getNodeType()==COMMENT_NODE ) {
> > + MessageElement childElement = new
> > MessageElement((CharacterData)child);
> > + parent.appendChild(childElement);
> > + } else {
> > + PrefixedQName qname = new
> > PrefixedQName(child.getNamespaceURI(),
> > + child.getLocalName(),
> > + child.getPrefix());
> > + MessageElement childElement = new MessageElement(qname);
> > + parent.appendChild(childElement);
> > + copyNode(childElement, child);
> > + }
> > + }
> > }
> > }
> >
> > 1.8 +1 -1 ws-axis/java/test/wsdl/sequence/SequenceService.java
> >
> > Index: SequenceService.java
> > ===================================================================
> > RCS file: /home/cvs/ws-axis/java/test/wsdl/sequence/SequenceService.java,v
> > retrieving revision 1.7
> > retrieving revision 1.8
> > diff -u -r1.7 -r1.8
> > --- SequenceService.java 25 Feb 2004 14:03:05 -0000 1.7
> > +++ SequenceService.java 24 Jun 2004 12:27:37 -0000 1.8
> > @@ -78,7 +78,7 @@
> > success = true;
> > }
> >
> > - resultElement = retDoc.createElement("return");
> > + resultElement = retDoc.createElementNS(null,"return");
> >
> > String resultStr = "false";
> > if (success) {
> >
> > 1.111 +3 -0
> > 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.110
> > retrieving revision 1.111
> > diff -u -r1.110 -r1.111
> > --- SerializationContextImpl.java 8 Jun 2004 19:45:48 -0000
> > 1.110
> > +++ SerializationContextImpl.java 24 Jun 2004 12:27:37 -0000
> > 1.111
> > @@ -403,6 +403,9 @@
> > if (prefix == null) {
> > if (defaultPrefix == null) {
> > prefix = "ns" + lastPrefixIndex++;
> > + while(nsStack.getNamespaceURI(prefix)!=null) {
> > + prefix = "ns" + lastPrefixIndex++;
> > + }
> > } else {
> > prefix = defaultPrefix;
> > }
> >
> > 1.19 +3 -3 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.18
> > retrieving revision 1.19
> > diff -u -r1.18 -r1.19
> > --- TestDOM.java 18 Nov 2003 22:36:37 -0000 1.18
> > +++ TestDOM.java 24 Jun 2004 12:27:38 -0000 1.19
> > @@ -123,14 +123,14 @@
> >
> > public void testEmptyNode() throws Exception
> > {
> > - SOAPBodyElement body = new
> > SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
> > + SOAPBodyElement body = new
> > SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
> > assertXMLEqual("<tmp/>",body.toString());
> > }
> >
> > public void testNodeWithAttribute() throws Exception
> > {
> > - org.w3c.dom.Element element =
> > XMLUtils.newDocument().createElement("tmp");
> > - element.setAttribute("attrib", "foo");
> > + org.w3c.dom.Element element =
> > XMLUtils.newDocument().createElementNS(null,"tmp");
> > + element.setAttributeNS(null,"attrib", "foo");
> > SOAPBodyElement body = new SOAPBodyElement(element);
> > assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
> > }
> >
> > 1.15 +75 -10 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.14
> > retrieving revision 1.15
> > diff -u -r1.14 -r1.15
> > --- TestMessageElement.java 10 Apr 2004 21:12:06 -0000 1.14
> > +++ TestMessageElement.java 24 Jun 2004 12:27:38 -0000 1.15
> > @@ -16,7 +16,6 @@
> >
> > package test.message;
> >
> > -import junit.framework.TestCase;
> > import org.apache.axis.Message;
> > import org.apache.axis.MessageContext;
> > import org.apache.axis.client.AxisClient;
> > @@ -26,30 +25,37 @@
> > import org.apache.axis.message.MessageElement;
> > import org.apache.axis.message.PrefixedQName;
> > import org.apache.axis.soap.SOAPConstants;
> > +import org.apache.axis.utils.XMLUtils;
> > +import org.w3c.dom.Document;
> > +import org.w3c.dom.Element;
> > +import org.w3c.dom.CDATASection;
> > import org.xml.sax.Attributes;
> > +import test.AxisTestBase;
> >
> > import javax.xml.namespace.QName;
> > +import javax.xml.soap.MessageFactory;
> > import javax.xml.soap.Name;
> > +import javax.xml.soap.SOAPBody;
> > +import javax.xml.soap.SOAPBodyElement;
> > import javax.xml.soap.SOAPElement;
> > -import javax.xml.soap.MessageFactory;
> > +import javax.xml.soap.SOAPEnvelope;
> > import javax.xml.soap.SOAPMessage;
> > import javax.xml.soap.SOAPPart;
> > -import javax.xml.soap.SOAPEnvelope;
> > -import javax.xml.soap.SOAPBody;
> > -import javax.xml.soap.SOAPBodyElement;
> > -import java.util.Iterator;
> > -import java.io.StringReader;
> > -import java.io.ByteArrayOutputStream;
> > -import java.io.ObjectOutputStream;
> > +import javax.xml.parsers.DocumentBuilderFactory;
> > +import javax.xml.parsers.DocumentBuilder;
> > import java.io.ByteArrayInputStream;
> > +import java.io.ByteArrayOutputStream;
> > import java.io.ObjectInputStream;
> > +import java.io.ObjectOutputStream;
> > +import java.io.StringReader;
> > +import java.util.Iterator;
> >
> > /**
> > * Test MessageElement class.
> > *
> > * @author Glyn Normington (glyn@apache.org)
> > */
> > -public class TestMessageElement extends TestCase {
> > +public class TestMessageElement extends AxisTestBase {
> >
> > public TestMessageElement(String name) {
> > super(name);
> > @@ -241,6 +247,65 @@
> >
> > assertEquals("m1 is not the same as m2", m1, m2);
> > assertEquals("m2 is not the same as m1", m2, m1);
> > + }
> > +
> > + public void testElementConstructor() throws Exception {
> > + String xmlIn = "<h:html xmlns:xdc=\"http://www.xml.com/books\"\n"
> > +
> > + "
> > xmlns:h=\"http://www.w3.org/HTML/1998/html4\">\n" +
> > + " <h:head><h:title>Book
> > Review</h:title></h:head>\n" +
> > + " <h:body>\n" +
> > + " <xdc:bookreview>\n" +
> > + " <xdc:title>XML: A Primer</xdc:title>\n" +
> > + " <h:table>\n" +
> > + " <h:tr align=\"center\">\n" +
> > + " <h:td>Author</h:td><h:td>Price</h:td>\n" +
> > + "
> > <h:td>Pages</h:td><h:td>Date</h:td></h:tr>\n" +
> > + " <!-- here is a comment -->\n" +
> > + " <h:tr align=\"left\">\n" +
> > + " <h:td><xdc:author>Simon St.
> > Laurent</xdc:author></h:td>\n" +
> > + " <h:td><xdc:price>31.98</xdc:price></h:td>\n"
> > +
> > + " <h:td><xdc:pages>352</xdc:pages></h:td>\n" +
> > + " <h:td><xdc:date>1998/01</xdc:date></h:td>\n"
> > +
> > + " <h:td><![CDATA[text content]]></h:td>\n" +
> > + " </h:tr>\n" +
> > + " </h:table>\n" +
> > + " </xdc:bookreview>\n" +
> > + " </h:body>\n" +
> > + "</h:html>";
> > +
> > + Document doc = XMLUtils.newDocument(new
> > ByteArrayInputStream(xmlIn.getBytes()));
> > + MessageElement me = new MessageElement(doc.getDocumentElement());
> > + String xmlOut = me.getAsString();
> > + this.assertXMLEqual(xmlIn,xmlOut);
> > + }
> > +
> > + public void testElementConstructor2() throws Exception {
> > + String xmlIn = "<!-- This file can be used to deploy the
> > echoAttachments sample -->\n" +
> > + "<!-- using this command: java
> > org.apache.axis.client.AdminClient attachdeploy.wsdd -->\n" +
> > + "\n" +
> > + "<!-- This deploys the echo attachment service. -->\n" +
> > + "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\"
> > xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\"
> > xmlns:ns1=\"urn:EchoAttachmentsService\" >\n" +
> > + " <service name=\"urn:EchoAttachmentsService\"
> > provider=\"java:RPC\" >\n" +
> > + " <parameter name=\"className\"
> > value=\"samples.attachments.EchoAttachmentsService\"/>\n" +
> > + " <parameter name=\"allowedMethods\" value=\"echo
> > echoDir\"/>\n" +
> > + " <operation name=\"echo\" returnQName=\"returnqname\"
> > returnType=\"ns1:DataHandler\" >\n" +
> > + " <parameter name=\"dh\"
> > type=\"ns1:DataHandler\"/>\n" +
> > + " </operation>\n" +
> > + "\n" +
> > + " <typeMapping
> > deserializer=\"org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactor
> > y\"\n" +
> > + "
> > languageSpecificType=\"java:javax.activation.DataHandler\"
> > qname=\"ns1:DataHandler\"\n" +
> > + "
> > serializer=\"org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory\"\
> > n" +
> > + "
> > encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
> > + " />\n" +
> > + " </service>\n" +
> > + "\n" +
> > + "</deployment>";
> > +
> > + Document doc = XMLUtils.newDocument(new
> > ByteArrayInputStream(xmlIn.getBytes()));
> > + MessageElement me = new MessageElement(doc.getDocumentElement());
> > + String xmlOut = me.getAsString();
> > + System.out.println(xmlOut);
> > + this.assertXMLEqual(xmlIn,xmlOut);
> > }
> >
> > public static void main(String[] args) throws Exception {
> >
> >
>
>
> --
> Davanum Srinivas - http://webservices.apache.org/~dims/
>
--
Davanum Srinivas - http://webservices.apache.org/~dims/
Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
Posted by Davanum Srinivas <da...@gmail.com>.
Jongjin,
I was hunting for a test case...can u please add it to JIRA? That's
exactly i had not marked the bug as closed :)
thanks,
dims
On Mon, 5 Jul 2004 23:38:58 +0900, Jongjin Choi <gu...@hotmail.com> wrote:
> Hi, dims.
>
> I looked into the following MessageElement changes and ran a test.
> Does this change resolve the problem RPCParam <-> SOAP Element mapping
> addressed in http://nagoya.apache.org/jira/browse/AXIS-1416?
>
> I made a simple test and found that the problem is remaining.
>
> Without resolving the AXIS-1416,
> the standard JAX-RPC handler under Axis can not read or modify
> the second and below level SOAP body elements.
>
> Thanks.
>
> -----Original Message-----
> From: dims@apache.org [mailto:dims@apache.org]
> Sent: Thursday, June 24, 2004 9:28 PM
> To: ws-axis-cvs@apache.org
> Subject: cvs commit: ws-axis/java/test/message TestMessageElement.java
>
> dims 2004/06/24 05:27:38
>
> Modified: java/test/wsdl/faults FaultServiceSoapBindingImpl.java
> java/src/org/apache/axis/message MessageElement.java
> java/test/wsdl/sequence SequenceService.java
> java/src/org/apache/axis/encoding
> SerializationContextImpl.java
> java/test/encoding TestDOM.java
> java/test/message TestMessageElement.java
> Log:
> Fix for AXIS-1350 - new MessageElement(new Element()) does not behave like
> an Element
> Fix for AXIS-616 - MessageElement is not for mortals
> Fix for AXIS-1054 - No way to non-default namespace prefixes when creating
> MessageElements from DOM elements
> Fix for AXIS-1403 - calling MessageElement#getChildren with a Text-Only
> content returns an empty list
>
> Notes:
> - traverse all the nodes recursively and create new MessageElement's for
> each node.
>
> Revision Changes Path
> 1.5 +1 -1
> ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java
>
> Index: FaultServiceSoapBindingImpl.java
> ===================================================================
> RCS file:
> /home/cvs/ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java,v
> retrieving revision 1.4
> retrieving revision 1.5
> diff -u -r1.4 -r1.5
> --- FaultServiceSoapBindingImpl.java 11 Dec 2002 22:40:20 -0000 1.4
> +++ FaultServiceSoapBindingImpl.java 24 Jun 2004 12:27:37 -0000 1.5
> @@ -23,7 +23,7 @@
> public int throwExtensionFault(java.lang.String description) throws
> java.rmi.RemoteException, test.wsdl.faults.ExtensionFault {
> ExtensionType extension = new ExtensionType();
> try {
> - extension.set_any(new MessageElement[] {new
> MessageElement(XMLUtils.newDocument().createElement(description))});
> + extension.set_any(new MessageElement[] {new
> MessageElement(XMLUtils.newDocument().createElementNS(null,description))});
> } catch (Exception e) {
> throw new java.rmi.RemoteException(e.getMessage());
> }
>
> 1.173 +85 -36
> 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.172
> retrieving revision 1.173
> diff -u -r1.172 -r1.173
> --- MessageElement.java 23 Jun 2004 04:14:31 -0000 1.172
> +++ MessageElement.java 24 Jun 2004 12:27:37 -0000 1.173
> @@ -16,22 +16,6 @@
>
> package org.apache.axis.message;
>
> -import java.io.Reader;
> -import java.io.Serializable;
> -import java.io.StringReader;
> -import java.io.StringWriter;
> -import java.util.ArrayList;
> -import java.util.Iterator;
> -import java.util.Vector;
> -import java.util.Enumeration;
> -import java.util.List;
> -
> -import javax.xml.namespace.QName;
> -import javax.xml.rpc.encoding.TypeMapping;
> -import javax.xml.soap.Name;
> -import javax.xml.soap.SOAPElement;
> -import javax.xml.soap.SOAPException;
> -
> import org.apache.axis.AxisFault;
> import org.apache.axis.Constants;
> import org.apache.axis.MessageContext;
> @@ -48,6 +32,9 @@
> import org.apache.axis.utils.XMLUtils;
> import org.apache.commons.logging.Log;
> import org.w3c.dom.Attr;
> +import org.w3c.dom.CDATASection;
> +import org.w3c.dom.CharacterData;
> +import org.w3c.dom.Comment;
> import org.w3c.dom.DOMException;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> @@ -61,6 +48,21 @@
> import org.xml.sax.SAXException;
> import org.xml.sax.helpers.AttributesImpl;
>
> +import javax.xml.namespace.QName;
> +import javax.xml.rpc.encoding.TypeMapping;
> +import javax.xml.soap.Name;
> +import javax.xml.soap.SOAPElement;
> +import javax.xml.soap.SOAPException;
> +import java.io.Reader;
> +import java.io.Serializable;
> +import java.io.StringReader;
> +import java.io.StringWriter;
> +import java.util.ArrayList;
> +import java.util.Enumeration;
> +import java.util.Iterator;
> +import java.util.List;
> +import java.util.Vector;
> +
> /*
> * MessageElement is the base type of nodes of the SOAP message parse
> tree.
> *
> @@ -106,8 +108,7 @@
> protected int endEventIndex = -1;
>
> // ...or as DOM
> - protected Element elementRep = null;
> - protected Text textRep = null;
> + protected CharacterData textRep = null;
>
> protected MessageElement parent = null;
>
> @@ -163,12 +164,12 @@
>
> public MessageElement(Element elem)
> {
> - elementRep = elem;
> namespaceURI = elem.getNamespaceURI();
> name = elem.getLocalName();
> + copyNode(elem);
> }
>
> - public MessageElement(Text text)
> + public MessageElement(CharacterData text)
> {
> textRep = text;
> namespaceURI = text.getNamespaceURI();
> @@ -399,8 +400,7 @@
> * protected int startEventIndex = 0; N?
> * protected int startContentsIndex = 0; N?
> * protected int endEventIndex = -1; N?
> - * protected Element elementRep = null; N?
> - * protected Text textRep = null; Y?
> + * protected CharacterData textRep = null; Y?
> * protected MessageElement parent = null; N
> * public ArrayList namespaces = null; Y
> * protected String encodingStyle = null; N?
> @@ -608,7 +608,13 @@
>
> public short getNodeType() {
> if(this.textRep != null) {
> + if(textRep instanceof Comment) {
> + return COMMENT_NODE;
> + } else if(textRep instanceof CDATASection) {
> + return CDATA_SECTION_NODE;
> + } else {
> return TEXT_NODE;
> + }
> }else if(false){
> return DOCUMENT_FRAGMENT_NODE;
> }else if(false){
> @@ -908,11 +914,6 @@
> log.error(Messages.getMessage("childPresent"), exc);
> throw exc;
> }
> - if (elementRep != null) {
> - SOAPException exc = new
> SOAPException(Messages.getMessage("xmlPresent"));
> - log.error(Messages.getMessage("xmlPresent"), exc);
> - throw exc;
> - }
> if (textRep != null) {
> SOAPException exc = new
> SOAPException(Messages.getMessage("xmlPresent"));
> log.error(Messages.getMessage("xmlPresent"), exc);
> @@ -1165,18 +1166,20 @@
> */
> protected void outputImpl(SerializationContext context) throws
> Exception
> {
> - if (elementRep != null) {
> - boolean oldPretty = context.getPretty();
> - context.setPretty(false);
> - context.writeDOMElement(elementRep);
> - context.setPretty(oldPretty);
> - return;
> - }
> -
> if (textRep != null) {
> boolean oldPretty = context.getPretty();
> context.setPretty(false);
> - context.writeSafeString(textRep.getData());
> + if (textRep instanceof CDATASection) {
> + context.writeString("<![CDATA[");
> + context.writeString(((Text)textRep).getData());
> + context.writeString("]]>");
> + } else if (textRep instanceof Comment) {
> + context.writeString("<!--");
> + context.writeString(((CharacterData)textRep).getData());
> + context.writeString("-->");
> + } else if (textRep instanceof Text) {
> + context.writeSafeString(((Text)textRep).getData());
> + }
> context.setPretty(oldPretty);
> return;
> }
> @@ -1727,5 +1730,51 @@
> if (obj == null || !(obj instanceof MessageElement))
> return false;
> return toString().equals(obj.toString());
> + }
> +
> + private void copyNode(org.w3c.dom.Node element) {
> + copyNode(this, element);
> + }
> +
> + private void copyNode(MessageElement parent, org.w3c.dom.Node
> element)
> + {
> + parent.setPrefix(element.getPrefix());
> + if(element.getLocalName() != null) {
> + parent.setQName(new QName(element.getNamespaceURI(),
> element.getLocalName()));
> + }
> +
> + org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
> + for(int i = 0; i < attrs.getLength(); i++){
> + org.w3c.dom.Node att = attrs.item(i);
> + if (att.getNamespaceURI() != null &&
> + att.getPrefix() != null &&
> + att.getNamespaceURI().equals(Constants.NS_URI_XMLNS) &&
> + att.getPrefix().equals("xmlns")) {
> + Mapping map = new Mapping(att.getNodeValue(),
> att.getLocalName());
> + addMapping(map);
> + }
> + parent.addAttribute(att.getPrefix(),
> + att.getNamespaceURI(),
> + att.getLocalName(),
> + att.getNodeValue());
> + }
> +
> + org.w3c.dom.NodeList children = element.getChildNodes();
> + for(int i = 0; i < children.getLength(); i++){
> + org.w3c.dom.Node child = children.item(i);
> + if(child.getNodeType()==TEXT_NODE ||
> + child.getNodeType()==CDATA_SECTION_NODE ||
> + child.getNodeType()==COMMENT_NODE ) {
> + MessageElement childElement = new
> MessageElement((CharacterData)child);
> + parent.appendChild(childElement);
> + } else {
> + PrefixedQName qname = new
> PrefixedQName(child.getNamespaceURI(),
> + child.getLocalName(),
> + child.getPrefix());
> + MessageElement childElement = new MessageElement(qname);
> + parent.appendChild(childElement);
> + copyNode(childElement, child);
> + }
> + }
> }
> }
>
> 1.8 +1 -1 ws-axis/java/test/wsdl/sequence/SequenceService.java
>
> Index: SequenceService.java
> ===================================================================
> RCS file: /home/cvs/ws-axis/java/test/wsdl/sequence/SequenceService.java,v
> retrieving revision 1.7
> retrieving revision 1.8
> diff -u -r1.7 -r1.8
> --- SequenceService.java 25 Feb 2004 14:03:05 -0000 1.7
> +++ SequenceService.java 24 Jun 2004 12:27:37 -0000 1.8
> @@ -78,7 +78,7 @@
> success = true;
> }
>
> - resultElement = retDoc.createElement("return");
> + resultElement = retDoc.createElementNS(null,"return");
>
> String resultStr = "false";
> if (success) {
>
> 1.111 +3 -0
> 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.110
> retrieving revision 1.111
> diff -u -r1.110 -r1.111
> --- SerializationContextImpl.java 8 Jun 2004 19:45:48 -0000
> 1.110
> +++ SerializationContextImpl.java 24 Jun 2004 12:27:37 -0000
> 1.111
> @@ -403,6 +403,9 @@
> if (prefix == null) {
> if (defaultPrefix == null) {
> prefix = "ns" + lastPrefixIndex++;
> + while(nsStack.getNamespaceURI(prefix)!=null) {
> + prefix = "ns" + lastPrefixIndex++;
> + }
> } else {
> prefix = defaultPrefix;
> }
>
> 1.19 +3 -3 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.18
> retrieving revision 1.19
> diff -u -r1.18 -r1.19
> --- TestDOM.java 18 Nov 2003 22:36:37 -0000 1.18
> +++ TestDOM.java 24 Jun 2004 12:27:38 -0000 1.19
> @@ -123,14 +123,14 @@
>
> public void testEmptyNode() throws Exception
> {
> - SOAPBodyElement body = new
> SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
> + SOAPBodyElement body = new
> SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
> assertXMLEqual("<tmp/>",body.toString());
> }
>
> public void testNodeWithAttribute() throws Exception
> {
> - org.w3c.dom.Element element =
> XMLUtils.newDocument().createElement("tmp");
> - element.setAttribute("attrib", "foo");
> + org.w3c.dom.Element element =
> XMLUtils.newDocument().createElementNS(null,"tmp");
> + element.setAttributeNS(null,"attrib", "foo");
> SOAPBodyElement body = new SOAPBodyElement(element);
> assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
> }
>
> 1.15 +75 -10 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.14
> retrieving revision 1.15
> diff -u -r1.14 -r1.15
> --- TestMessageElement.java 10 Apr 2004 21:12:06 -0000 1.14
> +++ TestMessageElement.java 24 Jun 2004 12:27:38 -0000 1.15
> @@ -16,7 +16,6 @@
>
> package test.message;
>
> -import junit.framework.TestCase;
> import org.apache.axis.Message;
> import org.apache.axis.MessageContext;
> import org.apache.axis.client.AxisClient;
> @@ -26,30 +25,37 @@
> import org.apache.axis.message.MessageElement;
> import org.apache.axis.message.PrefixedQName;
> import org.apache.axis.soap.SOAPConstants;
> +import org.apache.axis.utils.XMLUtils;
> +import org.w3c.dom.Document;
> +import org.w3c.dom.Element;
> +import org.w3c.dom.CDATASection;
> import org.xml.sax.Attributes;
> +import test.AxisTestBase;
>
> import javax.xml.namespace.QName;
> +import javax.xml.soap.MessageFactory;
> import javax.xml.soap.Name;
> +import javax.xml.soap.SOAPBody;
> +import javax.xml.soap.SOAPBodyElement;
> import javax.xml.soap.SOAPElement;
> -import javax.xml.soap.MessageFactory;
> +import javax.xml.soap.SOAPEnvelope;
> import javax.xml.soap.SOAPMessage;
> import javax.xml.soap.SOAPPart;
> -import javax.xml.soap.SOAPEnvelope;
> -import javax.xml.soap.SOAPBody;
> -import javax.xml.soap.SOAPBodyElement;
> -import java.util.Iterator;
> -import java.io.StringReader;
> -import java.io.ByteArrayOutputStream;
> -import java.io.ObjectOutputStream;
> +import javax.xml.parsers.DocumentBuilderFactory;
> +import javax.xml.parsers.DocumentBuilder;
> import java.io.ByteArrayInputStream;
> +import java.io.ByteArrayOutputStream;
> import java.io.ObjectInputStream;
> +import java.io.ObjectOutputStream;
> +import java.io.StringReader;
> +import java.util.Iterator;
>
> /**
> * Test MessageElement class.
> *
> * @author Glyn Normington (glyn@apache.org)
> */
> -public class TestMessageElement extends TestCase {
> +public class TestMessageElement extends AxisTestBase {
>
> public TestMessageElement(String name) {
> super(name);
> @@ -241,6 +247,65 @@
>
> assertEquals("m1 is not the same as m2", m1, m2);
> assertEquals("m2 is not the same as m1", m2, m1);
> + }
> +
> + public void testElementConstructor() throws Exception {
> + String xmlIn = "<h:html xmlns:xdc=\"http://www.xml.com/books\"\n"
> +
> + "
> xmlns:h=\"http://www.w3.org/HTML/1998/html4\">\n" +
> + " <h:head><h:title>Book
> Review</h:title></h:head>\n" +
> + " <h:body>\n" +
> + " <xdc:bookreview>\n" +
> + " <xdc:title>XML: A Primer</xdc:title>\n" +
> + " <h:table>\n" +
> + " <h:tr align=\"center\">\n" +
> + " <h:td>Author</h:td><h:td>Price</h:td>\n" +
> + "
> <h:td>Pages</h:td><h:td>Date</h:td></h:tr>\n" +
> + " <!-- here is a comment -->\n" +
> + " <h:tr align=\"left\">\n" +
> + " <h:td><xdc:author>Simon St.
> Laurent</xdc:author></h:td>\n" +
> + " <h:td><xdc:price>31.98</xdc:price></h:td>\n"
> +
> + " <h:td><xdc:pages>352</xdc:pages></h:td>\n" +
> + " <h:td><xdc:date>1998/01</xdc:date></h:td>\n"
> +
> + " <h:td><![CDATA[text content]]></h:td>\n" +
> + " </h:tr>\n" +
> + " </h:table>\n" +
> + " </xdc:bookreview>\n" +
> + " </h:body>\n" +
> + "</h:html>";
> +
> + Document doc = XMLUtils.newDocument(new
> ByteArrayInputStream(xmlIn.getBytes()));
> + MessageElement me = new MessageElement(doc.getDocumentElement());
> + String xmlOut = me.getAsString();
> + this.assertXMLEqual(xmlIn,xmlOut);
> + }
> +
> + public void testElementConstructor2() throws Exception {
> + String xmlIn = "<!-- This file can be used to deploy the
> echoAttachments sample -->\n" +
> + "<!-- using this command: java
> org.apache.axis.client.AdminClient attachdeploy.wsdd -->\n" +
> + "\n" +
> + "<!-- This deploys the echo attachment service. -->\n" +
> + "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\"
> xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\"
> xmlns:ns1=\"urn:EchoAttachmentsService\" >\n" +
> + " <service name=\"urn:EchoAttachmentsService\"
> provider=\"java:RPC\" >\n" +
> + " <parameter name=\"className\"
> value=\"samples.attachments.EchoAttachmentsService\"/>\n" +
> + " <parameter name=\"allowedMethods\" value=\"echo
> echoDir\"/>\n" +
> + " <operation name=\"echo\" returnQName=\"returnqname\"
> returnType=\"ns1:DataHandler\" >\n" +
> + " <parameter name=\"dh\"
> type=\"ns1:DataHandler\"/>\n" +
> + " </operation>\n" +
> + "\n" +
> + " <typeMapping
> deserializer=\"org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactor
> y\"\n" +
> + "
> languageSpecificType=\"java:javax.activation.DataHandler\"
> qname=\"ns1:DataHandler\"\n" +
> + "
> serializer=\"org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory\"\
> n" +
> + "
> encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
> + " />\n" +
> + " </service>\n" +
> + "\n" +
> + "</deployment>";
> +
> + Document doc = XMLUtils.newDocument(new
> ByteArrayInputStream(xmlIn.getBytes()));
> + MessageElement me = new MessageElement(doc.getDocumentElement());
> + String xmlOut = me.getAsString();
> + System.out.println(xmlOut);
> + this.assertXMLEqual(xmlIn,xmlOut);
> }
>
> public static void main(String[] args) throws Exception {
>
>
--
Davanum Srinivas - http://webservices.apache.org/~dims/
Re: cvs commit: ws-axis/java/test/message TestMessageElement.java
Posted by Davanum Srinivas <da...@gmail.com>.
Jongjin,
I was hunting for a test case...can u please add it to JIRA? That's
exactly i had not marked the bug as closed :)
thanks,
dims
On Mon, 5 Jul 2004 23:38:58 +0900, Jongjin Choi <gu...@hotmail.com> wrote:
> Hi, dims.
>
> I looked into the following MessageElement changes and ran a test.
> Does this change resolve the problem RPCParam <-> SOAP Element mapping
> addressed in http://nagoya.apache.org/jira/browse/AXIS-1416?
>
> I made a simple test and found that the problem is remaining.
>
> Without resolving the AXIS-1416,
> the standard JAX-RPC handler under Axis can not read or modify
> the second and below level SOAP body elements.
>
> Thanks.
>
> -----Original Message-----
> From: dims@apache.org [mailto:dims@apache.org]
> Sent: Thursday, June 24, 2004 9:28 PM
> To: ws-axis-cvs@apache.org
> Subject: cvs commit: ws-axis/java/test/message TestMessageElement.java
>
> dims 2004/06/24 05:27:38
>
> Modified: java/test/wsdl/faults FaultServiceSoapBindingImpl.java
> java/src/org/apache/axis/message MessageElement.java
> java/test/wsdl/sequence SequenceService.java
> java/src/org/apache/axis/encoding
> SerializationContextImpl.java
> java/test/encoding TestDOM.java
> java/test/message TestMessageElement.java
> Log:
> Fix for AXIS-1350 - new MessageElement(new Element()) does not behave like
> an Element
> Fix for AXIS-616 - MessageElement is not for mortals
> Fix for AXIS-1054 - No way to non-default namespace prefixes when creating
> MessageElements from DOM elements
> Fix for AXIS-1403 - calling MessageElement#getChildren with a Text-Only
> content returns an empty list
>
> Notes:
> - traverse all the nodes recursively and create new MessageElement's for
> each node.
>
> Revision Changes Path
> 1.5 +1 -1
> ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java
>
> Index: FaultServiceSoapBindingImpl.java
> ===================================================================
> RCS file:
> /home/cvs/ws-axis/java/test/wsdl/faults/FaultServiceSoapBindingImpl.java,v
> retrieving revision 1.4
> retrieving revision 1.5
> diff -u -r1.4 -r1.5
> --- FaultServiceSoapBindingImpl.java 11 Dec 2002 22:40:20 -0000 1.4
> +++ FaultServiceSoapBindingImpl.java 24 Jun 2004 12:27:37 -0000 1.5
> @@ -23,7 +23,7 @@
> public int throwExtensionFault(java.lang.String description) throws
> java.rmi.RemoteException, test.wsdl.faults.ExtensionFault {
> ExtensionType extension = new ExtensionType();
> try {
> - extension.set_any(new MessageElement[] {new
> MessageElement(XMLUtils.newDocument().createElement(description))});
> + extension.set_any(new MessageElement[] {new
> MessageElement(XMLUtils.newDocument().createElementNS(null,description))});
> } catch (Exception e) {
> throw new java.rmi.RemoteException(e.getMessage());
> }
>
> 1.173 +85 -36
> 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.172
> retrieving revision 1.173
> diff -u -r1.172 -r1.173
> --- MessageElement.java 23 Jun 2004 04:14:31 -0000 1.172
> +++ MessageElement.java 24 Jun 2004 12:27:37 -0000 1.173
> @@ -16,22 +16,6 @@
>
> package org.apache.axis.message;
>
> -import java.io.Reader;
> -import java.io.Serializable;
> -import java.io.StringReader;
> -import java.io.StringWriter;
> -import java.util.ArrayList;
> -import java.util.Iterator;
> -import java.util.Vector;
> -import java.util.Enumeration;
> -import java.util.List;
> -
> -import javax.xml.namespace.QName;
> -import javax.xml.rpc.encoding.TypeMapping;
> -import javax.xml.soap.Name;
> -import javax.xml.soap.SOAPElement;
> -import javax.xml.soap.SOAPException;
> -
> import org.apache.axis.AxisFault;
> import org.apache.axis.Constants;
> import org.apache.axis.MessageContext;
> @@ -48,6 +32,9 @@
> import org.apache.axis.utils.XMLUtils;
> import org.apache.commons.logging.Log;
> import org.w3c.dom.Attr;
> +import org.w3c.dom.CDATASection;
> +import org.w3c.dom.CharacterData;
> +import org.w3c.dom.Comment;
> import org.w3c.dom.DOMException;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> @@ -61,6 +48,21 @@
> import org.xml.sax.SAXException;
> import org.xml.sax.helpers.AttributesImpl;
>
> +import javax.xml.namespace.QName;
> +import javax.xml.rpc.encoding.TypeMapping;
> +import javax.xml.soap.Name;
> +import javax.xml.soap.SOAPElement;
> +import javax.xml.soap.SOAPException;
> +import java.io.Reader;
> +import java.io.Serializable;
> +import java.io.StringReader;
> +import java.io.StringWriter;
> +import java.util.ArrayList;
> +import java.util.Enumeration;
> +import java.util.Iterator;
> +import java.util.List;
> +import java.util.Vector;
> +
> /*
> * MessageElement is the base type of nodes of the SOAP message parse
> tree.
> *
> @@ -106,8 +108,7 @@
> protected int endEventIndex = -1;
>
> // ...or as DOM
> - protected Element elementRep = null;
> - protected Text textRep = null;
> + protected CharacterData textRep = null;
>
> protected MessageElement parent = null;
>
> @@ -163,12 +164,12 @@
>
> public MessageElement(Element elem)
> {
> - elementRep = elem;
> namespaceURI = elem.getNamespaceURI();
> name = elem.getLocalName();
> + copyNode(elem);
> }
>
> - public MessageElement(Text text)
> + public MessageElement(CharacterData text)
> {
> textRep = text;
> namespaceURI = text.getNamespaceURI();
> @@ -399,8 +400,7 @@
> * protected int startEventIndex = 0; N?
> * protected int startContentsIndex = 0; N?
> * protected int endEventIndex = -1; N?
> - * protected Element elementRep = null; N?
> - * protected Text textRep = null; Y?
> + * protected CharacterData textRep = null; Y?
> * protected MessageElement parent = null; N
> * public ArrayList namespaces = null; Y
> * protected String encodingStyle = null; N?
> @@ -608,7 +608,13 @@
>
> public short getNodeType() {
> if(this.textRep != null) {
> + if(textRep instanceof Comment) {
> + return COMMENT_NODE;
> + } else if(textRep instanceof CDATASection) {
> + return CDATA_SECTION_NODE;
> + } else {
> return TEXT_NODE;
> + }
> }else if(false){
> return DOCUMENT_FRAGMENT_NODE;
> }else if(false){
> @@ -908,11 +914,6 @@
> log.error(Messages.getMessage("childPresent"), exc);
> throw exc;
> }
> - if (elementRep != null) {
> - SOAPException exc = new
> SOAPException(Messages.getMessage("xmlPresent"));
> - log.error(Messages.getMessage("xmlPresent"), exc);
> - throw exc;
> - }
> if (textRep != null) {
> SOAPException exc = new
> SOAPException(Messages.getMessage("xmlPresent"));
> log.error(Messages.getMessage("xmlPresent"), exc);
> @@ -1165,18 +1166,20 @@
> */
> protected void outputImpl(SerializationContext context) throws
> Exception
> {
> - if (elementRep != null) {
> - boolean oldPretty = context.getPretty();
> - context.setPretty(false);
> - context.writeDOMElement(elementRep);
> - context.setPretty(oldPretty);
> - return;
> - }
> -
> if (textRep != null) {
> boolean oldPretty = context.getPretty();
> context.setPretty(false);
> - context.writeSafeString(textRep.getData());
> + if (textRep instanceof CDATASection) {
> + context.writeString("<![CDATA[");
> + context.writeString(((Text)textRep).getData());
> + context.writeString("]]>");
> + } else if (textRep instanceof Comment) {
> + context.writeString("<!--");
> + context.writeString(((CharacterData)textRep).getData());
> + context.writeString("-->");
> + } else if (textRep instanceof Text) {
> + context.writeSafeString(((Text)textRep).getData());
> + }
> context.setPretty(oldPretty);
> return;
> }
> @@ -1727,5 +1730,51 @@
> if (obj == null || !(obj instanceof MessageElement))
> return false;
> return toString().equals(obj.toString());
> + }
> +
> + private void copyNode(org.w3c.dom.Node element) {
> + copyNode(this, element);
> + }
> +
> + private void copyNode(MessageElement parent, org.w3c.dom.Node
> element)
> + {
> + parent.setPrefix(element.getPrefix());
> + if(element.getLocalName() != null) {
> + parent.setQName(new QName(element.getNamespaceURI(),
> element.getLocalName()));
> + }
> +
> + org.w3c.dom.NamedNodeMap attrs = element.getAttributes();
> + for(int i = 0; i < attrs.getLength(); i++){
> + org.w3c.dom.Node att = attrs.item(i);
> + if (att.getNamespaceURI() != null &&
> + att.getPrefix() != null &&
> + att.getNamespaceURI().equals(Constants.NS_URI_XMLNS) &&
> + att.getPrefix().equals("xmlns")) {
> + Mapping map = new Mapping(att.getNodeValue(),
> att.getLocalName());
> + addMapping(map);
> + }
> + parent.addAttribute(att.getPrefix(),
> + att.getNamespaceURI(),
> + att.getLocalName(),
> + att.getNodeValue());
> + }
> +
> + org.w3c.dom.NodeList children = element.getChildNodes();
> + for(int i = 0; i < children.getLength(); i++){
> + org.w3c.dom.Node child = children.item(i);
> + if(child.getNodeType()==TEXT_NODE ||
> + child.getNodeType()==CDATA_SECTION_NODE ||
> + child.getNodeType()==COMMENT_NODE ) {
> + MessageElement childElement = new
> MessageElement((CharacterData)child);
> + parent.appendChild(childElement);
> + } else {
> + PrefixedQName qname = new
> PrefixedQName(child.getNamespaceURI(),
> + child.getLocalName(),
> + child.getPrefix());
> + MessageElement childElement = new MessageElement(qname);
> + parent.appendChild(childElement);
> + copyNode(childElement, child);
> + }
> + }
> }
> }
>
> 1.8 +1 -1 ws-axis/java/test/wsdl/sequence/SequenceService.java
>
> Index: SequenceService.java
> ===================================================================
> RCS file: /home/cvs/ws-axis/java/test/wsdl/sequence/SequenceService.java,v
> retrieving revision 1.7
> retrieving revision 1.8
> diff -u -r1.7 -r1.8
> --- SequenceService.java 25 Feb 2004 14:03:05 -0000 1.7
> +++ SequenceService.java 24 Jun 2004 12:27:37 -0000 1.8
> @@ -78,7 +78,7 @@
> success = true;
> }
>
> - resultElement = retDoc.createElement("return");
> + resultElement = retDoc.createElementNS(null,"return");
>
> String resultStr = "false";
> if (success) {
>
> 1.111 +3 -0
> 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.110
> retrieving revision 1.111
> diff -u -r1.110 -r1.111
> --- SerializationContextImpl.java 8 Jun 2004 19:45:48 -0000
> 1.110
> +++ SerializationContextImpl.java 24 Jun 2004 12:27:37 -0000
> 1.111
> @@ -403,6 +403,9 @@
> if (prefix == null) {
> if (defaultPrefix == null) {
> prefix = "ns" + lastPrefixIndex++;
> + while(nsStack.getNamespaceURI(prefix)!=null) {
> + prefix = "ns" + lastPrefixIndex++;
> + }
> } else {
> prefix = defaultPrefix;
> }
>
> 1.19 +3 -3 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.18
> retrieving revision 1.19
> diff -u -r1.18 -r1.19
> --- TestDOM.java 18 Nov 2003 22:36:37 -0000 1.18
> +++ TestDOM.java 24 Jun 2004 12:27:38 -0000 1.19
> @@ -123,14 +123,14 @@
>
> public void testEmptyNode() throws Exception
> {
> - SOAPBodyElement body = new
> SOAPBodyElement(XMLUtils.newDocument().createElement("tmp"));
> + SOAPBodyElement body = new
> SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
> assertXMLEqual("<tmp/>",body.toString());
> }
>
> public void testNodeWithAttribute() throws Exception
> {
> - org.w3c.dom.Element element =
> XMLUtils.newDocument().createElement("tmp");
> - element.setAttribute("attrib", "foo");
> + org.w3c.dom.Element element =
> XMLUtils.newDocument().createElementNS(null,"tmp");
> + element.setAttributeNS(null,"attrib", "foo");
> SOAPBodyElement body = new SOAPBodyElement(element);
> assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());
> }
>
> 1.15 +75 -10 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.14
> retrieving revision 1.15
> diff -u -r1.14 -r1.15
> --- TestMessageElement.java 10 Apr 2004 21:12:06 -0000 1.14
> +++ TestMessageElement.java 24 Jun 2004 12:27:38 -0000 1.15
> @@ -16,7 +16,6 @@
>
> package test.message;
>
> -import junit.framework.TestCase;
> import org.apache.axis.Message;
> import org.apache.axis.MessageContext;
> import org.apache.axis.client.AxisClient;
> @@ -26,30 +25,37 @@
> import org.apache.axis.message.MessageElement;
> import org.apache.axis.message.PrefixedQName;
> import org.apache.axis.soap.SOAPConstants;
> +import org.apache.axis.utils.XMLUtils;
> +import org.w3c.dom.Document;
> +import org.w3c.dom.Element;
> +import org.w3c.dom.CDATASection;
> import org.xml.sax.Attributes;
> +import test.AxisTestBase;
>
> import javax.xml.namespace.QName;
> +import javax.xml.soap.MessageFactory;
> import javax.xml.soap.Name;
> +import javax.xml.soap.SOAPBody;
> +import javax.xml.soap.SOAPBodyElement;
> import javax.xml.soap.SOAPElement;
> -import javax.xml.soap.MessageFactory;
> +import javax.xml.soap.SOAPEnvelope;
> import javax.xml.soap.SOAPMessage;
> import javax.xml.soap.SOAPPart;
> -import javax.xml.soap.SOAPEnvelope;
> -import javax.xml.soap.SOAPBody;
> -import javax.xml.soap.SOAPBodyElement;
> -import java.util.Iterator;
> -import java.io.StringReader;
> -import java.io.ByteArrayOutputStream;
> -import java.io.ObjectOutputStream;
> +import javax.xml.parsers.DocumentBuilderFactory;
> +import javax.xml.parsers.DocumentBuilder;
> import java.io.ByteArrayInputStream;
> +import java.io.ByteArrayOutputStream;
> import java.io.ObjectInputStream;
> +import java.io.ObjectOutputStream;
> +import java.io.StringReader;
> +import java.util.Iterator;
>
> /**
> * Test MessageElement class.
> *
> * @author Glyn Normington (glyn@apache.org)
> */
> -public class TestMessageElement extends TestCase {
> +public class TestMessageElement extends AxisTestBase {
>
> public TestMessageElement(String name) {
> super(name);
> @@ -241,6 +247,65 @@
>
> assertEquals("m1 is not the same as m2", m1, m2);
> assertEquals("m2 is not the same as m1", m2, m1);
> + }
> +
> + public void testElementConstructor() throws Exception {
> + String xmlIn = "<h:html xmlns:xdc=\"http://www.xml.com/books\"\n"
> +
> + "
> xmlns:h=\"http://www.w3.org/HTML/1998/html4\">\n" +
> + " <h:head><h:title>Book
> Review</h:title></h:head>\n" +
> + " <h:body>\n" +
> + " <xdc:bookreview>\n" +
> + " <xdc:title>XML: A Primer</xdc:title>\n" +
> + " <h:table>\n" +
> + " <h:tr align=\"center\">\n" +
> + " <h:td>Author</h:td><h:td>Price</h:td>\n" +
> + "
> <h:td>Pages</h:td><h:td>Date</h:td></h:tr>\n" +
> + " <!-- here is a comment -->\n" +
> + " <h:tr align=\"left\">\n" +
> + " <h:td><xdc:author>Simon St.
> Laurent</xdc:author></h:td>\n" +
> + " <h:td><xdc:price>31.98</xdc:price></h:td>\n"
> +
> + " <h:td><xdc:pages>352</xdc:pages></h:td>\n" +
> + " <h:td><xdc:date>1998/01</xdc:date></h:td>\n"
> +
> + " <h:td><![CDATA[text content]]></h:td>\n" +
> + " </h:tr>\n" +
> + " </h:table>\n" +
> + " </xdc:bookreview>\n" +
> + " </h:body>\n" +
> + "</h:html>";
> +
> + Document doc = XMLUtils.newDocument(new
> ByteArrayInputStream(xmlIn.getBytes()));
> + MessageElement me = new MessageElement(doc.getDocumentElement());
> + String xmlOut = me.getAsString();
> + this.assertXMLEqual(xmlIn,xmlOut);
> + }
> +
> + public void testElementConstructor2() throws Exception {
> + String xmlIn = "<!-- This file can be used to deploy the
> echoAttachments sample -->\n" +
> + "<!-- using this command: java
> org.apache.axis.client.AdminClient attachdeploy.wsdd -->\n" +
> + "\n" +
> + "<!-- This deploys the echo attachment service. -->\n" +
> + "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\"
> xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\"
> xmlns:ns1=\"urn:EchoAttachmentsService\" >\n" +
> + " <service name=\"urn:EchoAttachmentsService\"
> provider=\"java:RPC\" >\n" +
> + " <parameter name=\"className\"
> value=\"samples.attachments.EchoAttachmentsService\"/>\n" +
> + " <parameter name=\"allowedMethods\" value=\"echo
> echoDir\"/>\n" +
> + " <operation name=\"echo\" returnQName=\"returnqname\"
> returnType=\"ns1:DataHandler\" >\n" +
> + " <parameter name=\"dh\"
> type=\"ns1:DataHandler\"/>\n" +
> + " </operation>\n" +
> + "\n" +
> + " <typeMapping
> deserializer=\"org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactor
> y\"\n" +
> + "
> languageSpecificType=\"java:javax.activation.DataHandler\"
> qname=\"ns1:DataHandler\"\n" +
> + "
> serializer=\"org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory\"\
> n" +
> + "
> encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" +
> + " />\n" +
> + " </service>\n" +
> + "\n" +
> + "</deployment>";
> +
> + Document doc = XMLUtils.newDocument(new
> ByteArrayInputStream(xmlIn.getBytes()));
> + MessageElement me = new MessageElement(doc.getDocumentElement());
> + String xmlOut = me.getAsString();
> + System.out.println(xmlOut);
> + this.assertXMLEqual(xmlIn,xmlOut);
> }
>
> public static void main(String[] args) throws Exception {
>
>
--
Davanum Srinivas - http://webservices.apache.org/~dims/