JBossWS SVN: r11499 - common/trunk/src/main/java/org/jboss/wsf/common.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-28 04:45:22 -0500 (Thu, 28 Jan 2010)
New Revision: 11499
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
Log:
[JBWS-2900] Optimize EntityResolver setup in DOMUtils
Modified: common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-28 09:25:15 UTC (rev 11498)
+++ common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-28 09:45:22 UTC (rev 11499)
@@ -49,6 +49,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
+import org.jboss.ws.core.utils.JBossWSEntityResolver;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -129,28 +130,36 @@
throw new RuntimeException("Unable to create document builder", e);
}
}
-
+
private void setEntityResolver(DocumentBuilder builder)
{
- String[] resolvers = new String[] { "org.jboss.ws.core.utils.JBossWSEntityResolver", "org.jboss.util.xml.JBossEntityResolver" };
-
EntityResolver entityResolver = null;
- ClassLoader loader = SecurityActions.getContextClassLoader();
- boolean debugEnabled = log.isDebugEnabled();
- for (String resolver : resolvers)
+ try
{
- try
+ entityResolver = new JBossWSEntityResolver();
+ }
+ catch (Throwable t)
+ {
+ boolean debugEnabled = log.isDebugEnabled();
+ if (debugEnabled)
+ log.debug("Cannot load: " + JBossWSEntityResolver.class.getCanonicalName());
+ String[] resolvers = new String[] { "org.jboss.util.xml.JBossEntityResolver" };
+ ClassLoader loader = SecurityActions.getContextClassLoader();
+ for (String resolver : resolvers)
{
- Class<?> resolverClass = SecurityActions.loadClass(loader, resolver);
- entityResolver = (EntityResolver)resolverClass.newInstance();
+ try
+ {
+ Class<?> resolverClass = SecurityActions.loadClass(loader, resolver);
+ entityResolver = (EntityResolver)resolverClass.newInstance();
+ break;
+ }
+ catch (Exception ex)
+ {
+ if (debugEnabled)
+ log.debug("Cannot load: " + resolver);
+ }
}
- catch (Exception ex)
- {
- if (debugEnabled)
- log.debug("Cannot load: " + resolver);
- }
}
-
if (entityResolver != null)
builder.setEntityResolver(entityResolver);
}
15 years
JBossWS SVN: r11498 - common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-28 04:25:15 -0500 (Thu, 28 Jan 2010)
New Revision: 11498
Modified:
common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java
Log:
[JBPAPP-3571] JBossWS - Optimize EntityResolver setup in DOMUtils
Modified: common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
--- common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-28 09:18:49 UTC (rev 11497)
+++ common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-28 09:25:15 UTC (rev 11498)
@@ -49,6 +49,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
+import org.jboss.ws.core.utils.JBossWSEntityResolver;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -129,26 +130,33 @@
throw new RuntimeException("Unable to create document builder", e);
}
}
-
+
private void setEntityResolver(DocumentBuilder builder)
{
- String[] resolvers = new String[] { "org.jboss.ws.core.utils.JBossWSEntityResolver", "org.jboss.util.xml.JBossEntityResolver" };
-
EntityResolver entityResolver = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- for (String resolver : resolvers)
+ try
{
- try
+ entityResolver = new JBossWSEntityResolver();
+ }
+ catch (Throwable t)
+ {
+ log.debug("Cannot load: " + JBossWSEntityResolver.class.getCanonicalName());
+ String[] resolvers = new String[] { "org.jboss.util.xml.JBossEntityResolver" };
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ for (String resolver : resolvers)
{
- Class<?> resolverClass = loader.loadClass(resolver);
- entityResolver = (EntityResolver)resolverClass.newInstance();
+ try
+ {
+ Class<?> resolverClass = loader.loadClass(resolver);
+ entityResolver = (EntityResolver)resolverClass.newInstance();
+ break;
+ }
+ catch (Exception ex)
+ {
+ log.debug("Cannot load: " + resolver);
+ }
}
- catch (Exception ex)
- {
- log.debug("Cannot load: " + resolver);
- }
}
-
if (entityResolver != null)
builder.setEntityResolver(entityResolver);
}
15 years
JBossWS SVN: r11497 - common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/wsf/common.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-28 04:18:49 -0500 (Thu, 28 Jan 2010)
New Revision: 11497
Modified:
common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/wsf/common/DOMUtils.java
Log:
[JBPAPP-3571] JBossWS - Optimize EntityResolver setup in DOMUtils
Modified: common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
--- common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-27 11:06:44 UTC (rev 11496)
+++ common/branches/jbossws-common-1.1.0/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-28 09:18:49 UTC (rev 11497)
@@ -49,6 +49,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
+import org.jboss.ws.core.utils.JBossWSEntityResolver;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -129,26 +130,33 @@
throw new RuntimeException("Unable to create document builder", e);
}
}
-
+
private void setEntityResolver(DocumentBuilder builder)
{
- String[] resolvers = new String[] { "org.jboss.ws.core.utils.JBossWSEntityResolver", "org.jboss.util.xml.JBossEntityResolver" };
-
EntityResolver entityResolver = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- for (String resolver : resolvers)
+ try
{
- try
+ entityResolver = new JBossWSEntityResolver();
+ }
+ catch (Throwable t)
+ {
+ log.debug("Cannot load: " + JBossWSEntityResolver.class.getCanonicalName());
+ String[] resolvers = new String[] { "org.jboss.util.xml.JBossEntityResolver" };
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ for (String resolver : resolvers)
{
- Class<?> resolverClass = loader.loadClass(resolver);
- entityResolver = (EntityResolver)resolverClass.newInstance();
+ try
+ {
+ Class<?> resolverClass = loader.loadClass(resolver);
+ entityResolver = (EntityResolver)resolverClass.newInstance();
+ break;
+ }
+ catch (Exception ex)
+ {
+ log.debug("Cannot load: " + resolver);
+ }
}
- catch (Exception ex)
- {
- log.debug("Cannot load: " + resolver);
- }
}
-
if (entityResolver != null)
builder.setEntityResolver(entityResolver);
}
15 years
JBossWS SVN: r11496 - stack/native/branches/jaxrpc-cxf/modules/core/src/main/resources.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-27 06:06:44 -0500 (Wed, 27 Jan 2010)
New Revision: 11496
Modified:
stack/native/branches/jaxrpc-cxf/modules/core/src/main/resources/jbossws-native-config-as6.xml
Log:
[JBWS-2899] Updating the stack specific config file
Modified: stack/native/branches/jaxrpc-cxf/modules/core/src/main/resources/jbossws-native-config-as6.xml
===================================================================
--- stack/native/branches/jaxrpc-cxf/modules/core/src/main/resources/jbossws-native-config-as6.xml 2010-01-27 11:06:19 UTC (rev 11495)
+++ stack/native/branches/jaxrpc-cxf/modules/core/src/main/resources/jbossws-native-config-as6.xml 2010-01-27 11:06:44 UTC (rev 11496)
@@ -2,17 +2,6 @@
<deployment xmlns="urn:jboss:bean-deployer:2.0">
- <!-- WSDeploymentAspectDeployers factory -->
- <bean name="WSAspectizedDeployersFactory" class="org.jboss.webservices.integration.deployers.WSAspectizedDeployersFactory">
- <constructor>
- <parameter>
- <inject bean="Deployers"/>
- </parameter>
- </constructor>
- <incallback method="addDeployer"/>
- <uncallback method="removeDeployer"/>
- </bean>
-
<!-- The registry for web service endpoints -->
<bean name="WSEndpointRegistry" class="org.jboss.wsf.framework.management.ManagedEndpointRegistry">
<property name="mbeanServer"><inject bean="WSMBeanServerLocator" property="mbeanServer"/></property>
15 years
JBossWS SVN: r11495 - stack/cxf/branches/jaxrpc-cxf/modules/server/src/main/resources.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-27 06:06:19 -0500 (Wed, 27 Jan 2010)
New Revision: 11495
Modified:
stack/cxf/branches/jaxrpc-cxf/modules/server/src/main/resources/jbossws-cxf-config-as6.xml
Log:
[JBWS-2899] Updating the stack specific config file
Modified: stack/cxf/branches/jaxrpc-cxf/modules/server/src/main/resources/jbossws-cxf-config-as6.xml
===================================================================
--- stack/cxf/branches/jaxrpc-cxf/modules/server/src/main/resources/jbossws-cxf-config-as6.xml 2010-01-27 11:00:59 UTC (rev 11494)
+++ stack/cxf/branches/jaxrpc-cxf/modules/server/src/main/resources/jbossws-cxf-config-as6.xml 2010-01-27 11:06:19 UTC (rev 11495)
@@ -2,18 +2,6 @@
<deployment xmlns="urn:jboss:bean-deployer:2.0">
- <!-- WSDeploymentAspectDeployers factory -->
- <bean name="WSAspectizedDeployersFactory" class="org.jboss.webservices.integration.deployers.WSAspectizedDeployersFactory">
- <constructor>
- <parameter>
- <inject bean="Deployers"/>
- </parameter>
- </constructor>
- <incallback method="addDeployer"/>
- <uncallback method="removeDeployer"/>
- <property name="includeJaxRpc">false</property>
- </bean>
-
<!-- The registry for web service endpoints -->
<bean name="WSEndpointRegistry" class="org.jboss.wsf.framework.management.ManagedEndpointRegistry">
<property name="mbeanServer"><inject bean="WSMBeanServerLocator" property="mbeanServer"/></property>
15 years
JBossWS SVN: r11494 - framework/branches/jaxrpc-cxf/src/main/java/org/jboss/wsf/framework/deployment.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-27 06:00:59 -0500 (Wed, 27 Jan 2010)
New Revision: 11494
Modified:
framework/branches/jaxrpc-cxf/src/main/java/org/jboss/wsf/framework/deployment/EndpointAPIDeploymentAspect.java
Log:
Make EndpointAPIDeploymentAspect extend the AbstractDeploymentAspect
Modified: framework/branches/jaxrpc-cxf/src/main/java/org/jboss/wsf/framework/deployment/EndpointAPIDeploymentAspect.java
===================================================================
--- framework/branches/jaxrpc-cxf/src/main/java/org/jboss/wsf/framework/deployment/EndpointAPIDeploymentAspect.java 2010-01-27 10:10:45 UTC (rev 11493)
+++ framework/branches/jaxrpc-cxf/src/main/java/org/jboss/wsf/framework/deployment/EndpointAPIDeploymentAspect.java 2010-01-27 11:00:59 UTC (rev 11494)
@@ -22,9 +22,9 @@
package org.jboss.wsf.framework.deployment;
import org.jboss.wsf.common.ResourceLoaderAdapter;
+import org.jboss.wsf.common.integration.AbstractDeploymentAspect;
import org.jboss.wsf.spi.deployment.ArchiveDeployment;
import org.jboss.wsf.spi.deployment.Deployment;
-import org.jboss.wsf.spi.deployment.DeploymentAspect;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
import org.jboss.wsf.spi.deployment.Deployment.DeploymentType;
@@ -36,7 +36,7 @@
* @since 31-Jul-2007
*/
// TODO: [JBWS-2674] review this deployment aspect once AS IL is rewritten
-public class EndpointAPIDeploymentAspect extends DeploymentAspect
+public class EndpointAPIDeploymentAspect extends AbstractDeploymentAspect
{
@Override
public void start(Deployment dep)
15 years
JBossWS SVN: r11493 - in common/branches/jbossws-common-1.1.0.SP4/src: main/java/org/jboss/wsf/common and 1 other directories.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-27 05:10:45 -0500 (Wed, 27 Jan 2010)
New Revision: 11493
Removed:
common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java
common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java
common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java
Modified:
common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/ws/Constants.java
common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java
common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/SecurityActions.java
Log:
[JBPAPP-3544] JBossWS - Optimize DocumentBuilderFactory creation using DocumentBuilderFactory.newInstance(String s, ClassLoader c)
Modified: common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/ws/Constants.java
===================================================================
--- common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/ws/Constants.java 2010-01-27 09:55:02 UTC (rev 11492)
+++ common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/ws/Constants.java 2010-01-27 10:10:45 UTC (rev 11493)
@@ -302,4 +302,6 @@
static final String EAGER_INITIALIZE_JAXB_CONTEXT_CACHE = "org.jboss.ws.eagerInitializeJAXBContextCache";
static final String DOM_CONTENT_CANONICAL_NORMALIZATION = "org.jboss.ws.DOMContentCanonicalNormalization";
+
+ static final String ALWAYS_RESOLVE_DOCUMENT_BUILDER_FACTORY = "org.jboss.ws.alwaysResolveDocumentBuilderFactory";
}
Modified: common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
--- common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-27 09:55:02 UTC (rev 11492)
+++ common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-27 10:10:45 UTC (rev 11493)
@@ -48,6 +48,7 @@
import javax.xml.transform.stream.StreamSource;
import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -71,7 +72,12 @@
private static final String DISABLE_DEFERRED_NODE_EXPANSION = "org.jboss.ws.disable_deferred_node_expansion";
private static final String DEFER_NODE_EXPANSION_FEATURE = "http://apache.org/xml/features/dom/defer-node-expansion";
-
+
+ private static String documentBuilderFactoryName;
+
+ private static final boolean alwaysResolveFactoryName = Boolean.getBoolean(Constants.ALWAYS_RESOLVE_DOCUMENT_BUILDER_FACTORY);
+ private static final boolean disableDeferedNodeExpansion = Boolean.getBoolean(DISABLE_DEFERRED_NODE_EXPANSION);
+
// All elements created by the same thread are created by the same builder and belong to the same doc
private static ThreadLocal<Document> documentThreadLocal = new ThreadLocal<Document>();
private static ThreadLocal<DocumentBuilder> builderThreadLocal = new ThreadLocal<DocumentBuilder>() {
@@ -80,14 +86,31 @@
DocumentBuilderFactory factory = null;
try
{
- factory = JBossWSDocumentBuilderFactory.newInstance();
+ //slow
+ //factory = DocumentBuilderFactory.newInstance();
+
+ //fast (requires JDK6 or greater)
+ if (documentBuilderFactoryName == null || alwaysResolveFactoryName)
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ if (!alwaysResolveFactoryName)
+ {
+ documentBuilderFactoryName = factory.getClass().getCanonicalName();
+ }
+ }
+ else
+ {
+ factory = DocumentBuilderFactory.newInstance(documentBuilderFactoryName, SecurityActions.getContextClassLoader());
+ }
+
+
factory.setValidating(false);
factory.setNamespaceAware(true);
try
{
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- if (Boolean.getBoolean(DISABLE_DEFERRED_NODE_EXPANSION))
+ if (disableDeferedNodeExpansion)
{
factory.setFeature(DEFER_NODE_EXPANSION_FEATURE, false);
}
Deleted: common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java
===================================================================
--- common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java 2010-01-27 09:55:02 UTC (rev 11492)
+++ common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java 2010-01-27 10:10:45 UTC (rev 11493)
@@ -1,492 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.wsf.common;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.WeakHashMap;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.validation.Schema;
-
-import org.jboss.logging.Logger;
-
-/**
- * A thread-safe {@link DocumentBuilderFactory} that also adds a caching system
- * for preventing useless access to the filesystem due to the Service API when
- * the same context classloader is in place.
- *
- * @author alessio.soldano(a)jboss.com
- * @since 22-Dec-2009
- *
- */
-public class JBossWSDocumentBuilderFactory extends DocumentBuilderFactory
-{
- private static Logger log = Logger.getLogger(JBossWSDocumentBuilderFactory.class);
- private static final String PROPERTY_NAME = "javax.xml.parsers.DocumentBuilderFactory";
- private static final boolean useJaxpProperty;
- /**
- * A weak hash map that keeps DocumentBuilderFactory instances for each classloader.
- * Weak keys are used to remove entries when classloaders are garbage collected.
- *
- * No need for a synchronized map as this accessed from the
- * static synchronized newInstance newInstance method.
- */
- private static Map<ClassLoader, JBossWSDocumentBuilderFactory> factoryMap = new WeakHashMap<ClassLoader, JBossWSDocumentBuilderFactory>();
-
- private final DocumentBuilderFactory delegate;
-
- //ThreadLocal attributes and features maps required to achieve thread safety
- private ThreadLocal<DocumentBuilderFactoryFields> fields = new ThreadLocal<DocumentBuilderFactoryFields>() {
- @Override
- protected DocumentBuilderFactoryFields initialValue()
- {
- return new DocumentBuilderFactoryFields();
- }
- };
-
- static
- {
- // Use the properties file "lib/jaxp.properties" in the JRE directory.
- // This configuration file is in standard java.util.Properties format and contains the fully
- // qualified name of the implementation class with the key being the system property defined above.
- PrivilegedAction<Object> action = new PropertyAccessAction("java.home");
- String javaHome = (String)AccessController.doPrivileged(action);
- File jaxmFile = new File(javaHome + "/lib/jaxp.properties");
- if ((Boolean)AccessController.doPrivileged(new PropertyFileExistAction(jaxmFile)))
- {
- String factoryName = null;
- boolean error = false;
- try
- {
- action = new PropertyFileAccessAction(jaxmFile.getCanonicalPath());
- Properties jaxmProperties = (Properties)AccessController.doPrivileged(action);
- factoryName = jaxmProperties.getProperty(PROPERTY_NAME);
- }
- catch (IOException e)
- {
- log.warn("Can't read " + jaxmFile);
- error = true;
- }
- finally
- {
- useJaxpProperty = (error || (factoryName != null));
- }
- }
- else
- {
- useJaxpProperty = false;
- }
- }
-
- private JBossWSDocumentBuilderFactory(DocumentBuilderFactory delegate)
- {
- this.delegate = delegate;
- }
-
- @Override
- public Object getAttribute(String name) throws IllegalArgumentException
- {
- return fields.get().getAttribute(name);
- }
-
- @Override
- public boolean getFeature(String name) throws ParserConfigurationException
- {
- return fields.get().getFeature(name);
- }
-
- /**
- * The creation method for the document builder; it's synchronized to allow us configuring the underlying
- * DocumentBuilderFactory and delegate to it in a thread safe way.
- *
- */
- @Override
- public synchronized DocumentBuilder newDocumentBuilder() throws ParserConfigurationException
- {
- DocumentBuilderFactoryFields currentFields = fields.get();
- currentFields.copyTo(delegate);
- return delegate.newDocumentBuilder();
- }
-
- @Override
- public void setAttribute(String name, Object value) throws IllegalArgumentException
- {
- fields.get().setAttribute(name, value);
- }
-
- @Override
- public void setFeature(String name, boolean value) throws ParserConfigurationException
- {
- fields.get().setFeature(name, value);
- }
-
- @Override
- public boolean isCoalescing()
- {
- return fields.get().isCoalescing();
- }
-
- @Override
- public void setCoalescing(boolean coalescing)
- {
- fields.get().setCoalescing(coalescing);
- }
-
- @Override
- public boolean isExpandEntityReferences()
- {
- return fields.get().isExpandEntityReferences();
- }
-
- @Override
- public void setExpandEntityReferences(boolean expandEntityReferences)
- {
- fields.get().setExpandEntityReferences(expandEntityReferences);
- }
-
- @Override
- public boolean isIgnoringComments()
- {
- return fields.get().isIgnoringComments();
- }
-
- @Override
- public void setIgnoringComments(boolean ignoringComments)
- {
- fields.get().setIgnoringComments(ignoringComments);
- }
-
- @Override
- public boolean isIgnoringElementContentWhitespace()
- {
- return fields.get().isIgnoringElementContentWhitespace();
- }
-
- @Override
- public void setIgnoringElementContentWhitespace(boolean ignoringElementContentWhitespace)
- {
- fields.get().setIgnoringElementContentWhitespace(ignoringElementContentWhitespace);
- }
-
- @Override
- public boolean isNamespaceAware()
- {
- return fields.get().isNamespaceAware();
- }
-
- @Override
- public void setNamespaceAware(boolean namespaceAware)
- {
- fields.get().setNamespaceAware(namespaceAware);
- }
-
- @Override
- public Schema getSchema()
- {
- return fields.get().getSchema();
- }
-
- @Override
- public void setSchema(Schema schema)
- {
- fields.get().setSchema(schema);
- }
-
- @Override
- public boolean isValidating()
- {
- return fields.get().isValidating();
- }
-
- @Override
- public void setValidating(boolean validating)
- {
- fields.get().setValidating(validating);
- }
-
- @Override
- public boolean isXIncludeAware()
- {
- return fields.get().isXIncludeAware();
- }
-
- @Override
- public void setXIncludeAware(boolean includeAware)
- {
- fields.get().setXIncludeAware(includeAware);
- }
-
- /**
- * The {@link DocumentBuilderFactory#newInstance()} documentation defines the retrieval algorithm:
- *
- * 1) Use the javax.xml.parsers.DocumentBuilderFactory system property.
- * 2) Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format
- * and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties
- * file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first
- * attempt is made to read from it, no further attempts are made to check for its existence. It is not possible to change the value of any
- * property in jaxp.properties after it has been read for the first time.
- * 3) Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for a
- * classname in the file META-INF/services/javax.xml.parsers.DocumentBuilderFactory in jars available to the runtime.
- * 4) Platform default DocumentBuilderFactory instance.
- *
- * So we basically check if 1) or 2) applies: if yes, we simply delegate to the DocumentBuilderFactory, otherwise we first try using our classloader
- * cache and delegate to the DocumentBuilderFactory only in case of a miss in the cache. Then we wrap up the result into a JBossWSDocumentBuilderFactory
- * instance.
- *
- * @return a DocumentBuilderFactoryInstance
- */
- public static synchronized JBossWSDocumentBuilderFactory newInstance()
- {
- if (useJaxpProperty || getFactoryNameFromSystemProperty() != null)
- {
- return new JBossWSDocumentBuilderFactory(DocumentBuilderFactory.newInstance());
- }
- ClassLoader classLoader = SecurityActions.getContextClassLoader();
- JBossWSDocumentBuilderFactory factory = factoryMap.get(classLoader);
- if (factory == null)
- {
- factory = new JBossWSDocumentBuilderFactory(DocumentBuilderFactory.newInstance());
- factoryMap.put(classLoader, factory);
- }
- return factory;
- }
-
- private static String getFactoryNameFromSystemProperty()
- {
- PrivilegedAction<Object> action = new PropertyAccessAction(PROPERTY_NAME);
- return (String)AccessController.doPrivileged(action);
- }
-
-
- //--------------------------------- Utility privileged actions
-
- private static class PropertyAccessAction implements PrivilegedAction<Object>
- {
- private String name;
-
- PropertyAccessAction(String name)
- {
- this.name = name;
- }
-
- public Object run()
- {
- return System.getProperty(name);
- }
- }
-
- private static class PropertyFileAccessAction implements PrivilegedAction<Object>
- {
- private String filename;
-
- PropertyFileAccessAction(String filename)
- {
- this.filename = filename;
- }
-
- public Object run()
- {
- InputStream inStream = null;
- try
- {
- inStream = new FileInputStream(filename);
- Properties props = new Properties();
- props.load(inStream);
- return props;
- }
- catch (IOException ex)
- {
- throw new SecurityException("Cannot load properties: " + filename, ex);
- }
- finally
- {
- try
- {
- inStream.close();
- }
- catch (Exception e) {} //ignore
- }
- }
- }
-
- private static class PropertyFileExistAction implements PrivilegedAction<Object>
- {
- private File file;
-
- PropertyFileExistAction(File file)
- {
- this.file = file;
- }
-
- public Object run()
- {
- return file.exists();
- }
- }
-
- /**
- * A utility class for storing the document builder factory fields in the ThreadLocal
- */
- private static class DocumentBuilderFactoryFields {
- private boolean coalescing = false;
- private boolean expandEntityReferences = true;
- private boolean ignoringComments = false;
- private boolean ignoringElementContentWhitespace = false;
- private boolean namespaceAware = false;
- private Schema schema = null;
- private boolean validating = false;
- private boolean XIncludeAware = false;
- private Map<String, Object> attributes = new HashMap<String, Object>();
- private Map<String, Boolean> features = new HashMap<String, Boolean>();
-
- public void copyTo(DocumentBuilderFactory target) throws ParserConfigurationException
- {
- target.setCoalescing(coalescing);
- target.setExpandEntityReferences(expandEntityReferences);
- target.setIgnoringComments(ignoringComments);
- target.setIgnoringElementContentWhitespace(ignoringElementContentWhitespace);
- target.setNamespaceAware(namespaceAware);
- target.setSchema(schema);
- target.setValidating(validating);
- target.setXIncludeAware(XIncludeAware);
- for (String key : attributes.keySet())
- {
- target.setAttribute(key, attributes.get(key));
- }
- for (String key : features.keySet())
- {
- target.setFeature(key, features.get(key));
- }
- }
-
- public Object getAttribute(String name)
- {
- return attributes.get(name);
- }
-
- public Boolean getFeature(String name)
- {
- return features.get(name);
- }
-
- public void setAttribute(String key, Object value)
- {
- this.attributes.put(key, value);
- }
-
- public void setFeature(String key, Boolean value)
- {
- this.features.put(key, value);
- }
-
- public boolean isCoalescing()
- {
- return coalescing;
- }
-
- public void setCoalescing(boolean coalescing)
- {
- this.coalescing = coalescing;
- }
-
- public boolean isExpandEntityReferences()
- {
- return expandEntityReferences;
- }
-
- public void setExpandEntityReferences(boolean expandEntityReferences)
- {
- this.expandEntityReferences = expandEntityReferences;
- }
-
- public boolean isIgnoringComments()
- {
- return ignoringComments;
- }
-
- public void setIgnoringComments(boolean ignoringComments)
- {
- this.ignoringComments = ignoringComments;
- }
-
- public boolean isIgnoringElementContentWhitespace()
- {
- return ignoringElementContentWhitespace;
- }
-
- public void setIgnoringElementContentWhitespace(boolean ignoringElementContentWhitespace)
- {
- this.ignoringElementContentWhitespace = ignoringElementContentWhitespace;
- }
-
- public boolean isNamespaceAware()
- {
- return namespaceAware;
- }
-
- public void setNamespaceAware(boolean namespaceAware)
- {
- this.namespaceAware = namespaceAware;
- }
-
- public Schema getSchema()
- {
- return schema;
- }
-
- public void setSchema(Schema schema)
- {
- this.schema = schema;
- }
-
- public boolean isValidating()
- {
- return validating;
- }
-
- public void setValidating(boolean validating)
- {
- this.validating = validating;
- }
-
- public boolean isXIncludeAware()
- {
- return XIncludeAware;
- }
-
- public void setXIncludeAware(boolean includeAware)
- {
- XIncludeAware = includeAware;
- }
- }
-
-}
Modified: common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/SecurityActions.java
===================================================================
--- common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/SecurityActions.java 2010-01-27 09:55:02 UTC (rev 11492)
+++ common/branches/jbossws-common-1.1.0.SP4/src/main/java/org/jboss/wsf/common/SecurityActions.java 2010-01-27 10:10:45 UTC (rev 11493)
@@ -89,4 +89,23 @@
});
}
}
+
+ /**
+ * Return the current value of the specified system property
+ *
+ * @param name
+ * @param defaultValue
+ * @return
+ */
+ static String getSystemProperty(final String name, final String defaultValue)
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
}
\ No newline at end of file
Deleted: common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java
===================================================================
--- common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java 2010-01-27 09:55:02 UTC (rev 11492)
+++ common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java 2010-01-27 10:10:45 UTC (rev 11493)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.ws.common.utils;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-/**
- * A dummy document builder factory just for testing in {@link JBossWSDocumentBuilderFactoryTestCase}.
- *
- * @author alessio.soldano(a)jboss.com
- * @since 23-Dec-2009
- *
- */
-public class DummyDocumentBuilderFactory extends DocumentBuilderFactory
-{
- @Override
- public Object getAttribute(String name) throws IllegalArgumentException
- {
- return null;
- }
-
- @Override
- public boolean getFeature(String name) throws ParserConfigurationException
- {
- return false;
- }
-
- @Override
- public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException
- {
- return null;
- }
-
- @Override
- public void setAttribute(String name, Object value) throws IllegalArgumentException
- {
- }
-
- @Override
- public void setFeature(String name, boolean value) throws ParserConfigurationException
- {
- }
-}
Deleted: common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java
===================================================================
--- common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java 2010-01-27 09:55:02 UTC (rev 11492)
+++ common/branches/jbossws-common-1.1.0.SP4/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java 2010-01-27 10:10:45 UTC (rev 11493)
@@ -1,191 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.ws.common.utils;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import junit.framework.TestCase;
-
-import org.jboss.wsf.common.JBossWSDocumentBuilderFactory;
-
-/**
- * Tests for the JBossWSDocumentBuilderFactory
- *
- * @author alessio.soldano(a)jboss.com
- * @since 23-Dec-2009
- *
- */
-public class JBossWSDocumentBuilderFactoryTestCase extends TestCase
-{
- public void testCaching() throws Exception
- {
- final String propName = "javax.xml.parsers.DocumentBuilderFactory";
- String origValue = System.getProperty(propName);
- try
- {
- //remove system prop if any, to get the same factory for a given classloader
- System.getProperties().remove(propName);
- DocumentBuilderFactory factory1 = JBossWSDocumentBuilderFactory.newInstance();
- DocumentBuilderFactory factory2 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected the same factory", factory1.equals(factory2));
-
- //set the system prop, we should get different factories every time as the classloader based cache is by-passed
- System.setProperty(propName, DummyDocumentBuilderFactory.class.getCanonicalName());
- DocumentBuilderFactory factory3 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected different factories", !factory3.equals(factory1));
- assertTrue("Expected different factories", !factory3.equals(factory2));
- DocumentBuilderFactory factory4 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected different factories", !factory4.equals(factory1));
- assertTrue("Expected different factories", !factory4.equals(factory2));
- assertTrue("Expected different factories", !factory4.equals(factory3));
-
- //remove the prop again, we should get the first factory
- System.getProperties().remove(propName);
- DocumentBuilderFactory factory5 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected the same factory", factory5.equals(factory1));
-
- ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- //change context classloader
- Thread.currentThread().setContextClassLoader(new TestClassLoader(origLoader));
- DocumentBuilderFactory factory6 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected different factories", !factory6.equals(factory1));
- DocumentBuilderFactory factory7 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected the same factory", factory7.equals(factory6));
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(origLoader);
- }
- }
- finally
- {
- if (origValue == null)
- {
- System.getProperties().remove(propName);
- }
- else
- {
- System.setProperty(propName, origValue);
- }
- }
- }
-
- public void testThreadSafety() throws Exception
- {
- DocumentBuilderFactory factory = JBossWSDocumentBuilderFactory.newInstance();
- List<Callable<Boolean>> callables = new LinkedList<Callable<Boolean>>();
- for (int j = 0; j < 3; j++)
- {
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, true, true, true));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, true, true, false));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, true, false, false));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, false, false));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, false, true));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, true, true));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, true, false));
- }
- }
- ExecutorService es = Executors.newFixedThreadPool(210);
- List<Future<Boolean>> futures = es.invokeAll(callables);
- for (Future<Boolean> f : futures)
- {
- assertTrue(f.get());
- }
- }
-
- /**
- * A Callable that use the provided thread safe factory to create a document builder and verifies it has the required configuration
- */
- public static class TestCallable implements Callable<Boolean>
- {
- private final DocumentBuilderFactory factory;
- private final Boolean namespaceAware;
- private final Boolean validating;
- private final Boolean XIncludeAware;
-
- public TestCallable(DocumentBuilderFactory factory, boolean namespaceAware, boolean validating, boolean includeAware)
- {
- this.factory = factory;
- this.namespaceAware = namespaceAware;
- this.validating = validating;
- this.XIncludeAware = includeAware;
- }
-
- public Boolean call() throws Exception
- {
- factory.setNamespaceAware(namespaceAware);
- factory.setValidating(validating);
- factory.setXIncludeAware(XIncludeAware);
- DocumentBuilder builder = factory.newDocumentBuilder();
- if (!namespaceAware.equals(builder.isNamespaceAware()))
- return false;
- if (!validating.equals(builder.isValidating()))
- return false;
- if (!XIncludeAware.equals(builder.isXIncludeAware()))
- return false;
- return true;
- }
-
- }
-
- /**
- * A ClassLoader doing nothing except falling back to its parent
- */
- public static class TestClassLoader extends ClassLoader
- {
- public TestClassLoader(ClassLoader parent)
- {
- super(parent);
- }
- }
-
-}
15 years
JBossWS SVN: r11491 - common/branches.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-27 04:51:40 -0500 (Wed, 27 Jan 2010)
New Revision: 11491
Added:
common/branches/jbossws-common-1.1.0.SP4/
Log:
Recreating (from 1.1.0.SP3) a branch for jbossws-common to be used in SOA 5
Copied: common/branches/jbossws-common-1.1.0.SP4 (from rev 11490, common/tags/jbossws-common-1.1.0.SP3)
15 years
JBossWS SVN: r11490 - in common/trunk/src: main/java/org/jboss/wsf/common and 1 other directories.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2010-01-26 10:29:45 -0500 (Tue, 26 Jan 2010)
New Revision: 11490
Removed:
common/trunk/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java
common/trunk/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java
common/trunk/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java
Modified:
common/trunk/src/main/java/org/jboss/ws/Constants.java
common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
common/trunk/src/main/java/org/jboss/wsf/common/SecurityActions.java
Log:
[JBWS-2898] Optimize DocumentBuilderFactory creation using DocumentBuilderFactory.newInstance(String s, ClassLoader c)
Modified: common/trunk/src/main/java/org/jboss/ws/Constants.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/Constants.java 2010-01-26 15:19:31 UTC (rev 11489)
+++ common/trunk/src/main/java/org/jboss/ws/Constants.java 2010-01-26 15:29:45 UTC (rev 11490)
@@ -319,6 +319,8 @@
static final String DOM_CONTENT_CANONICAL_NORMALIZATION = "org.jboss.ws.DOMContentCanonicalNormalization";
+ static final String ALWAYS_RESOLVE_DOCUMENT_BUILDER_FACTORY = "org.jboss.ws.alwaysResolveDocumentBuilderFactory";
+
static final String HTTP_KEEP_ALIVE = "org.jboss.ws.http.keepAlive";
static final String HTTP_MAX_CONNECTIONS = "org.jboss.ws.http.maxConnections";
Modified: common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-26 15:19:31 UTC (rev 11489)
+++ common/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2010-01-26 15:29:45 UTC (rev 11490)
@@ -48,6 +48,7 @@
import javax.xml.transform.stream.StreamSource;
import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -71,7 +72,12 @@
private static final String DISABLE_DEFERRED_NODE_EXPANSION = "org.jboss.ws.disable_deferred_node_expansion";
private static final String DEFER_NODE_EXPANSION_FEATURE = "http://apache.org/xml/features/dom/defer-node-expansion";
-
+
+ private static String documentBuilderFactoryName;
+
+ private static final boolean alwaysResolveFactoryName = Boolean.getBoolean(Constants.ALWAYS_RESOLVE_DOCUMENT_BUILDER_FACTORY);
+ private static final boolean disableDeferedNodeExpansion = Boolean.getBoolean(DISABLE_DEFERRED_NODE_EXPANSION);
+
// All elements created by the same thread are created by the same builder and belong to the same doc
private static ThreadLocal<Document> documentThreadLocal = new ThreadLocal<Document>();
private static ThreadLocal<DocumentBuilder> builderThreadLocal = new ThreadLocal<DocumentBuilder>() {
@@ -80,14 +86,31 @@
DocumentBuilderFactory factory = null;
try
{
- factory = JBossWSDocumentBuilderFactory.newInstance();
+ //slow
+ //factory = DocumentBuilderFactory.newInstance();
+
+ //fast (requires JDK6 or greater)
+ if (documentBuilderFactoryName == null || alwaysResolveFactoryName)
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ if (!alwaysResolveFactoryName)
+ {
+ documentBuilderFactoryName = factory.getClass().getCanonicalName();
+ }
+ }
+ else
+ {
+ factory = DocumentBuilderFactory.newInstance(documentBuilderFactoryName, SecurityActions.getContextClassLoader());
+ }
+
+
factory.setValidating(false);
factory.setNamespaceAware(true);
try
{
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- if (Boolean.getBoolean(DISABLE_DEFERRED_NODE_EXPANSION))
+ if (disableDeferedNodeExpansion)
{
factory.setFeature(DEFER_NODE_EXPANSION_FEATURE, false);
}
Deleted: common/trunk/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java 2010-01-26 15:19:31 UTC (rev 11489)
+++ common/trunk/src/main/java/org/jboss/wsf/common/JBossWSDocumentBuilderFactory.java 2010-01-26 15:29:45 UTC (rev 11490)
@@ -1,492 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.wsf.common;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.WeakHashMap;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.validation.Schema;
-
-import org.jboss.logging.Logger;
-
-/**
- * A thread-safe {@link DocumentBuilderFactory} that also adds a caching system
- * for preventing useless access to the filesystem due to the Service API when
- * the same context classloader is in place.
- *
- * @author alessio.soldano(a)jboss.com
- * @since 22-Dec-2009
- *
- */
-public class JBossWSDocumentBuilderFactory extends DocumentBuilderFactory
-{
- private static Logger log = Logger.getLogger(JBossWSDocumentBuilderFactory.class);
- private static final String PROPERTY_NAME = "javax.xml.parsers.DocumentBuilderFactory";
- private static final boolean useJaxpProperty;
- /**
- * A weak hash map that keeps DocumentBuilderFactory instances for each classloader.
- * Weak keys are used to remove entries when classloaders are garbage collected.
- *
- * No need for a synchronized map as this accessed from the
- * static synchronized newInstance newInstance method.
- */
- private static Map<ClassLoader, JBossWSDocumentBuilderFactory> factoryMap = new WeakHashMap<ClassLoader, JBossWSDocumentBuilderFactory>();
-
- private final DocumentBuilderFactory delegate;
-
- //ThreadLocal attributes and features maps required to achieve thread safety
- private ThreadLocal<DocumentBuilderFactoryFields> fields = new ThreadLocal<DocumentBuilderFactoryFields>() {
- @Override
- protected DocumentBuilderFactoryFields initialValue()
- {
- return new DocumentBuilderFactoryFields();
- }
- };
-
- static
- {
- // Use the properties file "lib/jaxp.properties" in the JRE directory.
- // This configuration file is in standard java.util.Properties format and contains the fully
- // qualified name of the implementation class with the key being the system property defined above.
- PrivilegedAction<Object> action = new PropertyAccessAction("java.home");
- String javaHome = (String)AccessController.doPrivileged(action);
- File jaxmFile = new File(javaHome + "/lib/jaxp.properties");
- if ((Boolean)AccessController.doPrivileged(new PropertyFileExistAction(jaxmFile)))
- {
- String factoryName = null;
- boolean error = false;
- try
- {
- action = new PropertyFileAccessAction(jaxmFile.getCanonicalPath());
- Properties jaxmProperties = (Properties)AccessController.doPrivileged(action);
- factoryName = jaxmProperties.getProperty(PROPERTY_NAME);
- }
- catch (IOException e)
- {
- log.warn("Can't read " + jaxmFile);
- error = true;
- }
- finally
- {
- useJaxpProperty = (error || (factoryName != null));
- }
- }
- else
- {
- useJaxpProperty = false;
- }
- }
-
- private JBossWSDocumentBuilderFactory(DocumentBuilderFactory delegate)
- {
- this.delegate = delegate;
- }
-
- @Override
- public Object getAttribute(String name) throws IllegalArgumentException
- {
- return fields.get().getAttribute(name);
- }
-
- @Override
- public boolean getFeature(String name) throws ParserConfigurationException
- {
- return fields.get().getFeature(name);
- }
-
- /**
- * The creation method for the document builder; it's synchronized to allow us configuring the underlying
- * DocumentBuilderFactory and delegate to it in a thread safe way.
- *
- */
- @Override
- public synchronized DocumentBuilder newDocumentBuilder() throws ParserConfigurationException
- {
- DocumentBuilderFactoryFields currentFields = fields.get();
- currentFields.copyTo(delegate);
- return delegate.newDocumentBuilder();
- }
-
- @Override
- public void setAttribute(String name, Object value) throws IllegalArgumentException
- {
- fields.get().setAttribute(name, value);
- }
-
- @Override
- public void setFeature(String name, boolean value) throws ParserConfigurationException
- {
- fields.get().setFeature(name, value);
- }
-
- @Override
- public boolean isCoalescing()
- {
- return fields.get().isCoalescing();
- }
-
- @Override
- public void setCoalescing(boolean coalescing)
- {
- fields.get().setCoalescing(coalescing);
- }
-
- @Override
- public boolean isExpandEntityReferences()
- {
- return fields.get().isExpandEntityReferences();
- }
-
- @Override
- public void setExpandEntityReferences(boolean expandEntityReferences)
- {
- fields.get().setExpandEntityReferences(expandEntityReferences);
- }
-
- @Override
- public boolean isIgnoringComments()
- {
- return fields.get().isIgnoringComments();
- }
-
- @Override
- public void setIgnoringComments(boolean ignoringComments)
- {
- fields.get().setIgnoringComments(ignoringComments);
- }
-
- @Override
- public boolean isIgnoringElementContentWhitespace()
- {
- return fields.get().isIgnoringElementContentWhitespace();
- }
-
- @Override
- public void setIgnoringElementContentWhitespace(boolean ignoringElementContentWhitespace)
- {
- fields.get().setIgnoringElementContentWhitespace(ignoringElementContentWhitespace);
- }
-
- @Override
- public boolean isNamespaceAware()
- {
- return fields.get().isNamespaceAware();
- }
-
- @Override
- public void setNamespaceAware(boolean namespaceAware)
- {
- fields.get().setNamespaceAware(namespaceAware);
- }
-
- @Override
- public Schema getSchema()
- {
- return fields.get().getSchema();
- }
-
- @Override
- public void setSchema(Schema schema)
- {
- fields.get().setSchema(schema);
- }
-
- @Override
- public boolean isValidating()
- {
- return fields.get().isValidating();
- }
-
- @Override
- public void setValidating(boolean validating)
- {
- fields.get().setValidating(validating);
- }
-
- @Override
- public boolean isXIncludeAware()
- {
- return fields.get().isXIncludeAware();
- }
-
- @Override
- public void setXIncludeAware(boolean includeAware)
- {
- fields.get().setXIncludeAware(includeAware);
- }
-
- /**
- * The {@link DocumentBuilderFactory#newInstance()} documentation defines the retrieval algorithm:
- *
- * 1) Use the javax.xml.parsers.DocumentBuilderFactory system property.
- * 2) Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format
- * and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties
- * file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first
- * attempt is made to read from it, no further attempts are made to check for its existence. It is not possible to change the value of any
- * property in jaxp.properties after it has been read for the first time.
- * 3) Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for a
- * classname in the file META-INF/services/javax.xml.parsers.DocumentBuilderFactory in jars available to the runtime.
- * 4) Platform default DocumentBuilderFactory instance.
- *
- * So we basically check if 1) or 2) applies: if yes, we simply delegate to the DocumentBuilderFactory, otherwise we first try using our classloader
- * cache and delegate to the DocumentBuilderFactory only in case of a miss in the cache. Then we wrap up the result into a JBossWSDocumentBuilderFactory
- * instance.
- *
- * @return a DocumentBuilderFactoryInstance
- */
- public static synchronized JBossWSDocumentBuilderFactory newInstance()
- {
- if (useJaxpProperty || getFactoryNameFromSystemProperty() != null)
- {
- return new JBossWSDocumentBuilderFactory(DocumentBuilderFactory.newInstance());
- }
- ClassLoader classLoader = SecurityActions.getContextClassLoader();
- JBossWSDocumentBuilderFactory factory = factoryMap.get(classLoader);
- if (factory == null)
- {
- factory = new JBossWSDocumentBuilderFactory(DocumentBuilderFactory.newInstance());
- factoryMap.put(classLoader, factory);
- }
- return factory;
- }
-
- private static String getFactoryNameFromSystemProperty()
- {
- PrivilegedAction<Object> action = new PropertyAccessAction(PROPERTY_NAME);
- return (String)AccessController.doPrivileged(action);
- }
-
-
- //--------------------------------- Utility privileged actions
-
- private static class PropertyAccessAction implements PrivilegedAction<Object>
- {
- private String name;
-
- PropertyAccessAction(String name)
- {
- this.name = name;
- }
-
- public Object run()
- {
- return System.getProperty(name);
- }
- }
-
- private static class PropertyFileAccessAction implements PrivilegedAction<Object>
- {
- private String filename;
-
- PropertyFileAccessAction(String filename)
- {
- this.filename = filename;
- }
-
- public Object run()
- {
- InputStream inStream = null;
- try
- {
- inStream = new FileInputStream(filename);
- Properties props = new Properties();
- props.load(inStream);
- return props;
- }
- catch (IOException ex)
- {
- throw new SecurityException("Cannot load properties: " + filename, ex);
- }
- finally
- {
- try
- {
- inStream.close();
- }
- catch (Exception e) {} //ignore
- }
- }
- }
-
- private static class PropertyFileExistAction implements PrivilegedAction<Object>
- {
- private File file;
-
- PropertyFileExistAction(File file)
- {
- this.file = file;
- }
-
- public Object run()
- {
- return file.exists();
- }
- }
-
- /**
- * A utility class for storing the document builder factory fields in the ThreadLocal
- */
- private static class DocumentBuilderFactoryFields {
- private boolean coalescing = false;
- private boolean expandEntityReferences = true;
- private boolean ignoringComments = false;
- private boolean ignoringElementContentWhitespace = false;
- private boolean namespaceAware = false;
- private Schema schema = null;
- private boolean validating = false;
- private boolean XIncludeAware = false;
- private Map<String, Object> attributes = new HashMap<String, Object>();
- private Map<String, Boolean> features = new HashMap<String, Boolean>();
-
- public void copyTo(DocumentBuilderFactory target) throws ParserConfigurationException
- {
- target.setCoalescing(coalescing);
- target.setExpandEntityReferences(expandEntityReferences);
- target.setIgnoringComments(ignoringComments);
- target.setIgnoringElementContentWhitespace(ignoringElementContentWhitespace);
- target.setNamespaceAware(namespaceAware);
- target.setSchema(schema);
- target.setValidating(validating);
- target.setXIncludeAware(XIncludeAware);
- for (String key : attributes.keySet())
- {
- target.setAttribute(key, attributes.get(key));
- }
- for (String key : features.keySet())
- {
- target.setFeature(key, features.get(key));
- }
- }
-
- public Object getAttribute(String name)
- {
- return attributes.get(name);
- }
-
- public Boolean getFeature(String name)
- {
- return features.get(name);
- }
-
- public void setAttribute(String key, Object value)
- {
- this.attributes.put(key, value);
- }
-
- public void setFeature(String key, Boolean value)
- {
- this.features.put(key, value);
- }
-
- public boolean isCoalescing()
- {
- return coalescing;
- }
-
- public void setCoalescing(boolean coalescing)
- {
- this.coalescing = coalescing;
- }
-
- public boolean isExpandEntityReferences()
- {
- return expandEntityReferences;
- }
-
- public void setExpandEntityReferences(boolean expandEntityReferences)
- {
- this.expandEntityReferences = expandEntityReferences;
- }
-
- public boolean isIgnoringComments()
- {
- return ignoringComments;
- }
-
- public void setIgnoringComments(boolean ignoringComments)
- {
- this.ignoringComments = ignoringComments;
- }
-
- public boolean isIgnoringElementContentWhitespace()
- {
- return ignoringElementContentWhitespace;
- }
-
- public void setIgnoringElementContentWhitespace(boolean ignoringElementContentWhitespace)
- {
- this.ignoringElementContentWhitespace = ignoringElementContentWhitespace;
- }
-
- public boolean isNamespaceAware()
- {
- return namespaceAware;
- }
-
- public void setNamespaceAware(boolean namespaceAware)
- {
- this.namespaceAware = namespaceAware;
- }
-
- public Schema getSchema()
- {
- return schema;
- }
-
- public void setSchema(Schema schema)
- {
- this.schema = schema;
- }
-
- public boolean isValidating()
- {
- return validating;
- }
-
- public void setValidating(boolean validating)
- {
- this.validating = validating;
- }
-
- public boolean isXIncludeAware()
- {
- return XIncludeAware;
- }
-
- public void setXIncludeAware(boolean includeAware)
- {
- XIncludeAware = includeAware;
- }
- }
-
-}
Modified: common/trunk/src/main/java/org/jboss/wsf/common/SecurityActions.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/SecurityActions.java 2010-01-26 15:19:31 UTC (rev 11489)
+++ common/trunk/src/main/java/org/jboss/wsf/common/SecurityActions.java 2010-01-26 15:29:45 UTC (rev 11490)
@@ -89,4 +89,23 @@
});
}
}
+
+ /**
+ * Return the current value of the specified system property
+ *
+ * @param name
+ * @param defaultValue
+ * @return
+ */
+ static String getSystemProperty(final String name, final String defaultValue)
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
}
\ No newline at end of file
Deleted: common/trunk/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java
===================================================================
--- common/trunk/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java 2010-01-26 15:19:31 UTC (rev 11489)
+++ common/trunk/src/test/java/org/jboss/test/ws/common/utils/DummyDocumentBuilderFactory.java 2010-01-26 15:29:45 UTC (rev 11490)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.ws.common.utils;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-/**
- * A dummy document builder factory just for testing in {@link JBossWSDocumentBuilderFactoryTestCase}.
- *
- * @author alessio.soldano(a)jboss.com
- * @since 23-Dec-2009
- *
- */
-public class DummyDocumentBuilderFactory extends DocumentBuilderFactory
-{
- @Override
- public Object getAttribute(String name) throws IllegalArgumentException
- {
- return null;
- }
-
- @Override
- public boolean getFeature(String name) throws ParserConfigurationException
- {
- return false;
- }
-
- @Override
- public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException
- {
- return null;
- }
-
- @Override
- public void setAttribute(String name, Object value) throws IllegalArgumentException
- {
- }
-
- @Override
- public void setFeature(String name, boolean value) throws ParserConfigurationException
- {
- }
-}
Deleted: common/trunk/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java
===================================================================
--- common/trunk/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java 2010-01-26 15:19:31 UTC (rev 11489)
+++ common/trunk/src/test/java/org/jboss/test/ws/common/utils/JBossWSDocumentBuilderFactoryTestCase.java 2010-01-26 15:29:45 UTC (rev 11490)
@@ -1,191 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.ws.common.utils;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import junit.framework.TestCase;
-
-import org.jboss.wsf.common.JBossWSDocumentBuilderFactory;
-
-/**
- * Tests for the JBossWSDocumentBuilderFactory
- *
- * @author alessio.soldano(a)jboss.com
- * @since 23-Dec-2009
- *
- */
-public class JBossWSDocumentBuilderFactoryTestCase extends TestCase
-{
- public void testCaching() throws Exception
- {
- final String propName = "javax.xml.parsers.DocumentBuilderFactory";
- String origValue = System.getProperty(propName);
- try
- {
- //remove system prop if any, to get the same factory for a given classloader
- System.getProperties().remove(propName);
- DocumentBuilderFactory factory1 = JBossWSDocumentBuilderFactory.newInstance();
- DocumentBuilderFactory factory2 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected the same factory", factory1.equals(factory2));
-
- //set the system prop, we should get different factories every time as the classloader based cache is by-passed
- System.setProperty(propName, DummyDocumentBuilderFactory.class.getCanonicalName());
- DocumentBuilderFactory factory3 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected different factories", !factory3.equals(factory1));
- assertTrue("Expected different factories", !factory3.equals(factory2));
- DocumentBuilderFactory factory4 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected different factories", !factory4.equals(factory1));
- assertTrue("Expected different factories", !factory4.equals(factory2));
- assertTrue("Expected different factories", !factory4.equals(factory3));
-
- //remove the prop again, we should get the first factory
- System.getProperties().remove(propName);
- DocumentBuilderFactory factory5 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected the same factory", factory5.equals(factory1));
-
- ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- //change context classloader
- Thread.currentThread().setContextClassLoader(new TestClassLoader(origLoader));
- DocumentBuilderFactory factory6 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected different factories", !factory6.equals(factory1));
- DocumentBuilderFactory factory7 = JBossWSDocumentBuilderFactory.newInstance();
- assertTrue("Expected the same factory", factory7.equals(factory6));
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(origLoader);
- }
- }
- finally
- {
- if (origValue == null)
- {
- System.getProperties().remove(propName);
- }
- else
- {
- System.setProperty(propName, origValue);
- }
- }
- }
-
- public void testThreadSafety() throws Exception
- {
- DocumentBuilderFactory factory = JBossWSDocumentBuilderFactory.newInstance();
- List<Callable<Boolean>> callables = new LinkedList<Callable<Boolean>>();
- for (int j = 0; j < 3; j++)
- {
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, true, true, true));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, true, true, false));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, true, false, false));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, false, false));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, false, true));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, true, true));
- }
- for (int i = 0; i < 10; i++)
- {
- callables.add(new TestCallable(factory, false, true, false));
- }
- }
- ExecutorService es = Executors.newFixedThreadPool(210);
- List<Future<Boolean>> futures = es.invokeAll(callables);
- for (Future<Boolean> f : futures)
- {
- assertTrue(f.get());
- }
- }
-
- /**
- * A Callable that use the provided thread safe factory to create a document builder and verifies it has the required configuration
- */
- public static class TestCallable implements Callable<Boolean>
- {
- private final DocumentBuilderFactory factory;
- private final Boolean namespaceAware;
- private final Boolean validating;
- private final Boolean XIncludeAware;
-
- public TestCallable(DocumentBuilderFactory factory, boolean namespaceAware, boolean validating, boolean includeAware)
- {
- this.factory = factory;
- this.namespaceAware = namespaceAware;
- this.validating = validating;
- this.XIncludeAware = includeAware;
- }
-
- public Boolean call() throws Exception
- {
- factory.setNamespaceAware(namespaceAware);
- factory.setValidating(validating);
- factory.setXIncludeAware(XIncludeAware);
- DocumentBuilder builder = factory.newDocumentBuilder();
- if (!namespaceAware.equals(builder.isNamespaceAware()))
- return false;
- if (!validating.equals(builder.isValidating()))
- return false;
- if (!XIncludeAware.equals(builder.isXIncludeAware()))
- return false;
- return true;
- }
-
- }
-
- /**
- * A ClassLoader doing nothing except falling back to its parent
- */
- public static class TestClassLoader extends ClassLoader
- {
- public TestClassLoader(ClassLoader parent)
- {
- super(parent);
- }
- }
-
-}
15 years