Author: darran.lofthouse(a)jboss.com
Date: 2007-05-05 14:28:29 -0400 (Sat, 05 May 2007)
New Revision: 2970
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java
Log:
JBWS-1625 - Calling SOAPPart.setContent() with a DOMSource containing an Element which is
a SOAPElement the contents of the body are added twice.
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java 2007-05-05
18:27:51 UTC (rev 2969)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java 2007-05-05
18:28:29 UTC (rev 2970)
@@ -110,7 +110,8 @@
if (domElement == null)
throw new IllegalArgumentException("Source node cannot be null");
- if (domElement instanceof SOAPElement)
+ // Can only use this optimization if we are doing a deep copy.
+ if (domElement instanceof SOAPElement && deep==true)
return (SOAPElement)domElement;
String localName = domElement.getLocalName();
Modified:
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java
===================================================================
---
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java 2007-05-05
18:27:51 UTC (rev 2969)
+++
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java 2007-05-05
18:28:29 UTC (rev 2970)
@@ -33,6 +33,7 @@
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.jboss.test.ws.JBossWSTest;
@@ -127,7 +128,7 @@
assertEquals(Constants.NS_SOAP11_ENV, env.getNamespaceURI());
}
- public void testSetContentOnSOAPPart() throws Exception
+ public void testSetContentOnSOAPPart_StreamSource() throws Exception
{
String expMsg =
"<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" +
@@ -153,6 +154,34 @@
assertEquals(DOMUtils.parse(expMsg), DOMUtils.parse(wasMsg));
}
+ public void testSetContentOnSOAPPart_DOMSource() throws Exception
+ {
+ String expMsg =
+ "<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" +
+ " <soapenv:Header/>" +
+ " <soapenv:Body>" +
+ " <HelloResponse
xmlns='http://helloservice.org/types\'>" +
+ " <argument>responseBean</argument>" +
+ " </HelloResponse>" +
+ " </soapenv:Body>" +
+ "</soapenv:Envelope>";
+
+ MessageFactory factory = new MessageFactoryImpl();
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(expMsg.getBytes());
+ SOAPMessage soapMsg = factory.createMessage(null, inputStream);
+
+ SOAPMessage message = factory.createMessage();
+ message.getSOAPPart().setContent(soapMsg.getSOAPPart().getContent());
+ message.saveChanges();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ message.writeTo(baos);
+ String wasMsg = new String(baos.toByteArray());
+
+ assertEquals(DOMUtils.parse(expMsg), DOMUtils.parse(wasMsg));
+ }
+
// [JBWS-1511] MessageFactory does not preserve comments
public void testPreserveComments() throws Exception
{