Author: darran.lofthouse(a)jboss.com
Date: 2010-12-08 15:34:10 -0500 (Wed, 08 Dec 2010)
New Revision: 13435
Modified:
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java
Log:
[JBPAPP-5546] SAAJ Where an Element is added to the SOAPBody this should be converted to a
SOAPElement.
Modified:
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
===================================================================
---
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2010-12-08
19:46:12 UTC (rev 13434)
+++
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2010-12-08
20:34:10 UTC (rev 13435)
@@ -292,8 +292,21 @@
return validChild == false;
}
- private static SOAPBodyElementDoc convertToBodyElement(Node node)
+ private static SOAPBodyElementDoc convertToBodyElement(Node node) throws DOMException
{
+ if (!(node instanceof SOAPElementImpl) && (node instanceof Element))
+ {
+ try
+ {
+ SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
+ node = (SOAPElementImpl)soapFactory.createElement((Element)node);
+ }
+ catch (SOAPException ex)
+ {
+ throw new DOMException(DOMException.INVALID_STATE_ERR, "Could not
convert Element to a SOAPElement");
+ }
+ }
+
if (!(node instanceof SOAPElementImpl))
throw new IllegalArgumentException("SOAPElement expected");
Modified:
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java
===================================================================
---
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java 2010-12-08
19:46:12 UTC (rev 13434)
+++
stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/common/soap/SOAPElementTestCase.java 2010-12-08
20:34:10 UTC (rev 13435)
@@ -38,6 +38,7 @@
import org.jboss.wsf.test.JBossWSTest;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -97,6 +98,24 @@
assertEquals(se, se2);
}
+ // JBWS-3170
+ public void testAppendNonSoapElement() throws Exception
+ {
+ MessageFactory msgFactory = MessageFactory.newInstance();
+ SOAPMessage soapMessage = msgFactory.createMessage();
+ SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
+ SOAPBody body = env.getBody();
+
+ Element e = body.getOwnerDocument().createElement("MyChild1");
+ SOAPElement se = (SOAPElement)body.appendChild(e);
+ assertNotNull("Expected an element", se);
+
+ assertEquals("Expected 1 child element", 1,
getIteratorCount(body.getChildElements()));
+
+ SOAPElement se2 = (SOAPElement)body.getChildElements().next();
+ assertEquals(se, se2);
+ }
+
//JBWS-2346
public void testGetElementByTagNameNS() throws Exception
{