Author: darran.lofthouse(a)jboss.com
Date: 2007-04-26 19:09:55 -0400 (Thu, 26 Apr 2007)
New Revision: 2936
Modified:
branches/jbossws-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java
branches/jbossws-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
Log:
JBWS-1610 - Backport test regression fixes.
Modified:
branches/jbossws-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java
===================================================================
---
branches/jbossws-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java 2007-04-26
22:38:29 UTC (rev 2935)
+++
branches/jbossws-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java 2007-04-26
23:09:55 UTC (rev 2936)
@@ -200,9 +200,14 @@
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);
}
@@ -462,7 +467,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-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java
===================================================================
---
branches/jbossws-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-04-26
22:38:29 UTC (rev 2935)
+++
branches/jbossws-1.2.0.GA_JBWS-1610/jbossws-core/src/main/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-04-26
23:09:55 UTC (rev 2936)
@@ -33,6 +33,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;
@@ -65,6 +66,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)
@@ -119,7 +122,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();
@@ -145,14 +151,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
{
@@ -169,7 +172,6 @@
if (soapHeader == null)
soapHeader = soapEnv.addHeader();
- Document ownerDoc = soapEnv.getOwnerDocument();
DOMUtils.copyAttributes(soapHeader, domHeader);
NodeList headerChildNodes = domHeader.getChildNodes();
@@ -191,14 +193,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
{
@@ -217,7 +216,6 @@
if (soapBody == null)
soapBody = (SOAPBodyImpl)soapEnv.addBody();
- Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBody, domBody);
SOAPBodyElement soapBodyElement = null;
@@ -243,14 +241,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
{
@@ -340,18 +335,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
@@ -360,7 +357,6 @@
SOAPBodyElementRpc soapBodyElement = new SOAPBodyElementRpc(beName);
soapBodyElement = (SOAPBodyElementRpc)soapBody.addChildElement(soapBodyElement);
- Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBodyElement, domBodyElement);
NodeList nlist = domBodyElement.getChildNodes();
@@ -382,14 +378,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
{
@@ -406,7 +399,6 @@
SOAPBodyElement soapBodyElement = new SOAPBodyElementMessage(beName);
soapBodyElement =
(SOAPBodyElementMessage)soapBody.addChildElement(soapBodyElement);
- Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBodyElement, domBodyElement);
NodeList nlist = domBodyElement.getChildNodes();
@@ -421,14 +413,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)
{
@@ -443,4 +432,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);
+ }
+ }
}