Author: alessio.soldano(a)jboss.com
Date: 2011-10-04 10:13:03 -0400 (Tue, 04 Oct 2011)
New Revision: 15035
Modified:
common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java
common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java
Log:
[JBWS-3365] Use a dedicated DocumentBuilfer for WSDL file publishing
Modified: common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java 2011-10-04 06:39:08 UTC
(rev 15034)
+++ common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java 2011-10-04 14:13:03 UTC
(rev 15035)
@@ -142,40 +142,41 @@
}
}
- @SuppressWarnings("deprecation")
- private void setEntityResolver(DocumentBuilder builder)
+ };
+
+ @SuppressWarnings("deprecation")
+ private static void setEntityResolver(DocumentBuilder builder)
+ {
+ EntityResolver entityResolver = null;
+ try
{
- EntityResolver entityResolver = null;
- try
+ entityResolver = new JBossWSEntityResolver();
+ }
+ catch (Throwable t)
+ {
+ boolean debugEnabled = log.isDebugEnabled();
+ if (debugEnabled)
+ log.debug("Cannot load JBossWSEntityResolver");
+ String[] resolvers = new String[] {
"org.jboss.util.xml.JBossEntityResolver" };
+ ClassLoader loader = SecurityActions.getContextClassLoader();
+ for (String resolver : resolvers)
{
- entityResolver = new JBossWSEntityResolver();
- }
- catch (Throwable t)
- {
- boolean debugEnabled = log.isDebugEnabled();
- if (debugEnabled)
- log.debug("Cannot load JBossWSEntityResolver");
- String[] resolvers = new String[] {
"org.jboss.util.xml.JBossEntityResolver" };
- ClassLoader loader = SecurityActions.getContextClassLoader();
- for (String resolver : resolvers)
+ try
{
- try
- {
- Class<?> resolverClass = SecurityActions.loadClass(loader,
resolver);
- entityResolver = (EntityResolver)resolverClass.newInstance();
- break;
- }
- catch (Exception ex)
- {
- if (debugEnabled)
- log.debug("Cannot load: " + resolver);
- }
+ Class<?> resolverClass = SecurityActions.loadClass(loader,
resolver);
+ entityResolver = (EntityResolver)resolverClass.newInstance();
+ break;
}
+ catch (Exception ex)
+ {
+ if (debugEnabled)
+ log.debug("Cannot load: " + resolver);
+ }
}
- if (entityResolver != null)
- builder.setEntityResolver(entityResolver);
}
- };
+ if (entityResolver != null)
+ builder.setEntityResolver(entityResolver);
+ }
private static void initializeFactory(final DocumentBuilderFactory factory)
{
@@ -211,6 +212,26 @@
private DOMUtils()
{
}
+
+ /**
+ * Creates a new DocumentBuilder instance using the provided DocumentBuilderFactory
+ *
+ * @param factory
+ * @return
+ */
+ public static DocumentBuilder newDocumentBuilder(final DocumentBuilderFactory
factory)
+ {
+ try
+ {
+ final DocumentBuilder builder = factory.newDocumentBuilder();
+ setEntityResolver(builder);
+ return builder;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(BundleUtils.getMessage(bundle,
"UNABLE_TO_CREATE_DOCUMENT_BUILDER"), e);
+ }
+ }
/**
* Initialize the DocumentBuilder, set the current thread association and returns it
@@ -239,14 +260,12 @@
/**
* Parse the given XML stream and return the root Element
- * This uses the document builder associated with the current thread.
*/
- public static Element parse(InputStream xmlStream) throws IOException
+ public static Element parse(InputStream xmlStream, DocumentBuilder builder) throws
IOException
{
try
{
Document doc;
- DocumentBuilder builder = getDocumentBuilder();
synchronized (builder) //synchronize to prevent concurrent parsing on the same
DocumentBuilder
{
doc = builder.parse(xmlStream);
@@ -262,6 +281,16 @@
xmlStream.close();
}
}
+
+ /**
+ * Parse the given XML stream and return the root Element
+ * This uses the document builder associated with the current thread.
+ */
+ public static Element parse(InputStream xmlStream) throws IOException
+ {
+ DocumentBuilder builder = getDocumentBuilder();
+ return parse(xmlStream, builder);
+ }
/**
* Parse the given input source and return the root Element.
Modified:
common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java 2011-10-04
06:39:08 UTC (rev 15034)
+++
common/trunk/src/main/java/org/jboss/ws/common/utils/AbstractWSDLFilePublisher.java 2011-10-04
14:13:03 UTC (rev 15035)
@@ -36,6 +36,10 @@
import javax.wsdl.Definition;
import javax.wsdl.Import;
import javax.wsdl.factory.WSDLFactory;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.jboss.logging.Logger;
import org.jboss.ws.api.util.BundleUtils;
@@ -67,6 +71,8 @@
// The server config
protected ServerConfig serverConfig;
+ private static DocumentBuilder builder;
+
public AbstractWSDLFilePublisher(ArchiveDeployment dep)
{
this.dep = dep;
@@ -88,6 +94,36 @@
}
}
+ private static synchronized DocumentBuilder getDocumentBuilder()
+ {
+ if (builder == null)
+ {
+ final ClassLoader classLoader = SecurityActions.getContextClassLoader();
+
SecurityActions.setContextClassLoader(AbstractWSDLFilePublisher.class.getClassLoader());
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+ try
+ {
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ }
+ catch (ParserConfigurationException pce)
+ {
+ log.error(pce);
+ }
+ builder = DOMUtils.newDocumentBuilder(factory);
+ }
+ finally
+ {
+ SecurityActions.setContextClassLoader(classLoader);
+ }
+ }
+ return builder;
+ }
+
/** Publish the wsdl imports for a given wsdl definition
*/
@SuppressWarnings("unchecked")
@@ -132,7 +168,7 @@
publishWsdlImports(targetURL, subdef, published);
// Publish XMLSchema imports
- Element subdoc = DOMUtils.parse(targetURL.openStream());
+ Element subdoc = DOMUtils.parse(targetURL.openStream(),
getDocumentBuilder());
publishSchemaImports(targetURL, subdoc, published);
}
}
@@ -203,7 +239,7 @@
log.debug("XMLSchema import published to: " + xsdURL);
// recursively publish imports
- Element subdoc = DOMUtils.parse(xsdURL.openStream());
+ Element subdoc = DOMUtils.parse(xsdURL.openStream(),
getDocumentBuilder());
publishSchemaImports(xsdURL, subdoc, published);
}
}
@@ -243,7 +279,7 @@
else
{
if (file.delete() == false)
- log.warn(BundleUtils.getMessage(bundle,
"CANNOT_DELETE_PUBLISHED_WSDL_DOCUMENT", file.toURL()));
+ log.warn(BundleUtils.getMessage(bundle,
"CANNOT_DELETE_PUBLISHED_WSDL_DOCUMENT", file.toURI().toURL()));
}
}
Show replies by date