Author: thomas.diesler(a)jboss.com
Date: 2007-04-26 14:42:38 -0400 (Thu, 26 Apr 2007)
New Revision: 2933
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/CommonSOAPBinding.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
Log:
[JBWS-1511] MessageFactory does not preserve comments. Fix test regression.
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/CommonSOAPBinding.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/CommonSOAPBinding.java 2007-04-26
14:03:24 UTC (rev 2932)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/CommonSOAPBinding.java 2007-04-26
18:42:38 UTC (rev 2933)
@@ -226,10 +226,13 @@
xmlName = namespaceRegistry.registerQName(xmlName);
Name soapName = new NameImpl(xmlName.getLocalPart(),
xmlName.getPrefix(), xmlName.getNamespaceURI());
- if (log.isDebugEnabled())
- log.debug("Add unboundHeader element: " + soapName);
+ log.debug("Add unboundHeader element: " + soapName);
SOAPContentElement contentElement = new
SOAPHeaderElementImpl(soapName);
contentElement.setParamMetaData(unboundHeader.toParameterMetaData(opMetaData));
+
+ if (soapHeader == null)
+ soapHeader = soapEnvelope.addHeader();
+
soapHeader.addChildElement(contentElement);
contentElement.setObjectValue(value);
}
@@ -542,7 +545,7 @@
throwFaultException((SOAPFaultImpl)soapBodyElement);
// Extract unbound OUT headers
- if (unboundHeaders != null)
+ if (unboundHeaders != null && soapHeader != null)
{
Map<QName, UnboundHeader> outHeaders = new HashMap<QName,
UnboundHeader>();
Iterator itHeaderElements = soapHeader.getChildElements();
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-04-26
14:03:24 UTC (rev 2932)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-04-26
18:42:38 UTC (rev 2933)
@@ -31,6 +31,7 @@
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
@@ -63,6 +64,8 @@
private static Logger log = Logger.getLogger(EnvelopeBuilderDOM.class);
private SOAPFactoryImpl soapFactory;
+ private String envNamespace;
+ private boolean isSOAP11;
private Style style;
public EnvelopeBuilderDOM(Style style)
@@ -117,7 +120,10 @@
SOAPPartImpl soapPart = (SOAPPartImpl)soapMessage.getSOAPPart();
SOAPEnvelopeImpl soapEnv = new SOAPEnvelopeImpl(soapPart,
soapFactory.createElement(domEnv, false), false);
- Document ownerDoc = soapEnv.getOwnerDocument();
+ // Get the envelope namespace
+ envNamespace = soapEnv.getNamespaceURI();
+ isSOAP11 = SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(envNamespace);
+
DOMUtils.copyAttributes(soapEnv, domEnv);
NodeList envChildNodes = domEnv.getChildNodes();
@@ -143,14 +149,11 @@
}
else if (childType == Node.COMMENT_NODE)
{
- String nodeValue = child.getNodeValue();
- Comment comment = ownerDoc.createComment(nodeValue);
- soapEnv.appendChild(comment);
+ appendCommentNode(soapEnv, child);
}
else if (childType == Node.TEXT_NODE)
{
- String nodeValue = child.getNodeValue();
- soapEnv.addTextNode(nodeValue);
+ appendTextNode(soapEnv, child);
}
else
{
@@ -167,7 +170,6 @@
if (soapHeader == null)
soapHeader = soapEnv.addHeader();
- Document ownerDoc = soapEnv.getOwnerDocument();
DOMUtils.copyAttributes(soapHeader, domHeader);
NodeList headerChildNodes = domHeader.getChildNodes();
@@ -189,14 +191,11 @@
}
else if (childType == Node.COMMENT_NODE)
{
- String nodeValue = child.getNodeValue();
- Comment comment = ownerDoc.createComment(nodeValue);
- soapHeader.appendChild(comment);
+ appendCommentNode(soapHeader, child);
}
else if (childType == Node.TEXT_NODE)
{
- String nodeValue = child.getNodeValue();
- soapHeader.addTextNode(nodeValue);
+ appendTextNode(soapHeader, child);
}
else
{
@@ -215,7 +214,6 @@
if (soapBody == null)
soapBody = (SOAPBodyImpl)soapEnv.addBody();
- Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBody, domBody);
SOAPBodyElement soapBodyElement = null;
@@ -241,14 +239,11 @@
}
else if (childType == Node.COMMENT_NODE)
{
- String nodeValue = child.getNodeValue();
- Comment comment = ownerDoc.createComment(nodeValue);
- soapBody.appendChild(comment);
+ appendCommentNode(soapBody, child);
}
else if (childType == Node.TEXT_NODE)
{
- String nodeValue = child.getNodeValue();
- soapBody.addTextNode(nodeValue);
+ appendTextNode(soapBody, child);
}
else
{
@@ -314,18 +309,20 @@
return soapBodyElement;
}
- public void buildBodyElementDoc(SOAPBodyImpl soapBody, Element domBodyElement) throws
SOAPException
+ public SOAPBodyElement buildBodyElementDoc(SOAPBodyImpl soapBody, Element
domBodyElement) throws SOAPException
{
Element srcElement = (Element)domBodyElement;
QName beName = DOMUtils.getElementQName(domBodyElement);
- SOAPContentElement contentElement = new SOAPBodyElementDoc(beName);
- contentElement = (SOAPContentElement)soapBody.addChildElement(contentElement);
+ SOAPBodyElementDoc soapBodyElement = new SOAPBodyElementDoc(beName);
+ SOAPContentElement contentElement =
(SOAPContentElement)soapBody.addChildElement(soapBodyElement);
DOMUtils.copyAttributes(contentElement, srcElement);
XMLFragment xmlFragment = new XMLFragment(new DOMSource(srcElement));
contentElement.setXMLFragment(xmlFragment);
+
+ return soapBodyElement;
}
public SOAPBodyElement buildBodyElementRpc(SOAPBodyImpl soapBody, Element
domBodyElement) throws SOAPException
@@ -334,7 +331,6 @@
SOAPBodyElementRpc soapBodyElement = new SOAPBodyElementRpc(beName);
soapBodyElement = (SOAPBodyElementRpc)soapBody.addChildElement(soapBodyElement);
- Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBodyElement, domBodyElement);
NodeList nlist = domBodyElement.getChildNodes();
@@ -356,14 +352,11 @@
}
else if (childType == Node.COMMENT_NODE)
{
- String nodeValue = child.getNodeValue();
- Comment comment = ownerDoc.createComment(nodeValue);
- soapBodyElement.appendChild(comment);
+ appendCommentNode(soapBodyElement, child);
}
else if (childType == Node.TEXT_NODE)
{
- String nodeValue = child.getNodeValue();
- soapBodyElement.addTextNode(nodeValue);
+ appendTextNode(soapBodyElement, child);
}
else
{
@@ -380,7 +373,6 @@
SOAPBodyElement soapBodyElement = new SOAPBodyElementMessage(beName);
soapBodyElement =
(SOAPBodyElementMessage)soapBody.addChildElement(soapBodyElement);
- Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBodyElement, domBodyElement);
NodeList nlist = domBodyElement.getChildNodes();
@@ -395,14 +387,11 @@
}
else if (childType == Node.COMMENT_NODE)
{
- String nodeValue = child.getNodeValue();
- Comment comment = ownerDoc.createComment(nodeValue);
- soapBodyElement.appendChild(comment);
+ appendCommentNode(soapBodyElement, child);
}
else if (childType == Node.TEXT_NODE)
{
- String nodeValue = child.getNodeValue();
- soapBodyElement.addTextNode(nodeValue);
+ appendTextNode(soapBodyElement, child);
}
else if (childType == Node.CDATA_SECTION_NODE)
{
@@ -417,4 +406,24 @@
return soapBodyElement;
}
+
+ private void appendCommentNode(SOAPElement soapElement, Node child)
+ {
+ if (isSOAP11)
+ {
+ String nodeValue = child.getNodeValue();
+ Document ownerDoc = soapElement.getOwnerDocument();
+ Comment comment = ownerDoc.createComment(nodeValue);
+ soapElement.appendChild(comment);
+ }
+ }
+
+ private void appendTextNode(SOAPElement soapElement, Node child) throws SOAPException
+ {
+ if (isSOAP11)
+ {
+ String nodeValue = child.getNodeValue();
+ soapElement.addTextNode(nodeValue);
+ }
+ }
}
Modified:
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java
===================================================================
---
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2007-04-26
14:03:24 UTC (rev 2932)
+++
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/SOAPContentElementTestCase.java 2007-04-26
18:42:38 UTC (rev 2933)
@@ -184,7 +184,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream();
soapMessage.writeTo(baos);
- 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>";
+ 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());
}
}