Author: alessio.soldano(a)jboss.com
Date: 2010-03-12 13:35:43 -0500 (Fri, 12 Mar 2010)
New Revision: 11775
Modified:
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
Log:
[JBWS-2940] Adding testcase for proper handling of namespaces during soap content model
transition
Modified:
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
===================================================================
---
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2010-03-12
15:06:37 UTC (rev 11774)
+++
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2010-03-12
18:35:43 UTC (rev 11775)
@@ -32,10 +32,16 @@
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.Text;
+import org.jboss.ws.core.soap.MessageFactoryImpl;
import org.jboss.ws.core.soap.NameImpl;
+import org.jboss.ws.core.soap.SOAPBodyImpl;
import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.soap.SOAPElementImpl;
+import org.jboss.ws.core.soap.Style;
import org.jboss.ws.core.soap.XMLFragment;
import org.jboss.wsf.test.JBossWSTest;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* Test the SOAPContentElement
@@ -187,4 +193,53 @@
String expEnv = "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:...
xmlns:ns1='http://handlerservice1.org/wsdl'><String_1>wo... header
was added</String_1></ns1:hello></env:Body></env:Envelope>";
assertEquals(expEnv, baos.toString());
}
+
+
+ //JBWS-2940: JAXB marshalling of object model can lead to a slightly different yet
equivalent XMLFragment
+ //The new fragment can have different namespace prefix declarations, which can cause
major issues in unlucky situations like below
+ public void testAttributesHandlingOnModelTransition() throws Exception
+ {
+ String envStr =
+ "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
+ "<env:Body>" +
+ "<ns2:Foo xmlns:ns2='firstNS'/>" +
+ "</env:Body>" +
+ "</env:Envelope>";
+
+ MessageFactoryImpl factory = new MessageFactoryImpl();
+ factory.setStyle(Style.DOCUMENT);
+ SOAPMessage soapMessage = factory.createMessage(null, new
ByteArrayInputStream(envStr.getBytes()));
+
+ SOAPContentElement sce = getSOAPContentElement(soapMessage);
+
+ //force transition to XML_VALID and set an equivalent XMLFragment (but having a new
ns declaration that would overwrite the one in the original fragment)
+ sce.setXMLFragment(new XMLFragment("<Foo xmlns='firstNS'
xmlns:ns2='secondNs'/>"));
+
+ SOAPBody soapBody = soapMessage.getSOAPBody();
+ //force transition to DOM_VALID
+ soapBody.getFirstChild().getChildNodes();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ soapMessage.writeTo(baos);
+
+ soapMessage = factory.createMessage(null, new
ByteArrayInputStream(baos.toByteArray()));
+ Node foo = soapMessage.getSOAPBody().getFirstChild();
+ assertEquals("firstNS", foo.getNamespaceURI());
+ }
+
+ private SOAPContentElement getSOAPContentElement(final SOAPMessage soapMessage) throws
Exception
+ {
+ SOAPBodyImpl soapBody = (SOAPBodyImpl)soapMessage.getSOAPBody();
+ SOAPElementImpl bodyElement = null;
+ NodeList nodes = soapBody.getChildNodes();
+ for (int i = 0; i < nodes.getLength() && bodyElement == null; i++)
+ {
+ Node current = nodes.item(i);
+ if (current instanceof SOAPElementImpl)
+ {
+ bodyElement = (SOAPElementImpl)current;
+ }
+ }
+ return (SOAPContentElement)bodyElement;
+ }
}