[jboss-svn-commits] JBossWS SVN: r1166 - in branches/jbossws-1.0: . src/main/java/org/jboss/ws/addressing src/main/java/org/jboss/ws/common src/main/java/org/jboss/ws/server src/main/java/org/jboss/ws/soap src/main/java/org/jboss/ws/utils src/test/java/org/jboss/test/ws/common/soap src/test/java/org/jboss/test/ws/common/utils src/test/java/org/jboss/test/ws/jaxrpc/wsse src/test/java/org/jboss/test/ws/jaxws/wsaddressing
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 6 07:37:25 EDT 2006
Author: thomas.diesler at jboss.com
Date: 2006-10-06 07:37:06 -0400 (Fri, 06 Oct 2006)
New Revision: 1166
Modified:
branches/jbossws-1.0/
branches/jbossws-1.0/.classpath
branches/jbossws-1.0/build.xml
branches/jbossws-1.0/src/main/java/org/jboss/ws/addressing/EndpointReferenceImpl.java
branches/jbossws-1.0/src/main/java/org/jboss/ws/common/CommonClient.java
branches/jbossws-1.0/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java
branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPBodyImpl.java
branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java
branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPHeaderElementImpl.java
branches/jbossws-1.0/src/main/java/org/jboss/ws/utils/DOMWriter.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/wsse/MicrosoftInteropTestCase.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/EndpointReferenceTestCase.java
branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/SOAPAddressingPropertiesTestCase.java
Log:
[JBWS-1130] Consolidate namespace declarations
Layout code. You should use the JBossWSCodeStyle
definition in your IDE.
Property changes on: branches/jbossws-1.0
___________________________________________________________________
Name: svn:ignore
-
clipboard.xml
output
output-eclipse
thirdparty
ant.properties
version.properties.md5
+
clipboard.xml
output
output-eclipse
thirdparty
ant.properties
version.properties.md5
clipboard.txt
Modified: branches/jbossws-1.0/.classpath
===================================================================
--- branches/jbossws-1.0/.classpath 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/.classpath 2006-10-06 11:37:06 UTC (rev 1166)
@@ -3,11 +3,9 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry excluding="org/jboss/test/ws/interop/" kind="src" path="src/test/java"/>
<classpathentry kind="lib" path="thirdparty/activation.jar"/>
- <classpathentry sourcepath="D:/cvs/JBossRemoting/src/main" kind="lib" path="thirdparty/jboss-remoting.jar"/>
<classpathentry kind="lib" path="thirdparty/mailapi.jar"/>
<classpathentry kind="lib" path="thirdparty/qdox.jar"/>
<classpathentry kind="lib" path="thirdparty/servlet-api.jar"/>
- <classpathentry sourcepath="D:/java/sourceforge/wsdl4j-1_5_2jboss/src" kind="lib" path="thirdparty/wsdl4j.jar"/>
<classpathentry kind="lib" path="thirdparty/xercesImpl.jar"/>
<classpathentry kind="lib" path="thirdparty/xml-apis.jar"/>
<classpathentry kind="lib" path="thirdparty/xmlsec.jar"/>
@@ -25,7 +23,11 @@
<classpathentry kind="lib" path="thirdparty/stax-api-1.0.jar"/>
<classpathentry kind="lib" path="thirdparty/wstx-lgpl-2.0.6.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/jboss-4.0.x"/>
- <classpathentry sourcepath="D:/cvs/jboss-branch/jboss-4.0.x/common/src/main" kind="lib" path="thirdparty/jboss-common.jar"/>
<classpathentry kind="lib" path="thirdparty/ant.jar"/>
+ <classpathentry kind="lib" path="thirdparty/jboss.jar"/>
+ <classpathentry kind="lib" path="thirdparty/jboss-j2ee.jar"/>
+ <classpathentry kind="lib" path="thirdparty/jboss-jmx.jar"/>
+ <classpathentry kind="lib" path="thirdparty/jbosssx.jar"/>
+ <classpathentry kind="lib" path="thirdparty/jboss-system.jar"/>
<classpathentry kind="output" path="output-eclipse"/>
</classpath>
Modified: branches/jbossws-1.0/build.xml
===================================================================
--- branches/jbossws-1.0/build.xml 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/build.xml 2006-10-06 11:37:06 UTC (rev 1166)
@@ -705,8 +705,8 @@
<!-- Build the src dist -->
<target name="build-src-dist" description="Build the source distribution">
- <mkdir dir="${build.src.dist}/jbossws-${version.id}"/>
- <copy todir="${build.src.dist}/jbossws-${version.id}">
+ <mkdir dir="${build.src.dist}/jbossws-${version.id}-src"/>
+ <copy todir="${build.src.dist}/jbossws-${version.id}-src">
<fileset dir="${basedir}">
<include name="ant.properties.example"/>
<include name="version.properties"/>
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/addressing/EndpointReferenceImpl.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/addressing/EndpointReferenceImpl.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/addressing/EndpointReferenceImpl.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -24,6 +24,7 @@
//$Id$
import java.io.IOException;
+import java.io.StringWriter;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
@@ -38,10 +39,10 @@
import javax.xml.ws.addressing.ReferenceParameters;
import javax.xml.ws.addressing.soap.SOAPAddressingBuilder;
+import org.jboss.ws.WSException;
+import org.jboss.ws.addressing.soap.SOAPAddressingBuilderImpl;
import org.jboss.ws.utils.DOMUtils;
import org.jboss.ws.utils.DOMWriter;
-import org.jboss.ws.WSException;
-import org.jboss.ws.addressing.soap.SOAPAddressingBuilderImpl;
import org.w3c.dom.Element;
/**
@@ -267,7 +268,10 @@
{
if (obj instanceof Element)
{
- String xmlFragment = DOMWriter.printNode((Element)obj, false);
+ StringWriter strwr = new StringWriter();
+ DOMWriter domWriter = new DOMWriter(strwr).setCompleteNamespaces(false);
+ domWriter.print((Element)obj);
+ String xmlFragment = strwr.toString();
xmlBuffer.append(xmlFragment);
}
else if (obj instanceof String)
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/common/CommonClient.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/common/CommonClient.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/common/CommonClient.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -315,14 +315,6 @@
handlerPass = handlerPass && callResponseHandlerChain(portName, HandlerType.ENDPOINT);
handlerPass = handlerPass && callResponseHandlerChain(portName, HandlerType.PRE);
- // Check if protocol handlers modified the payload
- if (((SOAPBodyImpl)reqMessage.getSOAPBody()).isModifiedFromSource())
- {
- log.debug("Handler modified body payload, unbind message again");
- SOAPMessage resMessage = msgContext.getSOAPMessage();
- binding.unbindResponseMessage(opMetaData, resMessage, epInv, unboundHeaders);
- }
-
retObj = syncOutputParams(inputParams, epInv);
}
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/server/AbstractServiceEndpointInvoker.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -143,13 +143,6 @@
handlersPass = handlersPass && callRequestHandlerChain(seInfo, HandlerType.ENDPOINT);
handlersPass = handlersPass && callRequestHandlerChain(seInfo, HandlerType.POST);
- // Check if protocol handlers modified the payload
- if (((SOAPBodyImpl)reqMessage.getSOAPBody()).isModifiedFromSource())
- {
- log.debug("Handler modified body payload, unbind message again");
- epInv = binding.unbindRequestMessage(opMetaData, reqMessage);
- }
-
if (handlersPass)
{
// Invoke the service endpoint
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPBodyImpl.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPBodyImpl.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPBodyImpl.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -23,11 +23,6 @@
// $Id$
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.Writer;
import java.util.Iterator;
import java.util.Locale;
@@ -37,24 +32,14 @@
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamSource;
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
-import org.jboss.ws.WSException;
-import org.jboss.ws.common.CommonMessageContext;
-import org.jboss.ws.metadata.UnifiedMetaData;
-import org.jboss.ws.utils.DOMUtils;
-import org.jboss.ws.utils.DOMWriter;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
/**
* An object that represents the contents of the SOAP body element in a SOAP message.
@@ -70,44 +55,15 @@
// provide logging
private static Logger log = Logger.getLogger(SOAPBodyImpl.class);
- // Generic JAXWS payload
- private Source payload;
- private boolean isDOMValid = true;
- private boolean isModifiedFromSource;
-
public SOAPBodyImpl(String prefix, String namespace)
{
super("Body", prefix, namespace);
}
- public boolean isDOMValid()
- {
- return isDOMValid;
- }
-
- public boolean isModifiedFromSource()
- {
- return isModifiedFromSource;
- }
-
- public Source getPayload()
- {
- return payload;
- }
-
- public void setPayload(Source payload)
- {
- log.debug("setPayload: " + payload.getClass().getName());
- removeContents();
- this.payload = payload;
- this.isDOMValid = false;
- }
-
/** Convert the child into a SOAPBodyElement */
public SOAPElement addChildElement(SOAPElement child) throws SOAPException
{
log.trace("addChildElement: " + child.getElementName());
- expandToDOM();
if ((child instanceof SOAPBodyElement) == false)
child = convertToBodyElement(child);
@@ -118,7 +74,6 @@
public SOAPBodyElement addBodyElement(Name name) throws SOAPException
{
log.trace("addBodyElement: " + name);
- expandToDOM();
SOAPBodyElement child = new SOAPBodyElementDoc(name);
return (SOAPBodyElement)addChildElement(child);
}
@@ -126,7 +81,6 @@
public SOAPBodyElement addDocument(Document doc) throws SOAPException
{
log.trace("addDocument");
- expandToDOM();
Element rootElement = doc.getDocumentElement();
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
SOAPElementImpl soapElement = soapFactory.createElement(rootElement, true);
@@ -136,7 +90,6 @@
public SOAPFault addFault() throws SOAPException
{
log.trace("addFault");
- expandToDOM();
if (hasFault())
throw new SOAPException("A SOAPBody may contain at most one SOAPFault child element");
@@ -146,7 +99,6 @@
public SOAPFault addFault(Name faultCode, String faultString) throws SOAPException
{
log.trace("addFault");
- expandToDOM();
if (hasFault())
throw new SOAPException("A SOAPBody may contain at most one SOAPFault child element");
@@ -160,7 +112,6 @@
public SOAPFault addFault(Name faultCode, String faultString, Locale locale) throws SOAPException
{
log.trace("addFault");
- expandToDOM();
if (hasFault())
throw new SOAPException("A SOAPBody may contain at most one SOAPFault child element");
@@ -174,7 +125,6 @@
public SOAPFault getFault()
{
log.trace("getFault");
- expandToDOM();
Iterator it = getChildElements(new NameImpl("Fault", Constants.PREFIX_ENV, getSOAPEnvelope().getNamespaceURI()));
return (it.hasNext() ? (SOAPFault)it.next() : null);
}
@@ -182,14 +132,12 @@
public boolean hasFault()
{
log.trace("hasFault");
- expandToDOM();
return getChildElements(Constants.SOAP11_FAULT).hasNext();
}
public Node appendChild(Node newChild) throws DOMException
{
log.trace("appendChild: " + newChild.getNodeName());
- expandToDOM();
Node retNode;
if (!(newChild instanceof SOAPBodyElement || newChild instanceof DocumentFragment))
{
@@ -202,7 +150,6 @@
public Node insertBefore(Node newChild, Node refChild) throws DOMException
{
log.trace("insertBefore: " + newChild.getNodeName());
- expandToDOM();
if (!(newChild instanceof SOAPBodyElement || newChild instanceof DocumentFragment))
newChild = convertToBodyElement(newChild);
@@ -212,7 +159,6 @@
public Node replaceChild(Node newChild, Node oldChild) throws DOMException
{
log.trace("replaceChild: " + newChild.getNodeName());
- expandToDOM();
if (!(newChild instanceof SOAPBodyElement || newChild instanceof DocumentFragment))
{
newChild = convertToBodyElement(newChild);
@@ -221,48 +167,6 @@
return super.replaceChild(newChild, oldChild);
}
- public Iterator getChildElements()
- {
- log.trace("getChildElements");
- expandToDOM();
- return super.getChildElements();
- }
-
- public Iterator getChildElements(Name name)
- {
- log.trace("getChildElements: " + name);
- expandToDOM();
- return super.getChildElements(name);
- }
-
- public NodeList getChildNodes()
- {
- log.trace("getChildNodes");
- expandToDOM();
- return super.getChildNodes();
- }
-
- public Node getFirstChild()
- {
- log.trace("getFirstChild");
- expandToDOM();
- return super.getFirstChild();
- }
-
- public Node getLastChild()
- {
- log.trace("getLastChild");
- expandToDOM();
- return super.getLastChild();
- }
-
- public boolean hasChildNodes()
- {
- log.trace("hasChildNodes");
- expandToDOM();
- return super.hasChildNodes();
- }
-
private SOAPBodyElementDoc convertToBodyElement(Node node)
{
if (!(node instanceof SOAPElementImpl))
@@ -272,107 +176,4 @@
element.detachNode();
return new SOAPBodyElementDoc(element);
}
-
- private void expandToDOM()
- {
- if (isDOMValid == false)
- {
- // DOM expansion should only happen when a handler accesses the DOM API.
- // We do not allow DOM expansion on a dev release.
- CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
- if (msgContext != null && UnifiedMetaData.isDevRelease())
- {
- Boolean allowExpand = (Boolean)msgContext.getProperty(CommonMessageContext.ALLOW_EXPAND_TO_DOM);
- if (Boolean.TRUE.equals(allowExpand) == false)
- throw new WSException("Expanding content element to DOM");
- }
-
- log.trace("BEGIN expandToDOM");
-
- isDOMValid = true;
- try
- {
- Element child = getBodyElementFromSource();
- SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
- addChildElement(soapFactory.createElement(child, true));
- payload = null;
- }
- catch (RuntimeException rte)
- {
- isDOMValid = false;
- throw rte;
- }
- catch (Exception ex)
- {
- isDOMValid = false;
- throw new WSException("Cannot expand to DOM" + ex);
- }
- finally
- {
- isModifiedFromSource = true;
- log.trace("END expandToDOM");
- }
- }
- }
-
- private Element getBodyElementFromSource()
- {
- Element child = null;
- try
- {
- if (payload instanceof StreamSource)
- {
- StreamSource streamSource = (StreamSource)payload;
-
- InputStream ins = streamSource.getInputStream();
- if (ins != null)
- {
- child = DOMUtils.parse(ins);
- }
- else
- {
- Reader reader = streamSource.getReader();
- child = DOMUtils.parse(new InputSource(reader));
- }
-
- // reset the excausted input stream
- String xmlStr = DOMWriter.printNode(child, false);
- payload = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes()));
- }
- else if (payload instanceof DOMSource)
- {
- DOMSource domSource = (DOMSource)payload;
- child = (Element)domSource.getNode();
- }
- else
- {
- throw new WSException("Source type not implemented: " + payload.getClass().getName());
- }
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- throw new WSException("Cannot get root element from Source" + ex);
- }
- return child;
- }
-
- @Override
- public void writeElementContent(Writer writer) throws IOException
- {
- if (payload != null)
- {
- Element child = getBodyElementFromSource();
- String xmlPayload = DOMWriter.printNode(child, false);
- log.debug("Content from payload: " + xmlPayload);
- writer.write(xmlPayload);
- }
- else
- {
- super.writeElementContent(writer);
- }
- }
}
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPContentElement.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -126,7 +126,7 @@
{
return getParamMetaData().getJavaType();
}
-
+
public boolean isDOMValid()
{
return isDOMValid;
@@ -972,25 +972,17 @@
}
}
+ public void writeElement(Writer writer) throws IOException
+ {
+ handleMTOMTransitions();
- public void writeElement(Writer writer) {
- try
+ if (isDOMValid)
{
- handleMTOMTransitions();
-
- if(isDOMValid)
- {
- new DOMWriter(writer).print(this);
- }
- else
- {
- writer.write( getXMLFragment() );
- }
-
+ new DOMWriter(writer).print(this);
}
- catch (Exception e)
+ else
{
- throw new WSException("Failed to write SOAPContentElement ", e);
+ writer.write(getXMLFragment());
}
}
@@ -1006,11 +998,12 @@
* it's needs to be decided wether or not the <code>xop:Include</code> should be restored.
* This as well depends upon the message context property.
*/
- public void handleMTOMTransitions() {
+ public void handleMTOMTransitions()
+ {
boolean mtomEnabled = isXOPParameter() && XOPContext.isMTOMEnabled();
- if( paramMetaData != null && mtomEnabled == false )
+ if (paramMetaData != null && mtomEnabled == false)
{
// If MTOM is disabled, we force dom expansion.
// This will inline any XOP include element
@@ -1022,7 +1015,7 @@
msgContext.setProperty(CommonMessageContext.ALLOW_EXPAND_TO_DOM, Boolean.TRUE);
expandToDOM();
}
- else if(isDOMValid && mtomEnabled )
+ else if (isDOMValid && mtomEnabled)
{
// When the DOM representation is valid,
// but MTOM is enabled we need to convert the inlined
@@ -1037,7 +1030,9 @@
{
return paramMetaData != null && paramMetaData.isXOP();
}
- public void accept(SAAJVisitor visitor) {
+
+ public void accept(SAAJVisitor visitor)
+ {
visitor.visitSOAPContentElement(this);
}
}
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPHeaderElementImpl.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPHeaderElementImpl.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPHeaderElementImpl.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -21,8 +21,16 @@
*/
package org.jboss.ws.soap;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
@@ -87,4 +95,48 @@
super.setParentElement(parent);
}
+
+ @Override
+ public void writeElement(Writer writer) throws IOException
+ {
+ StringWriter strwr = new StringWriter(256);
+ super.writeElement(strwr);
+
+ SOAPHeader soapHeader = (SOAPHeader)getParentElement();
+ SOAPEnvelope soapEnvelope = (SOAPEnvelope)soapHeader.getParentElement();
+
+ // Find known namespace declarations
+ List<String> knownNamespaces = new ArrayList<String>();
+ Iterator prefixes = soapEnvelope.getNamespacePrefixes();
+ while (prefixes.hasNext())
+ {
+ String prefix = (String)prefixes.next();
+ String nsURI = soapEnvelope.getNamespaceURI(prefix);
+ String xmlns = " xmlns:" + prefix + "='" + nsURI + "'";
+ knownNamespaces.add(xmlns);
+ }
+ prefixes = soapHeader.getNamespacePrefixes();
+ while (prefixes.hasNext())
+ {
+ String prefix = (String)prefixes.next();
+ String nsURI = soapHeader.getNamespaceURI(prefix);
+ String xmlns = " xmlns:" + prefix + "='" + nsURI + "'";
+ knownNamespaces.add(xmlns);
+ }
+
+ // Remove known namespace declarations
+ String xmlFragment = strwr.toString();
+ for (String xmlns : knownNamespaces)
+ {
+ int start = xmlFragment.indexOf(xmlns);
+ while (start > 0)
+ {
+ int end = start + xmlns.length();
+ xmlFragment = xmlFragment.substring(0, start) + xmlFragment.substring(end);
+ start = xmlFragment.indexOf(xmlns);
+ }
+ }
+
+ writer.write(xmlFragment);
+ }
}
Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/utils/DOMWriter.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/utils/DOMWriter.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/utils/DOMWriter.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -98,7 +98,9 @@
private boolean wroteXMLDeclaration;
// The node that started the write
private Node rootNode;
-
+ // True if we want namespace completion
+ private boolean completeNamespaces = true;
+
public DOMWriter(Writer w)
{
this.out = new PrintWriter(w);
@@ -157,6 +159,17 @@
return this;
}
+ /**
+ * Set wheter subelements should have their namespaces completed.
+ * Setting this to false may lead to invalid XML fragments.
+ * The default is true.
+ */
+ public DOMWriter setCompleteNamespaces(boolean complete)
+ {
+ this.completeNamespaces = complete;
+ return this;
+ }
+
public boolean isPrettyprint()
{
return prettyprint;
@@ -232,7 +245,7 @@
break;
}
- // print element with attributes
+ // print element with attributes
case Node.ELEMENT_NODE:
{
Element element = (Element)node;
@@ -247,7 +260,7 @@
out.print('<');
out.print(nodeName);
-
+
Map nsMap = new HashMap();
String elPrefix = node.getPrefix();
if (elPrefix != null)
@@ -255,7 +268,7 @@
String nsURI = getNamespaceURI(elPrefix, element, rootNode);
nsMap.put(elPrefix, nsURI);
}
-
+
Attr attrs[] = sortAttributes(node.getAttributes());
for (int i = 0; i < attrs.length; i++)
{
@@ -263,26 +276,29 @@
String atPrefix = attr.getPrefix();
String atName = attr.getNodeName();
String atValue = normalize(attr.getNodeValue());
-
+
if (atPrefix != null && (atPrefix.equals("xmlns") || atPrefix.equals("xml")) == false)
{
String nsURI = getNamespaceURI(atPrefix, element, rootNode);
nsMap.put(atPrefix, nsURI);
}
-
+
out.print(" " + atName + "='" + atValue + "'");
}
-
+
// Add missing namespace declaration
- Iterator itPrefix = nsMap.keySet().iterator();
- while (itPrefix.hasNext())
+ if (completeNamespaces)
{
- String prefix = (String)itPrefix.next();
- String nsURI = (String)nsMap.get(prefix);
- if (nsURI == null)
+ Iterator itPrefix = nsMap.keySet().iterator();
+ while (itPrefix.hasNext())
{
- nsURI = getNamespaceURI(prefix, element, null);
- out.print(" xmlns:" + prefix + "='" + nsURI + "'");
+ String prefix = (String)itPrefix.next();
+ String nsURI = (String)nsMap.get(prefix);
+ if (nsURI == null)
+ {
+ nsURI = getNamespaceURI(prefix, element, null);
+ out.print(" xmlns:" + prefix + "='" + nsURI + "'");
+ }
}
}
Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/soap/SOAPHeaderElementTestCase.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -22,6 +22,7 @@
package org.jboss.test.ws.common.soap;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
@@ -33,6 +34,7 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.soap.MessageFactoryImpl;
import org.jboss.ws.soap.NameImpl;
+import org.jboss.ws.utils.DOMUtils;
/**
* Test the SOAPHeaderElement
@@ -97,18 +99,15 @@
*/
public void testSetMustUnderstand() throws Exception
{
- String envStr =
+ String expEnv =
"<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
- " <env:Header>" +
- " <ns2:Bar xmlns:ns2='http://org.jboss.ws/header2' env:mustUnderstand='1'>SomeOtherValue</ns2:Bar>" +
- " </env:Header>" +
- " <env:Body/>" +
+ "<env:Header>" +
+ "<ns2:Bar xmlns:ns2='http://org.jboss.ws/header2' env:mustUnderstand='1'>SomeOtherValue</ns2:Bar>" +
+ "</env:Header>" +
+ "<env:Body/>" +
"</env:Envelope>";
MessageFactory factory = new MessageFactoryImpl();
- SOAPMessage expSoapMessage = factory.createMessage(null, new ByteArrayInputStream(envStr.getBytes()));
- SOAPEnvelope expSoapEnv = expSoapMessage.getSOAPPart().getEnvelope();
-
SOAPMessage soapMessage = factory.createMessage();
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
@@ -118,7 +117,10 @@
soapHeaderElement.setMustUnderstand(true);
soapHeaderElement.addTextNode("SomeOtherValue");
- System.out.println("FIXME: JBWS-1130");
- // assertEquals(expSoapEnv, soapEnv);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ soapMessage.writeTo(baos);
+ String wasEnv = new String(baos.toByteArray());
+
+ assertEquals(DOMUtils.parse(expEnv), DOMUtils.parse(wasEnv));
}
}
Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/common/utils/DOMWriterTestCase.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -22,9 +22,9 @@
package org.jboss.test.ws.common.utils;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import org.jboss.test.ws.JBossWSTest;
@@ -201,7 +201,7 @@
public void testEnvelopeWriter() throws Exception
{
- String xmlEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>"
+ String expEnv = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>"
+ " <env:Header xmlns:wsa='http://www.w3.org/2005/08/addressing'>"
+ " <wsa:To>http://fabrikam123.example/Purchasing</wsa:To>"
+ " <wsa:ReplyTo>"
@@ -217,10 +217,12 @@
+ "</env:Envelope>";
MessageFactory factory = MessageFactory.newInstance();
- SOAPMessage msgOut = factory.createMessage(null, new ByteArrayInputStream(xmlEnv.getBytes()));
- SOAPEnvelope soapEnv = msgOut.getSOAPPart().getEnvelope();
+ SOAPMessage soapMessage = factory.createMessage(null, new ByteArrayInputStream(expEnv.getBytes()));
- System.out.println("FIXME: JBWS-1130");
- //assertEquals(DOMUtils.parse(xmlEnv), soapEnv);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ soapMessage.writeTo(baos);
+ String wasEnv = new String(baos.toByteArray());
+
+ assertEquals(DOMUtils.parse(expEnv), DOMUtils.parse(wasEnv));
}
}
Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/wsse/MicrosoftInteropTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/wsse/MicrosoftInteropTestCase.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxrpc/wsse/MicrosoftInteropTestCase.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.jaxrpc.wsse;
+import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Calendar;
@@ -32,7 +33,7 @@
import org.jboss.test.ws.JBossWSTest;
import org.jboss.ws.soap.MessageFactoryImpl;
-import org.jboss.ws.utils.DOMWriter;
+import org.jboss.ws.utils.DOMUtils;
import org.jboss.ws.wsse.Constants;
import org.jboss.ws.wsse.SecurityDecoder;
import org.jboss.ws.wsse.SecurityStore;
@@ -52,7 +53,7 @@
/** Test that we can build an envelope from InputStream */
public void testMicrosoftRequest() throws Exception
{
- String envStr =
+ String expEnv =
"<?xml version='1.0' encoding='UTF-8'?>" +
"<soap:Envelope" +
" xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
@@ -65,7 +66,7 @@
" <wsa:ReplyTo>" +
" <wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>" +
" </wsa:ReplyTo>" +
- " <wsa:To>http://draught:8081/jaxrpc-jaxrpc-jse</wsa:To>" +
+ " <wsa:To>http://draught:8081/jbossws-jaxrpc-jse</wsa:To>" +
" </soap:Header>" +
" <soap:Body>" +
" <echoString xmlns='http://org.jboss.ws/jaxrpc/types'>" +
@@ -79,8 +80,7 @@
MessageFactory factory = new MessageFactoryImpl();
SOAPMessage soapMsg = factory.createMessage(null, inputStream);
- SOAPEnvelope env = soapMsg.getSOAPPart().getEnvelope();
- Document doc = env.getOwnerDocument();
+ SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
// The Microsoft WSE message is timestamp protected like so:
// <wsu:Timestamp wsu:Id="Timestamp-9e3e6632-f2a1-4b26-a682-9301a75003a7">
@@ -97,16 +97,16 @@
cal.set(Calendar.SECOND, 25);
SecurityDecoder decoder = new SecurityDecoder(new SecurityStore(), cal);
- decoder.decode(doc);
+ decoder.decode(soapEnv.getOwnerDocument());
decoder.complete();
- cleanupWsuIds(doc.getDocumentElement());
+ cleanupWsuIds(soapEnv);
- String decodedString = DOMWriter.printNode(doc, true);
- log.debug("Decoded message:" + decodedString);
-
- System.out.println("FIXME: JBWS-1130");
- // assertEquals(DOMUtils.parse(envStr), doc.getDocumentElement());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ soapMsg.writeTo(baos);
+ String wasEnv = new String(baos.toByteArray());
+
+ assertEquals(DOMUtils.parse(expEnv), DOMUtils.parse(wasEnv));
}
// WS-Security leaves wsu:id attributes arround on elements which are not cleaned
Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/EndpointReferenceTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/EndpointReferenceTestCase.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/EndpointReferenceTestCase.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -63,7 +63,6 @@
EndpointReferenceImpl epr = new EndpointReferenceImpl(inElement);
Element outElement = epr.toElement();
- System.out.println("FIXME: JBWS-1130");
- //assertEquals(inElement, outElement);
+ assertEquals(inElement, outElement);
}
}
Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/SOAPAddressingPropertiesTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/SOAPAddressingPropertiesTestCase.java 2006-10-06 11:23:30 UTC (rev 1165)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/jaxws/wsaddressing/SOAPAddressingPropertiesTestCase.java 2006-10-06 11:37:06 UTC (rev 1166)
@@ -25,16 +25,17 @@
// Exp $
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.net.URI;
import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.addressing.AddressingBuilder;
import javax.xml.ws.addressing.soap.SOAPAddressingBuilder;
import javax.xml.ws.addressing.soap.SOAPAddressingProperties;
import org.jboss.test.ws.JBossWSTest;
+import org.jboss.util.xml.DOMUtils;
/**
* Test the SOAPAddressingProperties
@@ -94,15 +95,19 @@
public void testWriteHeaders() throws Exception
{
MessageFactory factory = MessageFactory.newInstance();
- SOAPMessage soapMessage = factory.createMessage();
- addrProps.writeHeaders(soapMessage);
- SOAPEnvelope wasEnv = soapMessage.getSOAPPart().getEnvelope();
+ SOAPMessage wasMsg = factory.createMessage();
+ addrProps.writeHeaders(wasMsg);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ wasMsg.writeTo(baos);
+ String wasEnv = new String(baos.toByteArray());
- SOAPMessage msgOut = factory.createMessage(null, new ByteArrayInputStream(reqEnvStr.getBytes()));
- SOAPEnvelope expEnv = msgOut.getSOAPPart().getEnvelope();
+ SOAPMessage expMsg = factory.createMessage(null, new ByteArrayInputStream(reqEnvStr.getBytes()));
+ baos = new ByteArrayOutputStream();
+ expMsg.writeTo(baos);
+ String expEnv = new String(baos.toByteArray());
- System.out.println("FIXME: JBWS-1130");
- //assertEquals(expEnv, wasEnv);
+ assertEquals(DOMUtils.parse(expEnv), DOMUtils.parse(wasEnv));
}
public void testReplyToHeaders() throws Exception
@@ -113,14 +118,18 @@
replyProps.setAction(addrBuilder.newURI("http://fabrikam123.example/ReplyPO"));
MessageFactory factory = MessageFactory.newInstance();
- SOAPMessage soapMessage = factory.createMessage();
- replyProps.writeHeaders(soapMessage);
- SOAPEnvelope wasEnv = soapMessage.getSOAPPart().getEnvelope();
+ SOAPMessage wasMsg = factory.createMessage();
+ replyProps.writeHeaders(wasMsg);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ wasMsg.writeTo(baos);
+ String wasEnv = new String(baos.toByteArray());
- SOAPMessage msgOut = factory.createMessage(null, new ByteArrayInputStream(resEnvStr.getBytes()));
- SOAPEnvelope expEnv = msgOut.getSOAPPart().getEnvelope();
-
- System.out.println("FIXME: JBWS-1130");
- //assertEquals(expEnv, wasEnv);
+ SOAPMessage expMsg = factory.createMessage(null, new ByteArrayInputStream(resEnvStr.getBytes()));
+ baos = new ByteArrayOutputStream();
+ expMsg.writeTo(baos);
+ String expEnv = new String(baos.toByteArray());
+
+ assertEquals(DOMUtils.parse(expEnv), DOMUtils.parse(wasEnv));
}
}
More information about the jboss-svn-commits
mailing list