Author: thomas.diesler(a)jboss.com
Date: 2007-04-23 08:30:58 -0400 (Mon, 23 Apr 2007)
New Revision: 2899
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/Constants.java
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/jaxws/handler/LogicalMessageImpl.java
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/EnvelopeBuilderStax.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/NodeImpl.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyElementMessage.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/TextImpl.java
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java
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/jaxrpc/marshall/MarshallTest.java
Log:
[JBWS-1511] MessageFactory does not preserve comments
Modified: branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/Constants.java
===================================================================
--- branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/Constants.java 2007-04-23
08:00:28 UTC (rev 2898)
+++ branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/Constants.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -120,7 +120,7 @@
static final String PREFIX_XML = "xml";
/** XOP Include */
- static final Name NAME_XOP_INCLUDE = new NameImpl("Include", PREFIX_XOP,
NS_XOP);
+ static final QName NAME_XOP_INCLUDE = new QName(NS_XOP, "Include",
PREFIX_XOP);
/** SOAP-1.1 roles */
static final String URI_SOAP11_NEXT_ACTOR =
"http://schemas.xmlsoap.org/soap/actor/next";
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-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/CommonSOAPBinding.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -34,6 +34,7 @@
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
+import javax.xml.soap.Node;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
@@ -133,7 +134,8 @@
protected abstract MessageAbstraction createMessage(OperationMetaData opMetaData)
throws SOAPException;
/** On the client side, generate the payload from IN parameters. */
- public MessageAbstraction bindRequestMessage(OperationMetaData opMetaData,
EndpointInvocation epInv, Map<QName, UnboundHeader> unboundHeaders) throws
BindingException
+ public MessageAbstraction bindRequestMessage(OperationMetaData opMetaData,
EndpointInvocation epInv, Map<QName, UnboundHeader> unboundHeaders)
+ throws BindingException
{
if (log.isDebugEnabled())
log.debug("bindRequestMessage: " + opMetaData.getQName());
@@ -320,17 +322,26 @@
{
boolean isHeader = paramMetaData.isInHeader();
SOAPElement element = isHeader ? soapHeader : soapBodyElement;
- if(!isHeader) numParameters++;
-
+ if (!isHeader)
+ numParameters++;
+
SOAPContentElement value = getParameterFromMessage(paramMetaData,
element, false);
epInv.setRequestParamValue(xmlName, value);
}
}
}
- // TCK: verify the numer of parameters matches the actual message payload
- int numChildren = soapBodyElement.getChildNodes().getLength();
- if(numChildren!=numParameters) throw new WSException("Invalid number of
payload elements: " + numChildren);
+ // Verify the numer of parameters matches the actual message payload
+ int numChildElements = 0;
+ Iterator itElements = soapBodyElement.getChildElements();
+ while (itElements.hasNext())
+ {
+ Node node = (Node)itElements.next();
+ if (node instanceof SOAPElement)
+ numChildElements++;
+ }
+ if (numChildElements != numParameters)
+ throw new WSException("Invalid number of payload elements: " +
numChildElements);
}
// Generic message endpoint
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -105,6 +105,7 @@
{
try
{
+ soapBody.removeContents();
EnvelopeBuilderDOM builder = new EnvelopeBuilderDOM(style);
Element domBodyElement = DOMUtils.sourceToElement(source);
builder.buildBodyElementRpc(soapBody, domBodyElement);
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-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderDOM.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -26,10 +26,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
-import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.soap.Name;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
@@ -42,7 +43,10 @@
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.Style;
import org.jboss.ws.core.utils.DOMUtils;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
@@ -58,10 +62,12 @@
// provide logging
private static Logger log = Logger.getLogger(EnvelopeBuilderDOM.class);
- private Style style = Style.DOCUMENT;
+ private SOAPFactoryImpl soapFactory;
+ private Style style;
public EnvelopeBuilderDOM(Style style)
{
+ this.soapFactory = new SOAPFactoryImpl();
this.style = style;
}
@@ -107,29 +113,71 @@
public SOAPEnvelope build(SOAPMessage soapMessage, Element domEnv) throws
SOAPException
{
- String envNS = domEnv.getNamespaceURI();
- String envPrefix = domEnv.getPrefix();
-
// Construct the envelope
- SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
SOAPPartImpl soapPart = (SOAPPartImpl)soapMessage.getSOAPPart();
- SOAPEnvelopeImpl soapEnv = new SOAPEnvelopeImpl(soapPart,
soapFactory.createElement(domEnv, false));
+ SOAPEnvelopeImpl soapEnv = new SOAPEnvelopeImpl(soapPart,
soapFactory.createElement(domEnv, false), false);
+ Document ownerDoc = soapEnv.getOwnerDocument();
DOMUtils.copyAttributes(soapEnv, domEnv);
- // Add the header elements
- Element domHeader = DOMUtils.getFirstChildElement(domEnv, new QName(envNS,
"Header"));
- if (domHeader != null)
+ NodeList envChildNodes = domEnv.getChildNodes();
+ for (int i = 0; i < envChildNodes.getLength(); i++)
{
- SOAPHeader soapHeader = soapEnv.getHeader();
+ Node child = envChildNodes.item(i);
+ short childType = child.getNodeType();
+ if (childType == Node.ELEMENT_NODE)
+ {
+ String elName = child.getLocalName();
+ if ("Header".equals(elName))
+ {
+ buildSOAPHeader(soapEnv, (Element)child);
+ }
+ else if ("Body".equals(elName))
+ {
+ buildSOAPBody(soapEnv, (Element)child);
+ }
+ else
+ {
+ log.warn("Ignore envelope chile element: " + elName);
+ }
+ }
+ else if (childType == Node.COMMENT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ Comment comment = ownerDoc.createComment(nodeValue);
+ soapEnv.appendChild(comment);
+ }
+ else if (childType == Node.TEXT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ soapEnv.addTextNode(nodeValue);
+ }
+ else
+ {
+ log.warn("Ignore child type: " + childType);
+ }
+ }
- DOMUtils.copyAttributes(soapHeader, domHeader);
+ return soapEnv;
+ }
- Iterator it = DOMUtils.getChildElements(domHeader);
- while (it.hasNext())
+ private SOAPHeader buildSOAPHeader(SOAPEnvelopeImpl soapEnv, Element domHeader) throws
SOAPException
+ {
+ SOAPHeader soapHeader = soapEnv.getHeader();
+ if (soapHeader == null)
+ soapHeader = soapEnv.addHeader();
+
+ Document ownerDoc = soapEnv.getOwnerDocument();
+ DOMUtils.copyAttributes(soapHeader, domHeader);
+
+ NodeList headerChildNodes = domHeader.getChildNodes();
+ for (int i = 0; i < headerChildNodes.getLength(); i++)
+ {
+ Node child = headerChildNodes.item(i);
+ short childType = child.getNodeType();
+ if (childType == Node.ELEMENT_NODE)
{
- Element srcElement = (Element)it.next();
- //registerNamespacesLocally(srcElement);
+ Element srcElement = (Element)child;
XMLFragment xmlFragment = new XMLFragment(new DOMSource(srcElement));
Name name = new NameImpl(srcElement.getLocalName(), srcElement.getPrefix(),
srcElement.getNamespaceURI());
@@ -139,99 +187,75 @@
DOMUtils.copyAttributes(destElement, srcElement);
destElement.setXMLFragment(xmlFragment);
}
+ else if (childType == Node.COMMENT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ Comment comment = ownerDoc.createComment(nodeValue);
+ soapHeader.appendChild(comment);
+ }
+ else if (childType == Node.TEXT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ soapHeader.addTextNode(nodeValue);
+ }
+ else
+ {
+ log.warn("Ignore child type: " + childType);
+ }
}
- // Add the body elements
- Element domBody = DOMUtils.getFirstChildElement(domEnv, new QName(envNS,
"Body"));
+ return soapHeader;
+ }
+
+ private SOAPBody buildSOAPBody(SOAPEnvelopeImpl soapEnv, Element domBody) throws
SOAPException
+ {
+ String envNS = soapEnv.getNamespaceURI();
+
SOAPBodyImpl soapBody = (SOAPBodyImpl)soapEnv.getBody();
+ if (soapBody == null)
+ soapBody = (SOAPBodyImpl)soapEnv.addBody();
+ Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBody, domBody);
- Iterator itBody = DOMUtils.getChildElements(domBody);
- if (itBody.hasNext())
+ SOAPBodyElement soapBodyElement = null;
+ boolean attachHRefElements =
Constants.URI_SOAP11_ENC.equals(soapEnv.getAttributeNS(envNS,
"encodingStyle"));
+
+ NodeList bodyChildNodes = domBody.getChildNodes();
+ for (int i = 0; i < bodyChildNodes.getLength(); i++)
{
- Element domBodyElement = (Element)itBody.next();
-
- String localName = domBodyElement.getLocalName();
- String prefix = domBodyElement.getPrefix();
- String nsURI = domBodyElement.getNamespaceURI();
- Name beName = new NameImpl(localName, prefix, nsURI);
-
- // Process a <env:Fault> message
- if (beName.equals(new NameImpl("Fault", envPrefix, envNS)))
+ Node child = bodyChildNodes.item(i);
+ short childType = child.getNodeType();
+ if (childType == Node.ELEMENT_NODE)
{
- SOAPFaultImpl soapFault = new SOAPFaultImpl(envPrefix, envNS);
- soapBody.addChildElement(soapFault);
-
- DOMUtils.copyAttributes(soapFault, domBodyElement);
-
- // copy everything and let soapFault discover child elements itself
- XMLFragment xmlFragment = new XMLFragment(new DOMSource(domBodyElement));
- soapFault.setXMLFragment(xmlFragment);
- }
-
- // Process and RPC or DOCUMENT style message
- else
- {
-
- if (style == Style.RPC)
+ if (soapBodyElement == null)
{
- buildBodyElementRpc(soapBody, domBodyElement);
+ soapBodyElement = buildSOAPBodyElement(soapEnv, (Element)child);
+ attachHRefElements = attachHRefElements ||
Constants.URI_SOAP11_ENC.equals(soapBody.getAttributeNS(envNS,
"encodingStyle"));
}
- else if (style == Style.DOCUMENT)
+ else if (attachHRefElements)
{
- buildBodyElementDoc(soapBody, domBodyElement);
+ // Process additional soap encoded body elements
+ soapBody.addChildElement(soapFactory.createElement((Element)child,
true));
}
- else if (style == null)
- {
- SOAPBodyElementMessage soapBodyElement = new
SOAPBodyElementMessage(beName);
- soapBodyElement =
(SOAPBodyElementMessage)soapBody.addChildElement(soapBodyElement);
-
- DOMUtils.copyAttributes(soapBodyElement, domBodyElement);
-
- NodeList nlist = domBodyElement.getChildNodes();
- for (int i = 0; i < nlist.getLength(); i++)
- {
- org.w3c.dom.Node child = nlist.item(i);
- short childType = child.getNodeType();
- if (childType == org.w3c.dom.Node.ELEMENT_NODE)
- {
- SOAPElement soapElement =
soapFactory.createElement((Element)child);
- soapBodyElement.addChildElement(soapElement);
- }
- else if (childType == org.w3c.dom.Node.TEXT_NODE)
- {
- String nodeValue = child.getNodeValue();
- soapBodyElement.addTextNode(nodeValue);
- }
- else if (childType == org.w3c.dom.Node.CDATA_SECTION_NODE)
- {
- String nodeValue = child.getNodeValue();
- soapBodyElement.addTextNode(nodeValue);
- }
- else
- {
- log.warn("Ignore child type: " + childType);
- }
- }
- }
- else
- {
- throw new WSException("Unsupported message style: " + style);
- }
}
+ else if (childType == Node.COMMENT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ Comment comment = ownerDoc.createComment(nodeValue);
+ soapBody.appendChild(comment);
+ }
+ else if (childType == Node.TEXT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ soapBody.addTextNode(nodeValue);
+ }
+ else
+ {
+ log.warn("Ignore child type: " + childType);
+ }
}
- // Process additional soap encoded body elements
- boolean attachHRefElements =
Constants.URI_SOAP11_ENC.equals(soapEnv.getAttributeNS(envNS,
"encodingStyle"));
- attachHRefElements = attachHRefElements ||
Constants.URI_SOAP11_ENC.equals(soapBody.getAttributeNS(envNS,
"encodingStyle"));
- attachHRefElements = attachHRefElements && itBody.hasNext();
- while (attachHRefElements && itBody.hasNext())
- {
- Element srcElement = (Element)itBody.next();
- soapBody.addChildElement(soapFactory.createElement(srcElement, true));
- }
-
// Inline all attached href elements
if (attachHRefElements)
{
@@ -239,48 +263,158 @@
inlineHandler.processHRefs();
}
- return soapEnv;
+ return soapBody;
}
+ private SOAPBodyElement buildSOAPBodyElement(SOAPEnvelopeImpl soapEnv, Element
domBodyElement) throws SOAPException
+ {
+ String envNS = soapEnv.getNamespaceURI();
+ String envPrefix = soapEnv.getPrefix();
+
+ SOAPBodyImpl soapBody = (SOAPBodyImpl)soapEnv.getBody();
+ QName beName = DOMUtils.getElementQName(domBodyElement);
+
+ SOAPBodyElement soapBodyElement = null;
+
+ // Process a <env:Fault> message
+ if (beName.equals(new QName(envNS, "Fault")))
+ {
+ SOAPFaultImpl soapFault = new SOAPFaultImpl(envPrefix, envNS);
+ soapBody.addChildElement(soapFault);
+ soapBodyElement = soapFault;
+
+ DOMUtils.copyAttributes(soapFault, domBodyElement);
+
+ // copy everything and let soapFault discover child elements itself
+ XMLFragment xmlFragment = new XMLFragment(new DOMSource(domBodyElement));
+ soapFault.setXMLFragment(xmlFragment);
+ }
+
+ // Process and RPC or DOCUMENT style message
+ else
+ {
+ if (style == Style.DOCUMENT)
+ {
+ buildBodyElementDoc(soapBody, domBodyElement);
+ }
+ else if (style == Style.RPC)
+ {
+ soapBodyElement = buildBodyElementRpc(soapBody, domBodyElement);
+ }
+ else if (style == null)
+ {
+ buildBodyElementDefault(soapBody, domBodyElement);
+ }
+ else
+ {
+ throw new WSException("Unsupported message style: " + style);
+ }
+ }
+
+ return soapBodyElement;
+ }
+
public void buildBodyElementDoc(SOAPBodyImpl soapBody, Element domBodyElement) throws
SOAPException
{
- soapBody.removeContents();
-
Element srcElement = (Element)domBodyElement;
QName beName = DOMUtils.getElementQName(domBodyElement);
- SOAPContentElement destElement = new SOAPBodyElementDoc(beName);
- destElement = (SOAPContentElement)soapBody.addChildElement(destElement);
+ SOAPContentElement contentElement = new SOAPBodyElementDoc(beName);
+ contentElement = (SOAPContentElement)soapBody.addChildElement(contentElement);
- DOMUtils.copyAttributes(destElement, srcElement);
+ DOMUtils.copyAttributes(contentElement, srcElement);
XMLFragment xmlFragment = new XMLFragment(new DOMSource(srcElement));
- destElement.setXMLFragment(xmlFragment);
+ contentElement.setXMLFragment(xmlFragment);
}
- public void buildBodyElementRpc(SOAPBodyImpl soapBody, Element domBodyElement) throws
SOAPException
+ public SOAPBodyElement buildBodyElementRpc(SOAPBodyImpl soapBody, Element
domBodyElement) throws SOAPException
{
- soapBody.removeContents();
-
QName beName = DOMUtils.getElementQName(domBodyElement);
SOAPBodyElementRpc soapBodyElement = new SOAPBodyElementRpc(beName);
soapBodyElement = (SOAPBodyElementRpc)soapBody.addChildElement(soapBodyElement);
+ Document ownerDoc = soapBody.getOwnerDocument();
DOMUtils.copyAttributes(soapBodyElement, domBodyElement);
- Iterator itBodyElement = DOMUtils.getChildElements(domBodyElement);
- while (itBodyElement.hasNext())
+ NodeList nlist = domBodyElement.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
{
- Element srcElement = (Element)itBodyElement.next();
+ Node child = nlist.item(i);
+ short childType = child.getNodeType();
+ if (childType == Node.ELEMENT_NODE)
+ {
+ Element srcElement = (Element)child;
+ Name name = new NameImpl(srcElement.getLocalName(), srcElement.getPrefix(),
srcElement.getNamespaceURI());
+ SOAPContentElement destElement = new SOAPContentElement(name);
+ destElement =
(SOAPContentElement)soapBodyElement.addChildElement(destElement);
- Name name = new NameImpl(srcElement.getLocalName(), srcElement.getPrefix(),
srcElement.getNamespaceURI());
- SOAPContentElement destElement = new SOAPContentElement(name);
- destElement = (SOAPContentElement)soapBodyElement.addChildElement(destElement);
+ DOMUtils.copyAttributes(destElement, srcElement);
- DOMUtils.copyAttributes(destElement, srcElement);
+ XMLFragment xmlFragment = new XMLFragment(new DOMSource(srcElement));
+ destElement.setXMLFragment(xmlFragment);
+ }
+ else if (childType == Node.COMMENT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ Comment comment = ownerDoc.createComment(nodeValue);
+ soapBodyElement.appendChild(comment);
+ }
+ else if (childType == Node.TEXT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ soapBodyElement.addTextNode(nodeValue);
+ }
+ else
+ {
+ log.warn("Ignore child type: " + childType);
+ }
+ }
- XMLFragment xmlFragment = new XMLFragment(new DOMSource(srcElement));
- destElement.setXMLFragment(xmlFragment);
+ return soapBodyElement;
+ }
+
+ public SOAPBodyElement buildBodyElementDefault(SOAPBodyImpl soapBody, Element
domBodyElement) throws SOAPException
+ {
+ QName beName = DOMUtils.getElementQName(domBodyElement);
+ SOAPBodyElement soapBodyElement = new SOAPBodyElementMessage(beName);
+ soapBodyElement =
(SOAPBodyElementMessage)soapBody.addChildElement(soapBodyElement);
+
+ Document ownerDoc = soapBody.getOwnerDocument();
+ DOMUtils.copyAttributes(soapBodyElement, domBodyElement);
+
+ NodeList nlist = domBodyElement.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
+ {
+ Node child = nlist.item(i);
+ short childType = child.getNodeType();
+ if (childType == Node.ELEMENT_NODE)
+ {
+ SOAPElement soapElement = soapFactory.createElement((Element)child);
+ soapBodyElement.addChildElement(soapElement);
+ }
+ else if (childType == Node.COMMENT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ Comment comment = ownerDoc.createComment(nodeValue);
+ soapBodyElement.appendChild(comment);
+ }
+ else if (childType == Node.TEXT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ soapBodyElement.addTextNode(nodeValue);
+ }
+ else if (childType == Node.CDATA_SECTION_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ soapBodyElement.addTextNode(nodeValue);
+ }
+ else
+ {
+ log.warn("Ignore child type: " + childType);
+ }
}
+
+ return soapBodyElement;
}
}
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderStax.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -256,7 +256,7 @@
if (Part.ENVELOPE == currentPart)
{
// setup envelope impl
- soapEnv = new SOAPEnvelopeImpl(soapPart, qName.getNamespaceURI());
+ soapEnv = new SOAPEnvelopeImpl(soapPart, qName.getNamespaceURI(), false);
destElement = soapEnv; // soapEnv becomes current
}
else if (Part.HEADER == currentPart)
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/MessageFactoryImpl.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -154,7 +154,7 @@
SOAPMessageImpl soapMessage = new SOAPMessageImpl();
SOAPPartImpl soapPart = (SOAPPartImpl)soapMessage.getSOAPPart();
- new SOAPEnvelopeImpl(soapPart, envNamespace);
+ new SOAPEnvelopeImpl(soapPart, envNamespace, true);
return soapMessage;
}
Modified: branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/NodeImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/NodeImpl.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/NodeImpl.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -552,6 +552,10 @@
{
retNode = new TextImpl(node);
}
+ else if (node instanceof org.w3c.dom.Comment)
+ {
+ retNode = new TextImpl(node);
+ }
else
{
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Operation not
supported on this type of node: " + node);
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyElementMessage.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyElementMessage.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyElementMessage.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -23,8 +23,8 @@
import java.io.Writer;
+import javax.xml.namespace.QName;
import javax.xml.rpc.JAXRPCException;
-import javax.xml.soap.Name;
import javax.xml.soap.SOAPBodyElement;
import org.jboss.ws.core.utils.DOMWriter;
@@ -39,7 +39,7 @@
*/
public class SOAPBodyElementMessage extends SOAPElementImpl implements SOAPBodyElement
{
- public SOAPBodyElementMessage(Name name)
+ public SOAPBodyElementMessage(QName name)
{
super(name);
}
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -38,6 +38,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.core.utils.DOMUtils;
+import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
@@ -254,10 +255,14 @@
return newDocument;
}
- private static boolean needsConversionToBodyElement(Node node)
+ private static boolean needsConversionToBodyElement(Node newChild)
{
// JBCTS-440 #addTextNodeTest1 appends a Text node to a SOAPBody
- return !(node instanceof SOAPBodyElement || node instanceof DocumentFragment ||
node instanceof Text);
+ boolean validChild = newChild instanceof SOAPBodyElement;
+ validChild = validChild || newChild instanceof DocumentFragment;
+ validChild = validChild || newChild instanceof Text;
+ validChild = validChild || newChild instanceof Comment;
+ return validChild == false;
}
private static SOAPBodyElementDoc convertToBodyElement(Node node)
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPEnvelopeImpl.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -54,7 +54,7 @@
/** Construct a SOAP envelope for the given SOAP version URI prefix, etc.
*/
- public SOAPEnvelopeImpl(SOAPPartImpl soapPart, SOAPElement element) throws
SOAPException
+ public SOAPEnvelopeImpl(SOAPPartImpl soapPart, SOAPElement element, boolean
addHeaderAndBody) throws SOAPException
{
super((SOAPElementImpl)element);
@@ -71,16 +71,16 @@
assertEnvelopeNamespace(namespaceURI);
addNamespaceDeclaration(prefix, namespaceURI);
- // the Element source might already contain a Header and Body declaration
- if (null == soapPart.getEnvelope().getHeader())
+ if (addHeaderAndBody)
+ {
addHeader();
- if (null == soapPart.getEnvelope().getBody())
addBody();
+ }
}
/** Construct a SOAP envelope for the given SOAP version URI.
*/
- SOAPEnvelopeImpl(SOAPPartImpl soapPart, String namespace) throws SOAPException
+ SOAPEnvelopeImpl(SOAPPartImpl soapPart, String namespace, boolean addHeaderAndBody)
throws SOAPException
{
super("Envelope", Constants.PREFIX_ENV, namespace);
@@ -90,8 +90,11 @@
assertEnvelopeNamespace(namespace);
addNamespaceDeclaration(getPrefix(), namespace);
- addHeader();
- addBody();
+ if (addHeaderAndBody)
+ {
+ addHeader();
+ addBody();
+ }
}
public SOAPMessage getSOAPMessage()
@@ -156,7 +159,7 @@
while (it.hasNext())
{
Node node = (Node)it.next();
- if (node.getLocalName().equals("Body"))
+ if ("Body".equals(node.getLocalName()))
return (SOAPBody)node;
}
return null;
@@ -168,7 +171,7 @@
while (it.hasNext())
{
Node node = (Node)it.next();
- if (node.getLocalName().equals("Header"))
+ if ("Header".equals(node.getLocalName()))
return (SOAPHeader)node;
}
return null;
@@ -179,7 +182,10 @@
*/
public SOAPElement addTextNode(String value) throws SOAPException
{
- throw new SOAPException("Cannot add Text node to SOAPEnvelope");
+ if (value.trim().length() > 0)
+ throw new SOAPException("Cannot add Text node to SOAPEnvelope");
+
+ return super.addTextNode(value);
}
public Document getOwnerDocument()
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPHeaderImpl.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -36,6 +36,7 @@
import org.jboss.ws.Constants;
import org.jboss.ws.core.utils.SAAJUtils;
+import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
@@ -272,7 +273,11 @@
private static boolean needsConversionToHeaderElement(Node newChild)
{
// JBCTS-440 #addTextNodeTest2 appends a Text node to a SOAPHeader
- return !(newChild instanceof SOAPHeaderElementImpl || newChild instanceof
DocumentFragment || newChild instanceof Text);
+ boolean validChild = newChild instanceof SOAPHeaderElementImpl;
+ validChild = validChild || newChild instanceof DocumentFragment;
+ validChild = validChild || newChild instanceof Text;
+ validChild = validChild || newChild instanceof Comment;
+ return validChild == false;
}
private static SOAPHeaderElementImpl convertToHeaderElement(Node node)
Modified: branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/TextImpl.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/TextImpl.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/TextImpl.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -42,8 +42,7 @@
*/
public boolean isComment()
{
- String value = getNodeValue().trim();
- return value.startsWith("<!--") &&
value.endsWith("-->");
+ return domNode.getNodeType() == org.w3c.dom.Node.COMMENT_NODE;
}
public String getValue()
Modified:
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java
===================================================================
---
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-core/src/java/org/jboss/ws/core/soap/XMLContent.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -33,7 +33,6 @@
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.xml.namespace.QName;
-import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.transform.Source;
@@ -54,6 +53,8 @@
import org.jboss.ws.extensions.xop.XOPContext;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.ws.metadata.umdm.ParameterMetaData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -297,18 +298,13 @@
if (domElement == container)
return;
- String rootLocalName = domElement.getLocalName();
- String rootPrefix = domElement.getPrefix();
- String rootNS = domElement.getNamespaceURI();
- NameImpl contentRootName = new NameImpl(rootLocalName, rootPrefix, rootNS);
-
// Make sure the content root element name matches this element name
- Name name = container.getElementName();
QName qname = container.getElementQName();
+ QName contentRootName = DOMUtils.getElementQName(domElement);
boolean artificalElement = (SOAPContentElement.GENERIC_PARAM_NAME.equals(qname) ||
SOAPContentElement.GENERIC_RETURN_NAME.equals(qname));
- if (!artificalElement && !contentRootName.equals(name))
- throw new WSException("Content root name does not match element name:
" + contentRootName + " != " + name);
+ if (!artificalElement && !contentRootName.equals(qname))
+ throw new WSException("Content root name does not match element name:
" + contentRootName + " != " + qname);
// Remove all child nodes
container.removeContents();
@@ -317,11 +313,10 @@
// These need to be replaced (costly!)
if (artificalElement)
{
- QName xmlName = contentRootName.toQName();
- container.setElementQNameInternal(xmlName);
+ container.setElementQNameInternal(contentRootName);
}
- // Copy attributes
+ Document ownerDoc = container.getOwnerDocument();
DOMUtils.copyAttributes(container, domElement);
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
@@ -335,7 +330,7 @@
{
SOAPElement soapElement = soapFactory.createElement((Element)child);
container.addChildElement(soapElement);
- if (Constants.NAME_XOP_INCLUDE.equals(name) || container.isXOPParameter())
+ if (Constants.NAME_XOP_INCLUDE.equals(qname) || container.isXOPParameter())
XOPContext.inlineXOPData(soapElement);
}
else if (childType == Node.TEXT_NODE)
@@ -343,6 +338,12 @@
String nodeValue = child.getNodeValue();
container.addTextNode(nodeValue);
}
+ else if (childType == Node.COMMENT_NODE)
+ {
+ String nodeValue = child.getNodeValue();
+ Comment comment = ownerDoc.createComment(nodeValue);
+ container.appendChild(comment);
+ }
else if (childType == Node.CDATA_SECTION_NODE)
{
String nodeValue = child.getNodeValue();
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-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/common/soap/MessageFactoryTestCase.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -25,18 +25,22 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.stream.StreamSource;
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.Constants;
+import org.jboss.ws.core.jaxrpc.Style;
import org.jboss.ws.core.soap.MessageFactoryImpl;
import org.jboss.ws.core.utils.DOMUtils;
+import org.jboss.ws.core.utils.DOMWriter;
import org.w3c.dom.Element;
/**
@@ -153,7 +157,7 @@
public void testPreserveComments() throws Exception
{
String expMsg =
- "<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ns1='http://somens.org'>" +
+ "<soapenv:Envelope xmlns:ns1='http://somens.org'
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" +
" <!-- header -->" +
" <soapenv:Header>" +
" <!-- header element -->" +
@@ -169,12 +173,27 @@
" </soapenv:Body>" +
"</soapenv:Envelope>";
- MessageFactory factory = new MessageFactoryImpl();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(expMsg.getBytes());
+ // Verify that DOM parse/write do not modify the message
+ Element expEnv = DOMUtils.parse(expMsg);
+ assertEquals(expMsg, DOMWriter.printNode(expEnv, false));
+
+ doPreserveCommentsPerStyle(expMsg, Style.DOCUMENT);
+ doPreserveCommentsPerStyle(expMsg, Style.RPC);
+ doPreserveCommentsPerStyle(expMsg, null);
+ }
+
+ private void doPreserveCommentsPerStyle(String expXML, Style style) throws
IOException, SOAPException
+ {
+ MessageFactoryImpl factory = new MessageFactoryImpl();
+ factory.setStyle(style);
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(expXML.getBytes());
SOAPMessage soapMsg = factory.createMessage(null, inputStream);
- SOAPEnvelope env = soapMsg.getSOAPPart().getEnvelope();
+ SOAPEnvelope wasEnv = soapMsg.getSOAPPart().getEnvelope();
- System.out.println("FIXME: [JBWS-1511] MessageFactory does not preserve
comments");
- //assertEquals(DOMUtils.parse(expMsg), (Element)env);
+ String wasXML = DOMWriter.printNode(wasEnv, false);
+ //System.out.println(expXML);
+ //System.out.println(wasXML);
+ assertEquals(expXML, wasXML);
}
}
\ No newline at end of file
Modified:
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/marshall/MarshallTest.java
===================================================================
---
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/marshall/MarshallTest.java 2007-04-23
08:00:28 UTC (rev 2898)
+++
branches/jbossws-2.0/jbossws-tests/src/java/org/jboss/test/ws/jaxrpc/marshall/MarshallTest.java 2007-04-23
12:30:58 UTC (rev 2899)
@@ -1,24 +1,24 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
package org.jboss.test.ws.jaxrpc.marshall;
import java.math.BigDecimal;
@@ -36,7 +36,7 @@
/**
* Test standard JAX-RPC types.
- *
+ *
* @author Thomas.Diesler(a)jboss.org
* @since 15-Feb-2005
*/
@@ -227,8 +227,8 @@
{
Calendar in = new GregorianCalendar(1968, 5, 16, 14, 23, 55);
/**
- * Will be a problem where the JVM is running in a TZ which
- * has Daylight Saving Time influence. So offset the TZ to GMT.
+ * Will be a problem where the JVM is running in a TZ which has Daylight
+ * Saving Time influence. So offset the TZ to GMT.
*/
in.setTimeZone(TimeZone.getTimeZone("GMT-0"));
Calendar out = calendarTest(in);
@@ -607,6 +607,11 @@
String in = "one";
String out = stringTest(in);
assertEquals(in, out);
+
+ System.out.println("FIXME: [JBWS-1617] JAXRPC doc/literal trims empty
string");
+ //in = " ";
+ //out = stringTest(in);
+ //assertEquals(in, out);
}
public void testStringSpecialChars() throws Exception