You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by aj...@apache.org on 2007/07/02 06:14:50 UTC

svn commit: r552397 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java axiom-tests/src/test/java/org/apache/axiom/soap/SOAPEnvelopeBuildTest.java

Author: ajith
Date: Sun Jul  1 21:14:49 2007
New Revision: 552397

URL: http://svn.apache.org/viewvc?view=rev&rev=552397
Log:
1. Fixing issue WSCOMMONS-211. The fault was in the OMStaxWrapper logic.
2. Added Davids testcase as one of the standard tests so that we will not break this in the future

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPEnvelopeBuildTest.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java?view=diff&rev=552397&r1=552396&r2=552397
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java Sun Jul  1 21:14:49 2007
@@ -1002,9 +1002,14 @@
             }
         } else {
             if (state == SWITCHED) {
-                if (currentEvent == START_ELEMENT) {
+                //this is a potential place for bugs
+                //we have to test if the root node of this parser
+                //has the same name for this test
+                if (currentEvent == START_ELEMENT &&
+                        (parser.getLocalName().equals(((OMElement)rootNode).getLocalName()))) {
                     ++depth;
-                } else if (currentEvent == END_ELEMENT) {
+                } else if (currentEvent == END_ELEMENT   &&
+                       (parser.getLocalName().equals(((OMElement)rootNode).getLocalName())) ) {                                      
                     --depth;
                     if (depth < 0) {
                         state = COMPLETED;

Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPEnvelopeBuildTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPEnvelopeBuildTest.java?view=auto&rev=552397
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPEnvelopeBuildTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPEnvelopeBuildTest.java Sun Jul  1 21:14:49 2007
@@ -0,0 +1,120 @@
+package org.apache.axiom.soap;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+public class SOAPEnvelopeBuildTest extends TestCase {
+
+
+	String testMessage="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
+    "<soapenv:Header><x:Header xmlns:x=\"http://test/\">Hello</x:Header></soapenv:Header>"+
+    "<soapenv:Body><x:Content xmlns:x=\"http://test/\">Hello</x:Content></soapenv:Body>"+
+    	"</soapenv:Envelope>";
+
+	public void testBodyPreservedSerialize() throws Exception{
+		XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(testMessage));
+		StAXSOAPModelBuilder sob = new StAXSOAPModelBuilder(parser, null);
+		SOAPEnvelope se = (SOAPEnvelope)sob.getDocumentElement();
+		SOAPHeader sh = se.getHeader();
+		Iterator iter = sh.getChildElements();
+		while(iter.hasNext())iter.next();
+
+		StringWriter sw = new StringWriter();
+		se.serialize(sw);
+
+		checkBodyExists(sw.toString());
+	}
+
+	public void testBodyPreservedSerializeAndConsume() throws Exception{
+		XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(testMessage));
+		StAXSOAPModelBuilder sob = new StAXSOAPModelBuilder(parser, null);
+		SOAPEnvelope se = (SOAPEnvelope)sob.getDocumentElement();
+		SOAPHeader sh = se.getHeader();
+        sh.build();
+		StringWriter sw = new StringWriter();
+		se.serializeAndConsume(sw);
+
+		checkBodyExists(sw.toString());
+	}
+
+    public void testBodyPreservedSerializeAndConsumeAsXML() throws Exception{
+		XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(testMessage));
+		StAXOMBuilder sob = new StAXOMBuilder(parser);
+		OMElement se = sob.getDocumentElement();
+		OMElement sh = se.getFirstElement();
+		Iterator iter = sh.getChildElements();
+		while(iter.hasNext())iter.next();
+		StringWriter sw = new StringWriter();
+		se.serializeAndConsume(sw);
+
+		checkBodyExists(sw.toString());
+	}
+
+    public void testBodyPreservedSerializeAndConsumeDoesntTouchHeaders() throws Exception{
+		XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(testMessage));
+		StAXSOAPModelBuilder sob = new StAXSOAPModelBuilder(parser, null);
+		SOAPEnvelope se = (SOAPEnvelope)sob.getDocumentElement();
+
+		StringWriter sw = new StringWriter();
+		se.serializeAndConsume(sw);
+
+		checkBodyExists(sw.toString());
+	}
+
+	public void testBodyPreservedSerializeAndConsumeTouchesBody() throws Exception{
+		XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(testMessage));
+		StAXSOAPModelBuilder sob = new StAXSOAPModelBuilder(parser, null);
+		SOAPEnvelope se = (SOAPEnvelope)sob.getDocumentElement();
+		SOAPHeader sh = se.getHeader();
+		Iterator iter = sh.getChildElements();
+		while(iter.hasNext())iter.next();
+		se.getBody();
+		StringWriter sw = new StringWriter();
+		se.serializeAndConsume(sw);
+
+		checkBodyExists(sw.toString());
+	}
+
+	private void checkBodyExists(String str) throws Exception{
+		XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(str));
+		StAXSOAPModelBuilder sob = new StAXSOAPModelBuilder(parser, null);
+		SOAPEnvelope se = (SOAPEnvelope)sob.getDocumentElement();
+		SOAPBody sb = se.getBody();
+		if(sb == null){
+			fail("No SOAP Body");
+		}
+		Iterator children = sb.getChildElements();
+		if(!children.hasNext()){
+			fail("No children of the Body element");
+		}
+	}
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org