Author: alessio.soldano(a)jboss.com
Date: 2011-04-14 11:33:37 -0400 (Thu, 14 Apr 2011)
New Revision: 14096
Added:
shared-testsuite/trunk/src/test/java/org/jboss/test/helper/
shared-testsuite/trunk/src/test/java/org/jboss/test/helper/DOMWriter.java
Removed:
shared-testsuite/trunk/src/test/java/org/jboss/test/helper/DOMWriter.java
Modified:
shared-testsuite/trunk/
shared-testsuite/trunk/src/test/ant-import/build-jars-jaxws.xml
shared-testsuite/trunk/src/test/ant-import/build-samples-jaxws.xml
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestCase.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestServiceBean.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1807/ProviderImpl.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1815/JBWS1815TestCase.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws2960/JBWS2960TestCase.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/namespace/CustomHandler.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/AddressingPort.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/ServerHandler.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointEJB.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointJSE.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/LogicalSourceHandler.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/ProviderBeanPayload.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/logicalhandler/LogicalSourceHandler.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java
Log:
[JBWS-3224][JBWS-3265] Isolate deployment classloader from ws server integration
Property changes on: shared-testsuite/trunk
___________________________________________________________________
Added: svn:mergeinfo
+ /shared-testsuite/branches/asoldano:14040-14045
Modified: shared-testsuite/trunk/src/test/ant-import/build-jars-jaxws.xml
===================================================================
--- shared-testsuite/trunk/src/test/ant-import/build-jars-jaxws.xml 2011-04-14 15:30:44
UTC (rev 14095)
+++ shared-testsuite/trunk/src/test/ant-import/build-jars-jaxws.xml 2011-04-14 15:33:37
UTC (rev 14096)
@@ -378,6 +378,7 @@
<war warfile="${tests.output.dir}/test-libs/jaxws-jbws1807.war"
webxml="${tests.output.dir}/test-resources/jaxws/jbws1807/WEB-INF/web.xml">
<classes dir="${tests.output.dir}/test-classes">
<include name="org/jboss/test/ws/jaxws/jbws1807/ProviderImpl.class"
/>
+ <include name="org/jboss/test/helper/DOMWriter.class" />
</classes>
<webinf
dir="${tests.output.dir}/test-resources/jaxws/jbws1807/WEB-INF">
<include name="wsdl/**" />
@@ -1083,6 +1084,7 @@
<include name="org/jboss/test/ws/jaxws/namespace/EndpointBean.class"
/>
<include
name="org/jboss/test/ws/jaxws/namespace/EndpointInterface.class" />
<include name="org/jboss/test/ws/jaxws/namespace/*.xml" />
+ <include name="org/jboss/test/helper/DOMWriter.class" />
</classes>
<webinf
dir="${tests.output.dir}/test-resources/jaxws/namespace/WEB-INF">
<include name="jboss-web.xml" />
Modified: shared-testsuite/trunk/src/test/ant-import/build-samples-jaxws.xml
===================================================================
--- shared-testsuite/trunk/src/test/ant-import/build-samples-jaxws.xml 2011-04-14 15:30:44
UTC (rev 14095)
+++ shared-testsuite/trunk/src/test/ant-import/build-samples-jaxws.xml 2011-04-14 15:33:37
UTC (rev 14096)
@@ -175,6 +175,9 @@
<include
name="org/jboss/test/ws/jaxws/samples/logicalhandler/ObjectFactory.class"/>
<include
name="org/jboss/test/ws/jaxws/samples/logicalhandler/jaxws-server-jaxb-handlers.xml"/>
</classes>
+ <manifest>
+ <attribute name="Dependencies" value="com.sun.xml.bind export
services"/>
+ </manifest>
</war>
<!-- jaxws-samples-oneway -->
Deleted: shared-testsuite/trunk/src/test/java/org/jboss/test/helper/DOMWriter.java
===================================================================
---
shared-testsuite/branches/asoldano/src/test/java/org/jboss/test/helper/DOMWriter.java 2011-04-08
15:52:49 UTC (rev 14045)
+++ shared-testsuite/trunk/src/test/java/org/jboss/test/helper/DOMWriter.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -1,671 +0,0 @@
-/*
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (
http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache
Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact apache(a)apache.org.
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <
http://www.apache.org/>.
- */
-package org.jboss.test.helper;
-
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * Traverse a DOM tree in order to print a document that is parsed.
- *
- * @author Andy Clark, IBM
- * @author Thomas.Diesler(a)jboss.org
- * @author <a href="mailto:mvecera@redhat.com">Martin Vecera</a>
- * @author <a href="mailto:alessio.soldano@jboss.com">Alessio
Soldano</a>
- */
-@SuppressWarnings("unchecked")
-public class DOMWriter
-{
- private static final Pattern PATTERN =
Pattern.compile("[&<>'\"\r\n]");
- // Print writer
- private PrintWriter out;
- // True, if canonical output
- private boolean canonical;
- // True, if pretty printing should be used
- private boolean prettyprint;
- // True, if the XML declaration should be written
- private boolean writeXMLDeclaration;
- // True, if whitespace should be ignored
- private boolean ignoreWhitespace;
- // Explicit character set encoding
- private String charsetName;
- // indent for the pretty printer
- private int prettyIndent;
- // True, if the XML declaration has been written
- private boolean wroteXMLDeclaration;
- // The node that started the write
- private Node rootNode;
- // True if we want namespace completion
- private boolean completeNamespaces = true;
- // The current default namespace
- private String currentDefaultNamespace;
-
- public DOMWriter(Writer w)
- {
- this.out = new PrintWriter(w);
- }
-
- public DOMWriter(Writer w, String charsetName)
- {
- this.out = new PrintWriter(w);
- this.charsetName = charsetName;
- this.writeXMLDeclaration = true;
- }
-
- public DOMWriter(OutputStream stream)
- {
- try
- {
- this.out = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
- }
- catch (UnsupportedEncodingException e)
- {
- // ignore, UTF-8 should be available
- }
- }
-
- public DOMWriter(OutputStream stream, String charsetName)
- {
- try
- {
- this.out = new PrintWriter(new OutputStreamWriter(stream, charsetName));
- this.charsetName = charsetName;
- this.writeXMLDeclaration = true;
- }
- catch (UnsupportedEncodingException e)
- {
- throw new IllegalArgumentException("Unsupported encoding: " +
charsetName);
- }
- }
-
- /**
- * Print a node with explicit prettyprinting.
- * The defaults for all other DOMWriter properties apply.
- *
- */
- public static String printNode(Node node, boolean prettyprint)
- {
- StringWriter strw = new StringWriter();
- new DOMWriter(strw).setPrettyprint(prettyprint).print(node);
- return strw.toString();
- }
-
- public boolean isCanonical()
- {
- return canonical;
- }
-
- /**
- * Set wheter entities should appear in their canonical form.
- * The default is false.
- */
- public DOMWriter setCanonical(boolean canonical)
- {
- this.canonical = canonical;
- return this;
- }
-
- public boolean isIgnoreWhitespace()
- {
- return ignoreWhitespace;
- }
-
- /**
- * Set whether whitespace should be ignored.
- * The default is false.
- */
- public DOMWriter setIgnoreWhitespace(boolean ignoreWhitespace)
- {
- this.ignoreWhitespace = ignoreWhitespace;
- 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;
- }
-
- /**
- * Set wheter element should be indented.
- * The default is false.
- */
- public DOMWriter setPrettyprint(boolean prettyprint)
- {
- this.prettyprint = prettyprint;
- return this;
- }
-
- public boolean isWriteXMLDeclaration()
- {
- return writeXMLDeclaration;
- }
-
- /**
- * Set wheter the XML declaration should be written.
- * The default is false.
- */
- public DOMWriter setWriteXMLDeclaration(boolean flag)
- {
- this.writeXMLDeclaration = flag;
- return this;
- }
-
- public void print(Node node)
- {
- if (prettyprint && ignoreWhitespace)
- throw new IllegalStateException("Cannot pretty print and ignore
whitespace");
-
- rootNode = node;
- printInternal(node, false);
- }
-
- private void printInternal(Node node, boolean indentEndMarker)
- {
- // is there anything to do?
- if (node == null)
- {
- return;
- }
-
- // JBAS-2117 - Don't skip the DOCUMENT_NODE
- // if (node instanceof Document) node = ((Document)node).getDocumentElement();
-
- if (wroteXMLDeclaration == false && writeXMLDeclaration == true &&
canonical == false)
- {
- out.print("<?xml version='1.0'");
- if (charsetName != null)
- out.print(" encoding='" + charsetName + "'");
-
- out.print("?>");
- if (prettyprint)
- out.println();
-
- wroteXMLDeclaration = true;
- }
-
- int type = node.getNodeType();
- boolean hasChildNodes = node.getChildNodes().getLength() > 0;
-
- String nodeName = node.getNodeName();
- switch (type)
- {
- // print document
- case Node.DOCUMENT_NODE:
- {
- NodeList children = node.getChildNodes();
- int len = children.getLength();
- for (int iChild = 0; iChild < len; iChild++)
- {
- printInternal(children.item(iChild), false);
- }
- out.flush();
- break;
- }
-
- // print element with attributes
- case Node.ELEMENT_NODE:
- {
- Element element = (Element)node;
- if (prettyprint)
- {
- for (int i = 0; i < prettyIndent; i++)
- {
- out.print(' ');
- }
- prettyIndent++;
- }
-
- out.print('<');
- out.print(nodeName);
-
- Map nsMap = new HashMap();
- String elPrefix = node.getPrefix();
- String elNamespaceURI = node.getNamespaceURI();
- if (elPrefix != null)
- {
- String nsURI = getNamespaceURI(elPrefix, element, rootNode);
- nsMap.put(elPrefix, nsURI);
- }
-
- Attr attrs[] = sortAttributes(node.getAttributes());
- for (int i = 0; i < attrs.length; i++)
- {
- Attr attr = attrs[i];
- String atPrefix = attr.getPrefix();
- String atName = attr.getNodeName();
- String atValue = normalize(attr.getNodeValue(), canonical);
-
- if (atName.equals("xmlns"))
- currentDefaultNamespace = atValue;
-
- if (atPrefix != null && !atPrefix.equals("xmlns")
&& !atPrefix.equals("xml"))
- {
- String nsURI = getNamespaceURI(atPrefix, element, rootNode);
- nsMap.put(atPrefix, nsURI);
- // xsi:type='ns1:SubType', xsi:type='xsd:string'
- if (atName.equals(atPrefix + ":type") &&
atValue.indexOf(":") > 0)
- {
- // xsi defined on the envelope
- if (nsURI == null)
- nsURI = getNamespaceURI(atPrefix, element, null);
-
- if
("http://www.w3.org/2001/XMLSchema-instance".equals(nsURI))
- {
- String typePrefix = atValue.substring(0,
atValue.indexOf(":"));
- String typeURI = getNamespaceURI(typePrefix, element, rootNode);
- nsMap.put(typePrefix, typeURI);
- }
- }
- }
-
- out.print(" " + atName + "='" + atValue +
"'");
- }
-
- // Add namespace declaration for prefixes
- // that are defined further up the tree
- if (completeNamespaces)
- {
- Iterator itPrefix = nsMap.keySet().iterator();
- while (itPrefix.hasNext())
- {
- String prefix = (String)itPrefix.next();
- String nsURI = (String)nsMap.get(prefix);
- if (nsURI == null)
- {
- nsURI = getNamespaceURI(prefix, element, null);
- out.print(" xmlns:" + prefix + "='" + nsURI
+ "'");
- }
- }
- }
-
- // The SAX ContentHandler will by default not add the namespace declaration
- // <Hello xmlns='http://somens'>World</Hello>
- if (elPrefix == null && elNamespaceURI != null)
- {
- String defaultNamespace = element.getAttribute("xmlns");
- if (defaultNamespace.length() == 0 &&
!elNamespaceURI.equals(currentDefaultNamespace))
- {
- out.print(" xmlns='" + elNamespaceURI +
"'");
- currentDefaultNamespace = elNamespaceURI;
- }
- }
-
- if (hasChildNodes)
- {
- out.print('>');
- }
-
- // Find out if the end marker is indented
- indentEndMarker = isEndMarkerIndented(node);
-
- if (indentEndMarker)
- {
- out.print('\n');
- }
-
- NodeList childNodes = node.getChildNodes();
- int len = childNodes.getLength();
- for (int i = 0; i < len; i++)
- {
- Node childNode = childNodes.item(i);
- printInternal(childNode, false);
- }
- break;
- }
-
- // handle entity reference nodes
- case Node.ENTITY_REFERENCE_NODE:
- {
- if (canonical)
- {
- NodeList children = node.getChildNodes();
- if (children != null)
- {
- int len = children.getLength();
- for (int i = 0; i < len; i++)
- {
- printInternal(children.item(i), false);
- }
- }
- }
- else
- {
- out.print('&');
- out.print(nodeName);
- out.print(';');
- }
- break;
- }
-
- // print cdata sections
- case Node.CDATA_SECTION_NODE:
- {
- if (canonical)
- {
- out.print(normalize(node.getNodeValue(), canonical));
- }
- else
- {
- out.print("<![CDATA[");
- out.print(node.getNodeValue());
- out.print("]]>");
- }
- break;
- }
-
- // print text
- case Node.TEXT_NODE:
- {
- String text = normalize(node.getNodeValue(), canonical);
- if (text.trim().length() > 0)
- {
- out.print(text);
- }
- else if (prettyprint == false && ignoreWhitespace == false)
- {
- out.print(text);
- }
- break;
- }
-
- // print processing instruction
- case Node.PROCESSING_INSTRUCTION_NODE:
- {
- out.print("<?");
- out.print(nodeName);
- String data = node.getNodeValue();
- if (data != null && data.length() > 0)
- {
- out.print(' ');
- out.print(data);
- }
- out.print("?>");
- break;
- }
-
- // print comment
- case Node.COMMENT_NODE:
- {
- for (int i = 0; i < prettyIndent; i++)
- {
- out.print(' ');
- }
-
- out.print("<!--");
- String data = node.getNodeValue();
- if (data != null)
- {
- out.print(data);
- }
- out.print("-->");
-
- if (prettyprint)
- {
- out.print('\n');
- }
-
- break;
- }
- }
-
- if (type == Node.ELEMENT_NODE)
- {
- if (prettyprint)
- prettyIndent--;
-
- if (hasChildNodes == false)
- {
- out.print("/>");
- }
- else
- {
- if (indentEndMarker)
- {
- for (int i = 0; i < prettyIndent; i++)
- {
- out.print(' ');
- }
- }
-
- out.print("</");
- out.print(nodeName);
- out.print('>');
- }
-
- if (prettyIndent > 0)
- {
- out.print('\n');
- }
- }
- out.flush();
- }
-
- private String getNamespaceURI(String prefix, Element element, Node stopNode)
- {
- Node parent = element.getParentNode();
- String nsURI = element.getAttribute("xmlns:" + prefix);
- if (nsURI.length() == 0 && element != stopNode && parent instanceof
Element)
- return getNamespaceURI(prefix, (Element)parent, stopNode);
-
- return (nsURI.length() > 0 ? nsURI : null);
- }
-
- private boolean isEndMarkerIndented(Node node)
- {
- if (prettyprint)
- {
- NodeList childNodes = node.getChildNodes();
- int len = childNodes.getLength();
- for (int i = 0; i < len; i++)
- {
- Node children = childNodes.item(i);
- if (children.getNodeType() == Node.ELEMENT_NODE)
- {
- return true;
- }
- }
- }
- return false;
- }
-
- /** Returns a sorted list of attributes. */
- private Attr[] sortAttributes(NamedNodeMap attrs)
- {
-
- int len = (attrs != null) ? attrs.getLength() : 0;
- Attr array[] = new Attr[len];
- for (int i = 0; i < len; i++)
- {
- array[i] = (Attr)attrs.item(i);
- }
- for (int i = 0; i < len - 1; i++)
- {
- String name = array[i].getNodeName();
- int index = i;
- for (int j = i + 1; j < len; j++)
- {
- String curName = array[j].getNodeName();
- if (curName.compareTo(name) < 0)
- {
- name = curName;
- index = j;
- }
- }
- if (index != i)
- {
- Attr temp = array[i];
- array[i] = array[index];
- array[index] = temp;
- }
- }
- return (array);
- }
-
- /** Normalizes the given string. */
- public static String normalize(String strValue, boolean canonical)
- {
- Matcher m = PATTERN.matcher(strValue);
- if (m.find())
- {
- int pos = m.start(); // we can use previous match to skip some part at the
string beginning
- int len = strValue.length(); // just a single call to length()
- char[] input = new char[len]; // this is to ommit calls to String.charAt()
- strValue.getChars(0, len, input, 0);
- StringBuilder sb = new StringBuilder(len * 3); // faster than StringBuffer, not
thread safe
-
- int copyStart = 0;
-
- for (int i = pos; i < len; i++)
- {
- char ch = input[i];
- switch (ch)
- {
- case '<' :
- if (copyStart < i)
- {
- sb.append(input, copyStart, i - copyStart);
- }
- copyStart = i + 1;
- sb.append("<");
- break;
- case '>' :
- if (copyStart < i)
- {
- sb.append(input, copyStart, i - copyStart);
- }
- copyStart = i + 1;
- sb.append(">");
- break;
- case '"' :
- if (copyStart < i)
- {
- sb.append(input, copyStart, i - copyStart);
- }
- copyStart = i + 1;
- sb.append(""");
- break;
- case '\'' :
- if (copyStart < i)
- {
- sb.append(input, copyStart, i - copyStart);
- }
- copyStart = i + 1;
- sb.append("'");
- break;
- case '&' :
- if (copyStart < i)
- {
- sb.append(input, copyStart, i - copyStart);
- }
- copyStart = i + 1;
- sb.append("&");
- break;
- case '\r' :
- case '\n' :
- if (canonical)
- {
- if (copyStart < i)
- {
- sb.append(input, copyStart, i - copyStart);
- }
- copyStart = i + 1;
- sb.append("&#");
- sb.append(Integer.toString(ch));
- sb.append(';');
- break;
- }
-
- }
- }
- if (copyStart < len)
- {
- sb.append(input, copyStart, len - copyStart);
- }
-
- return sb.toString();
- }
- else
- {
- return strValue;
- }
- }
-}
Copied: shared-testsuite/trunk/src/test/java/org/jboss/test/helper/DOMWriter.java (from
rev 14045,
shared-testsuite/branches/asoldano/src/test/java/org/jboss/test/helper/DOMWriter.java)
===================================================================
--- shared-testsuite/trunk/src/test/java/org/jboss/test/helper/DOMWriter.java
(rev 0)
+++ shared-testsuite/trunk/src/test/java/org/jboss/test/helper/DOMWriter.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -0,0 +1,671 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (
http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache
Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache(a)apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <
http://www.apache.org/>.
+ */
+package org.jboss.test.helper;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Traverse a DOM tree in order to print a document that is parsed.
+ *
+ * @author Andy Clark, IBM
+ * @author Thomas.Diesler(a)jboss.org
+ * @author <a href="mailto:mvecera@redhat.com">Martin Vecera</a>
+ * @author <a href="mailto:alessio.soldano@jboss.com">Alessio
Soldano</a>
+ */
+@SuppressWarnings("unchecked")
+public class DOMWriter
+{
+ private static final Pattern PATTERN =
Pattern.compile("[&<>'\"\r\n]");
+ // Print writer
+ private PrintWriter out;
+ // True, if canonical output
+ private boolean canonical;
+ // True, if pretty printing should be used
+ private boolean prettyprint;
+ // True, if the XML declaration should be written
+ private boolean writeXMLDeclaration;
+ // True, if whitespace should be ignored
+ private boolean ignoreWhitespace;
+ // Explicit character set encoding
+ private String charsetName;
+ // indent for the pretty printer
+ private int prettyIndent;
+ // True, if the XML declaration has been written
+ private boolean wroteXMLDeclaration;
+ // The node that started the write
+ private Node rootNode;
+ // True if we want namespace completion
+ private boolean completeNamespaces = true;
+ // The current default namespace
+ private String currentDefaultNamespace;
+
+ public DOMWriter(Writer w)
+ {
+ this.out = new PrintWriter(w);
+ }
+
+ public DOMWriter(Writer w, String charsetName)
+ {
+ this.out = new PrintWriter(w);
+ this.charsetName = charsetName;
+ this.writeXMLDeclaration = true;
+ }
+
+ public DOMWriter(OutputStream stream)
+ {
+ try
+ {
+ this.out = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // ignore, UTF-8 should be available
+ }
+ }
+
+ public DOMWriter(OutputStream stream, String charsetName)
+ {
+ try
+ {
+ this.out = new PrintWriter(new OutputStreamWriter(stream, charsetName));
+ this.charsetName = charsetName;
+ this.writeXMLDeclaration = true;
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new IllegalArgumentException("Unsupported encoding: " +
charsetName);
+ }
+ }
+
+ /**
+ * Print a node with explicit prettyprinting.
+ * The defaults for all other DOMWriter properties apply.
+ *
+ */
+ public static String printNode(Node node, boolean prettyprint)
+ {
+ StringWriter strw = new StringWriter();
+ new DOMWriter(strw).setPrettyprint(prettyprint).print(node);
+ return strw.toString();
+ }
+
+ public boolean isCanonical()
+ {
+ return canonical;
+ }
+
+ /**
+ * Set wheter entities should appear in their canonical form.
+ * The default is false.
+ */
+ public DOMWriter setCanonical(boolean canonical)
+ {
+ this.canonical = canonical;
+ return this;
+ }
+
+ public boolean isIgnoreWhitespace()
+ {
+ return ignoreWhitespace;
+ }
+
+ /**
+ * Set whether whitespace should be ignored.
+ * The default is false.
+ */
+ public DOMWriter setIgnoreWhitespace(boolean ignoreWhitespace)
+ {
+ this.ignoreWhitespace = ignoreWhitespace;
+ 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;
+ }
+
+ /**
+ * Set wheter element should be indented.
+ * The default is false.
+ */
+ public DOMWriter setPrettyprint(boolean prettyprint)
+ {
+ this.prettyprint = prettyprint;
+ return this;
+ }
+
+ public boolean isWriteXMLDeclaration()
+ {
+ return writeXMLDeclaration;
+ }
+
+ /**
+ * Set wheter the XML declaration should be written.
+ * The default is false.
+ */
+ public DOMWriter setWriteXMLDeclaration(boolean flag)
+ {
+ this.writeXMLDeclaration = flag;
+ return this;
+ }
+
+ public void print(Node node)
+ {
+ if (prettyprint && ignoreWhitespace)
+ throw new IllegalStateException("Cannot pretty print and ignore
whitespace");
+
+ rootNode = node;
+ printInternal(node, false);
+ }
+
+ private void printInternal(Node node, boolean indentEndMarker)
+ {
+ // is there anything to do?
+ if (node == null)
+ {
+ return;
+ }
+
+ // JBAS-2117 - Don't skip the DOCUMENT_NODE
+ // if (node instanceof Document) node = ((Document)node).getDocumentElement();
+
+ if (wroteXMLDeclaration == false && writeXMLDeclaration == true &&
canonical == false)
+ {
+ out.print("<?xml version='1.0'");
+ if (charsetName != null)
+ out.print(" encoding='" + charsetName + "'");
+
+ out.print("?>");
+ if (prettyprint)
+ out.println();
+
+ wroteXMLDeclaration = true;
+ }
+
+ int type = node.getNodeType();
+ boolean hasChildNodes = node.getChildNodes().getLength() > 0;
+
+ String nodeName = node.getNodeName();
+ switch (type)
+ {
+ // print document
+ case Node.DOCUMENT_NODE:
+ {
+ NodeList children = node.getChildNodes();
+ int len = children.getLength();
+ for (int iChild = 0; iChild < len; iChild++)
+ {
+ printInternal(children.item(iChild), false);
+ }
+ out.flush();
+ break;
+ }
+
+ // print element with attributes
+ case Node.ELEMENT_NODE:
+ {
+ Element element = (Element)node;
+ if (prettyprint)
+ {
+ for (int i = 0; i < prettyIndent; i++)
+ {
+ out.print(' ');
+ }
+ prettyIndent++;
+ }
+
+ out.print('<');
+ out.print(nodeName);
+
+ Map nsMap = new HashMap();
+ String elPrefix = node.getPrefix();
+ String elNamespaceURI = node.getNamespaceURI();
+ if (elPrefix != null)
+ {
+ String nsURI = getNamespaceURI(elPrefix, element, rootNode);
+ nsMap.put(elPrefix, nsURI);
+ }
+
+ Attr attrs[] = sortAttributes(node.getAttributes());
+ for (int i = 0; i < attrs.length; i++)
+ {
+ Attr attr = attrs[i];
+ String atPrefix = attr.getPrefix();
+ String atName = attr.getNodeName();
+ String atValue = normalize(attr.getNodeValue(), canonical);
+
+ if (atName.equals("xmlns"))
+ currentDefaultNamespace = atValue;
+
+ if (atPrefix != null && !atPrefix.equals("xmlns")
&& !atPrefix.equals("xml"))
+ {
+ String nsURI = getNamespaceURI(atPrefix, element, rootNode);
+ nsMap.put(atPrefix, nsURI);
+ // xsi:type='ns1:SubType', xsi:type='xsd:string'
+ if (atName.equals(atPrefix + ":type") &&
atValue.indexOf(":") > 0)
+ {
+ // xsi defined on the envelope
+ if (nsURI == null)
+ nsURI = getNamespaceURI(atPrefix, element, null);
+
+ if
("http://www.w3.org/2001/XMLSchema-instance".equals(nsURI))
+ {
+ String typePrefix = atValue.substring(0,
atValue.indexOf(":"));
+ String typeURI = getNamespaceURI(typePrefix, element, rootNode);
+ nsMap.put(typePrefix, typeURI);
+ }
+ }
+ }
+
+ out.print(" " + atName + "='" + atValue +
"'");
+ }
+
+ // Add namespace declaration for prefixes
+ // that are defined further up the tree
+ if (completeNamespaces)
+ {
+ Iterator itPrefix = nsMap.keySet().iterator();
+ while (itPrefix.hasNext())
+ {
+ String prefix = (String)itPrefix.next();
+ String nsURI = (String)nsMap.get(prefix);
+ if (nsURI == null)
+ {
+ nsURI = getNamespaceURI(prefix, element, null);
+ out.print(" xmlns:" + prefix + "='" + nsURI
+ "'");
+ }
+ }
+ }
+
+ // The SAX ContentHandler will by default not add the namespace declaration
+ // <Hello xmlns='http://somens'>World</Hello>
+ if (elPrefix == null && elNamespaceURI != null)
+ {
+ String defaultNamespace = element.getAttribute("xmlns");
+ if (defaultNamespace.length() == 0 &&
!elNamespaceURI.equals(currentDefaultNamespace))
+ {
+ out.print(" xmlns='" + elNamespaceURI +
"'");
+ currentDefaultNamespace = elNamespaceURI;
+ }
+ }
+
+ if (hasChildNodes)
+ {
+ out.print('>');
+ }
+
+ // Find out if the end marker is indented
+ indentEndMarker = isEndMarkerIndented(node);
+
+ if (indentEndMarker)
+ {
+ out.print('\n');
+ }
+
+ NodeList childNodes = node.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ Node childNode = childNodes.item(i);
+ printInternal(childNode, false);
+ }
+ break;
+ }
+
+ // handle entity reference nodes
+ case Node.ENTITY_REFERENCE_NODE:
+ {
+ if (canonical)
+ {
+ NodeList children = node.getChildNodes();
+ if (children != null)
+ {
+ int len = children.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ printInternal(children.item(i), false);
+ }
+ }
+ }
+ else
+ {
+ out.print('&');
+ out.print(nodeName);
+ out.print(';');
+ }
+ break;
+ }
+
+ // print cdata sections
+ case Node.CDATA_SECTION_NODE:
+ {
+ if (canonical)
+ {
+ out.print(normalize(node.getNodeValue(), canonical));
+ }
+ else
+ {
+ out.print("<![CDATA[");
+ out.print(node.getNodeValue());
+ out.print("]]>");
+ }
+ break;
+ }
+
+ // print text
+ case Node.TEXT_NODE:
+ {
+ String text = normalize(node.getNodeValue(), canonical);
+ if (text.trim().length() > 0)
+ {
+ out.print(text);
+ }
+ else if (prettyprint == false && ignoreWhitespace == false)
+ {
+ out.print(text);
+ }
+ break;
+ }
+
+ // print processing instruction
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ {
+ out.print("<?");
+ out.print(nodeName);
+ String data = node.getNodeValue();
+ if (data != null && data.length() > 0)
+ {
+ out.print(' ');
+ out.print(data);
+ }
+ out.print("?>");
+ break;
+ }
+
+ // print comment
+ case Node.COMMENT_NODE:
+ {
+ for (int i = 0; i < prettyIndent; i++)
+ {
+ out.print(' ');
+ }
+
+ out.print("<!--");
+ String data = node.getNodeValue();
+ if (data != null)
+ {
+ out.print(data);
+ }
+ out.print("-->");
+
+ if (prettyprint)
+ {
+ out.print('\n');
+ }
+
+ break;
+ }
+ }
+
+ if (type == Node.ELEMENT_NODE)
+ {
+ if (prettyprint)
+ prettyIndent--;
+
+ if (hasChildNodes == false)
+ {
+ out.print("/>");
+ }
+ else
+ {
+ if (indentEndMarker)
+ {
+ for (int i = 0; i < prettyIndent; i++)
+ {
+ out.print(' ');
+ }
+ }
+
+ out.print("</");
+ out.print(nodeName);
+ out.print('>');
+ }
+
+ if (prettyIndent > 0)
+ {
+ out.print('\n');
+ }
+ }
+ out.flush();
+ }
+
+ private String getNamespaceURI(String prefix, Element element, Node stopNode)
+ {
+ Node parent = element.getParentNode();
+ String nsURI = element.getAttribute("xmlns:" + prefix);
+ if (nsURI.length() == 0 && element != stopNode && parent instanceof
Element)
+ return getNamespaceURI(prefix, (Element)parent, stopNode);
+
+ return (nsURI.length() > 0 ? nsURI : null);
+ }
+
+ private boolean isEndMarkerIndented(Node node)
+ {
+ if (prettyprint)
+ {
+ NodeList childNodes = node.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ Node children = childNodes.item(i);
+ if (children.getNodeType() == Node.ELEMENT_NODE)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /** Returns a sorted list of attributes. */
+ private Attr[] sortAttributes(NamedNodeMap attrs)
+ {
+
+ int len = (attrs != null) ? attrs.getLength() : 0;
+ Attr array[] = new Attr[len];
+ for (int i = 0; i < len; i++)
+ {
+ array[i] = (Attr)attrs.item(i);
+ }
+ for (int i = 0; i < len - 1; i++)
+ {
+ String name = array[i].getNodeName();
+ int index = i;
+ for (int j = i + 1; j < len; j++)
+ {
+ String curName = array[j].getNodeName();
+ if (curName.compareTo(name) < 0)
+ {
+ name = curName;
+ index = j;
+ }
+ }
+ if (index != i)
+ {
+ Attr temp = array[i];
+ array[i] = array[index];
+ array[index] = temp;
+ }
+ }
+ return (array);
+ }
+
+ /** Normalizes the given string. */
+ public static String normalize(String strValue, boolean canonical)
+ {
+ Matcher m = PATTERN.matcher(strValue);
+ if (m.find())
+ {
+ int pos = m.start(); // we can use previous match to skip some part at the
string beginning
+ int len = strValue.length(); // just a single call to length()
+ char[] input = new char[len]; // this is to ommit calls to String.charAt()
+ strValue.getChars(0, len, input, 0);
+ StringBuilder sb = new StringBuilder(len * 3); // faster than StringBuffer, not
thread safe
+
+ int copyStart = 0;
+
+ for (int i = pos; i < len; i++)
+ {
+ char ch = input[i];
+ switch (ch)
+ {
+ case '<' :
+ if (copyStart < i)
+ {
+ sb.append(input, copyStart, i - copyStart);
+ }
+ copyStart = i + 1;
+ sb.append("<");
+ break;
+ case '>' :
+ if (copyStart < i)
+ {
+ sb.append(input, copyStart, i - copyStart);
+ }
+ copyStart = i + 1;
+ sb.append(">");
+ break;
+ case '"' :
+ if (copyStart < i)
+ {
+ sb.append(input, copyStart, i - copyStart);
+ }
+ copyStart = i + 1;
+ sb.append(""");
+ break;
+ case '\'' :
+ if (copyStart < i)
+ {
+ sb.append(input, copyStart, i - copyStart);
+ }
+ copyStart = i + 1;
+ sb.append("'");
+ break;
+ case '&' :
+ if (copyStart < i)
+ {
+ sb.append(input, copyStart, i - copyStart);
+ }
+ copyStart = i + 1;
+ sb.append("&");
+ break;
+ case '\r' :
+ case '\n' :
+ if (canonical)
+ {
+ if (copyStart < i)
+ {
+ sb.append(input, copyStart, i - copyStart);
+ }
+ copyStart = i + 1;
+ sb.append("&#");
+ sb.append(Integer.toString(ch));
+ sb.append(';');
+ break;
+ }
+
+ }
+ }
+ if (copyStart < len)
+ {
+ sb.append(input, copyStart, len - copyStart);
+ }
+
+ return sb.toString();
+ }
+ else
+ {
+ return strValue;
+ }
+ }
+}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestCase.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestCase.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestCase.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -48,7 +48,7 @@
import org.jboss.wsf.test.JBossWSTest;
import org.jboss.wsf.test.JBossWSTestSetup;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestServiceBean.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestServiceBean.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxrpc/samples/message/MessageTestServiceBean.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -35,7 +35,7 @@
import javax.xml.transform.dom.DOMSource;
import org.jboss.logging.Logger;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.jboss.wsf.common.DOMWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/endpoint/EndpointServlet.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -30,7 +30,10 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.Endpoint;
import javax.xml.ws.EndpointReference;
import javax.xml.ws.Service;
@@ -38,7 +41,7 @@
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import org.jboss.logging.Logger;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -51,7 +54,6 @@
@SuppressWarnings("serial")
public class EndpointServlet extends HttpServlet
{
-
private Endpoint endpoint1;
private Endpoint endpoint2;
private static final String TEST_ELEMENT = "<fabrikam:CustomerKey
xmlns:fabrikam='http://example.com/fabrikam'>123456789</fab...;
@@ -92,8 +94,9 @@
String retStr = port.echo(param);
//Test epr
-
assertEndpointReference(endpoint1.getEndpointReference(DOMUtils.parse(TEST_ELEMENT)),
TEST_ELEMENT);
- assertEndpointReference(endpoint1.getEndpointReference(W3CEndpointReference.class,
(Element[])null), null);
+ DocumentBuilder builder = getDocumentBuilder();
+ assertEndpointReference(endpoint1.getEndpointReference(DOMUtils.parse(TEST_ELEMENT,
builder)), TEST_ELEMENT, builder);
+ assertEndpointReference(endpoint1.getEndpointReference(W3CEndpointReference.class,
(Element[])null), null, builder);
// Return the result
PrintWriter pw = new PrintWriter(res.getWriter());
@@ -101,11 +104,11 @@
pw.close();
}
- private void assertEndpointReference(EndpointReference epr, String refPar) throws
IOException
+ private void assertEndpointReference(EndpointReference epr, String refPar,
DocumentBuilder builder) throws IOException
{
Logger.getLogger(this.getClass()).info("epr: "+epr);
assert(W3CEndpointReference.class.getName().equals(epr.getClass().getName()));
- Element endpointReference = DOMUtils.parse(epr.toString());
+ Element endpointReference = DOMUtils.parse(epr.toString(), builder);
assert("EndpointReference".equals(endpointReference.getNodeName()));
assert("http://www.w3.org/2005/08/addressing".equals(endpointRe...;
NodeList addresses = endpointReference.getElementsByTagName("Address");
@@ -116,4 +119,23 @@
assert(epr.toString().contains(refPar));
}
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1807/ProviderImpl.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1807/ProviderImpl.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1807/ProviderImpl.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -24,6 +24,9 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.BindingType;
@@ -34,8 +37,8 @@
import javax.xml.ws.http.HTTPBinding;
import org.jboss.logging.Logger;
-import org.jboss.wsf.common.DOMUtils;
-import org.jboss.wsf.common.DOMWriter;
+import org.jboss.test.helper.DOMWriter;
+import org.jboss.wsf.util.DOMUtils;
@WebServiceProvider(wsdlLocation = "WEB-INF/wsdl/provider.wsdl", portName =
"ProviderPort", serviceName = "ProviderService", targetNamespace =
"http://ws.com/")
@ServiceMode(value = Service.Mode.PAYLOAD)
@@ -49,7 +52,7 @@
{
try
{
- String input = DOMWriter.printNode(DOMUtils.sourceToElement(source), false);
+ String input = DOMWriter.printNode(DOMUtils.sourceToElement(source,
getDocumentBuilder()), false);
log.info("invoke: " + input);
String reply = "<reply>" + input + "</reply>";
@@ -60,4 +63,23 @@
throw new RuntimeException(ex);
}
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1815/JBWS1815TestCase.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1815/JBWS1815TestCase.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws1815/JBWS1815TestCase.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -25,6 +25,10 @@
import java.io.IOException;
import java.net.URL;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.soap.Detail;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPConnection;
@@ -36,7 +40,7 @@
import junit.framework.Test;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.jboss.wsf.test.JBossWSTest;
import org.jboss.wsf.test.JBossWSTestSetup;
import org.w3c.dom.Element;
@@ -69,7 +73,7 @@
public void testWSDLAccess() throws Exception
{
URL wsdlURL = new URL(TARGET_ENDPOINT_ADDRESS + "?wsdl");
- Element wsdl = DOMUtils.parse(wsdlURL.openStream());
+ Element wsdl = DOMUtils.parse(wsdlURL.openStream(), getDocumentBuilder());
assertNotNull(wsdl);
}
@@ -98,5 +102,24 @@
SOAPMessage reqMsg = msgFactory.createMessage(null, new
ByteArrayInputStream(msgString.getBytes()));
return reqMsg;
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws2960/JBWS2960TestCase.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws2960/JBWS2960TestCase.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/jbws2960/JBWS2960TestCase.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -35,7 +35,7 @@
import junit.framework.Assert;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.jboss.wsf.test.JBossWSTest;
import org.jboss.wsf.test.JBossWSTestHelper;
import org.w3c.dom.Element;
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/namespace/CustomHandler.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/namespace/CustomHandler.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/namespace/CustomHandler.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -31,7 +31,7 @@
import javax.xml.ws.handler.soap.SOAPMessageContext;
import org.jboss.logging.Logger;
-import org.jboss.wsf.common.DOMWriter;
+import org.jboss.test.helper.DOMWriter;
/**
* A simple SOAPHandler checking the exchanged message uses the SEI namespace.
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/AddressingPort.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/AddressingPort.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/AddressingPort.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -25,12 +25,15 @@
import java.rmi.RemoteException;
import java.util.Map;
+import javax.xml.XMLConstants;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.BindingProvider;
import org.jboss.logging.Logger;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.jboss.wsf.common.addressing.MAP;
import org.jboss.wsf.common.addressing.MAPBuilder;
import org.jboss.wsf.common.addressing.MAPBuilderFactory;
@@ -109,7 +112,7 @@
}
try
{
- replyTo.addReferenceParameter(DOMUtils.parse(getClientIdElement(clientID)));
+ replyTo.addReferenceParameter(DOMUtils.parse(getClientIdElement(clientID),
getDocumentBuilder()));
}
catch (IOException e)
{
@@ -162,4 +165,23 @@
buffer.append(">" + clientid + "</" + qualname +
">");
return buffer.toString();
}
+
+ private static DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/ServerHandler.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/ServerHandler.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/addressing/ServerHandler.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -26,13 +26,14 @@
import javax.xml.ws.handler.MessageContext.Scope;
import org.jboss.logging.Logger;
-import org.jboss.wsf.common.DOMUtils;
import org.jboss.wsf.common.addressing.MAP;
import org.jboss.wsf.common.addressing.MAPBuilder;
import org.jboss.wsf.common.addressing.MAPBuilderFactory;
import org.jboss.wsf.common.addressing.MAPEndpoint;
import org.jboss.wsf.common.handler.GenericSOAPHandler;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* A server side handler for the ws-addressing
@@ -65,10 +66,10 @@
if (obj instanceof Element)
{
Element el = (Element)obj;
- QName qname = DOMUtils.getElementQName(el);
+ QName qname = getElementQName(el);
if (qname.equals(IDQN))
{
- clientid = DOMUtils.getTextContent(el);
+ clientid = getTextContent(el);
}
}
else
@@ -101,4 +102,95 @@
return true;
}
+
+ // ---------------- DOM Util methods -------------------
+
+ /** Get the qname of the given node.
+ */
+ protected static QName getElementQName(Element el)
+ {
+ String qualifiedName = el.getNodeName();
+ return resolveQName(el, qualifiedName);
+ }
+
+ /** Transform the given qualified name into a QName
+ */
+ protected static QName resolveQName(Element el, String qualifiedName)
+ {
+ QName qname;
+ String prefix = "";
+ String namespaceURI = "";
+ String localPart = qualifiedName;
+
+ int colIndex = qualifiedName.indexOf(":");
+ if (colIndex > 0)
+ {
+ prefix = qualifiedName.substring(0, colIndex);
+ localPart = qualifiedName.substring(colIndex + 1);
+
+ if ("xmlns".equals(prefix))
+ {
+ namespaceURI = "URI:XML_PREDEFINED_NAMESPACE";
+ }
+ else
+ {
+ Element nsElement = el;
+ while (namespaceURI.equals("") && nsElement != null)
+ {
+ namespaceURI = nsElement.getAttribute("xmlns:" + prefix);
+ if (namespaceURI.equals(""))
+ nsElement = getParentElement(nsElement);
+ }
+ }
+
+ if (namespaceURI.equals("") && el.getNamespaceURI() != null)
+ {
+ namespaceURI = el.getNamespaceURI();
+ }
+
+ if (namespaceURI.equals(""))
+ throw new IllegalArgumentException("Cannot find namespace uri for:
" + qualifiedName);
+ }
+ else
+ {
+ Element nsElement = el;
+ while (namespaceURI.equals("") && nsElement != null)
+ {
+ namespaceURI = nsElement.getAttribute("xmlns");
+ if (namespaceURI.equals(""))
+ nsElement = getParentElement(nsElement);
+ }
+ }
+
+ qname = new QName(namespaceURI, localPart, prefix);
+ return qname;
+ }
+
+ /** Gets parent element or null if there is none
+ */
+ protected static Element getParentElement(Node node)
+ {
+ Node parent = node.getParentNode();
+ return (parent instanceof Element ? (Element)parent : null);
+ }
+
+ /** Get the concatenated text content, or null.
+ */
+ protected static String getTextContent(Node node)
+ {
+ boolean hasTextContent = false;
+ StringBuilder buffer = new StringBuilder();
+ NodeList nlist = node.getChildNodes();
+ int len = nlist.getLength();
+ for (int i = 0; i < len; i++)
+ {
+ Node child = nlist.item(i);
+ if (child.getNodeType() == Node.TEXT_NODE)
+ {
+ buffer.append(child.getNodeValue());
+ hasTextContent = true;
+ }
+ }
+ return (hasTextContent ? buffer.toString() : null);
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointEJB.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointEJB.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointEJB.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -33,12 +33,15 @@
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
+import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.MessageContext;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.jboss.wsf.common.DOMWriter;
import org.jboss.wsf.spi.annotation.AuthMethod;
import org.jboss.wsf.spi.annotation.TransportGuarantee;
@@ -107,11 +110,11 @@
Element root = null;
if (wsdl instanceof InputSource)
{
- root = DOMUtils.parse((InputSource)wsdl);
+ root = DOMUtils.parse((InputSource)wsdl, getDocumentBuilder());
}
else if (wsdl instanceof URI)
{
- root = DOMUtils.parse(((URI)wsdl).toURL().openStream());
+ root = DOMUtils.parse(((URI)wsdl).toURL().openStream(),
getDocumentBuilder());
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
new DOMWriter(out).setPrettyprint(true).print(root);
@@ -140,4 +143,23 @@
{
return wsCtx.isUserInRole(role);
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointJSE.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointJSE.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/context/EndpointJSE.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -31,12 +31,15 @@
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
+import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.handler.MessageContext;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.jboss.wsf.common.DOMWriter;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
@@ -84,11 +87,11 @@
Element root = null;
if (wsdl instanceof InputSource)
{
- root = DOMUtils.parse((InputSource)wsdl);
+ root = DOMUtils.parse((InputSource)wsdl, getDocumentBuilder());
}
else if (wsdl instanceof URI)
{
- root = DOMUtils.parse(((URI)wsdl).toURL().openStream());
+ root = DOMUtils.parse(((URI)wsdl).toURL().openStream(),
getDocumentBuilder());
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
new DOMWriter(out).setPrettyprint(true).print(root);
@@ -118,4 +121,23 @@
{
return wsCtx.isUserInRole(role);
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/LogicalSourceHandler.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/LogicalSourceHandler.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/LogicalSourceHandler.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -24,6 +24,9 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
@@ -34,7 +37,7 @@
import org.jboss.logging.Logger;
import org.jboss.wsf.common.handler.GenericLogicalHandler;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.w3c.dom.Element;
/**
@@ -72,7 +75,7 @@
tf.newTransformer().transform(source, new StreamResult(baos));
// Parse the payload and extract the value
- Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()));
+ Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()),
getDocumentBuilder());
String oldValue = DOMUtils.getTextContent(root);
String newValue = oldValue + ":" + direction +
"LogicalHandler";
@@ -96,4 +99,23 @@
throw new WebServiceException(ex);
}
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/ProviderBeanPayload.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/ProviderBeanPayload.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/httpbinding/ProviderBeanPayload.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -21,10 +21,13 @@
*/
package org.jboss.test.ws.jaxws.samples.httpbinding;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.w3c.dom.Element;
import javax.jws.HandlerChain;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -81,7 +84,7 @@
private void verifyRequest(String xml) throws IOException
{
- Element was = DOMUtils.parse(xml);
+ Element was = DOMUtils.parse(xml, getDocumentBuilder());
if(!"somePayload".equals(was.getLocalName())
|| !"http://org.jboss.ws/httpbinding".equals(was.getNamespaceURI())
@@ -90,5 +93,24 @@
throw new WebServiceException("Unexpected payload: " + xml);
}
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/logicalhandler/LogicalSourceHandler.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/logicalhandler/LogicalSourceHandler.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/logicalhandler/LogicalSourceHandler.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -24,6 +24,9 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
@@ -34,7 +37,7 @@
import org.jboss.logging.Logger;
import org.jboss.wsf.common.handler.GenericLogicalHandler;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.w3c.dom.Element;
/**
@@ -72,7 +75,7 @@
tf.newTransformer().transform(source, new StreamResult(baos));
// Parse the payload and extract the value
- Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()));
+ Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()),
getDocumentBuilder());
Element element = DOMUtils.getFirstChildElement(root);
String oldValue = DOMUtils.getTextContent(element);
@@ -97,4 +100,23 @@
throw new WebServiceException(ex);
}
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -24,6 +24,9 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
@@ -34,7 +37,7 @@
import org.jboss.logging.Logger;
import org.jboss.wsf.common.handler.GenericLogicalHandler;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import org.w3c.dom.Element;
/**
@@ -72,7 +75,7 @@
tf.newTransformer().transform(source, new StreamResult(baos));
// Parse the payload and extract the value
- Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()));
+ Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()),
getDocumentBuilder());
String oldValue = DOMUtils.getTextContent(root);
String newValue = oldValue + ":" + direction +
":LogicalSourceHandler";
@@ -96,4 +99,23 @@
throw new WebServiceException(ex);
}
}
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -22,7 +22,7 @@
package org.jboss.test.ws.jaxws.samples.provider;
import org.w3c.dom.Element;
-import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.util.DOMUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,6 +30,9 @@
import java.io.IOException;
import javax.jws.HandlerChain;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -81,7 +84,7 @@
private void verifyRequest(String xml) throws IOException
{
- Element was = DOMUtils.parse(xml);
+ Element was = DOMUtils.parse(xml, getDocumentBuilder());
if(!"somePayload".equals(was.getLocalName())
|| !"http://org.jboss.ws/provider".equals(was.getNamespaceURI())
@@ -89,6 +92,25 @@
{
throw new WebServiceException("Unexpected payload: " + xml);
}
-}
+ }
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ DocumentBuilderFactory factory = null;
+ try
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create document builder", e);
+ }
+ }
}
Modified:
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java
===================================================================
---
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java 2011-04-14
15:30:44 UTC (rev 14095)
+++
shared-testsuite/trunk/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java 2011-04-14
15:33:37 UTC (rev 14096)
@@ -23,7 +23,9 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -35,8 +37,6 @@
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
-import org.jboss.wsf.common.IOUtils;
-
@WebService(portName = "SaajServicePort", serviceName =
"SaajService", wsdlLocation = "WEB-INF/wsdl/SaajService.wsdl",
targetNamespace = "http://www.jboss.org/jbossws/saaj", endpointInterface =
"org.jboss.test.ws.saaj.jbws3084.ServiceIface")
public class ServiceImpl implements ServiceIface
{
@@ -93,7 +93,7 @@
{
InputStream is = entry.getValue().getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- IOUtils.copyStream(baos, is);
+ copyStream(baos, is);
String name = Integer.toString(index++);
DataHandler handler = new DataHandler(new InputStreamDataSource(
new ByteArrayInputStream(baos.toByteArray()), "text/plain",
name));
@@ -107,4 +107,25 @@
return "Hello World!";
}
+
+ public static void copyStream(OutputStream outs, InputStream ins) throws IOException
+ {
+ try
+ {
+ byte[] bytes = new byte[1024];
+ int r = ins.read(bytes);
+ while (r > 0)
+ {
+ outs.write(bytes, 0, r);
+ r = ins.read(bytes);
+ }
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ finally{
+ ins.close();
+ }
+ }
}