JBossWS SVN: r14918 - common/trunk/src/main/java/org/jboss/ws/common.
by jbossws-commits@lists.jboss.org
Author: alessio.soldano(a)jboss.com
Date: 2011-09-01 07:07:51 -0400 (Thu, 01 Sep 2011)
New Revision: 14918
Modified:
common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java
common/trunk/src/main/java/org/jboss/ws/common/SecurityActions.java
Log:
[JBWS-3344] Caching default document builder factory to improve performances
Modified: common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java 2011-09-01 07:21:16 UTC (rev 14917)
+++ common/trunk/src/main/java/org/jboss/ws/common/DOMUtils.java 2011-09-01 11:07:51 UTC (rev 14918)
@@ -75,59 +75,64 @@
private static final String DISALLOW_DOCTYPE_DECL_FEATURE = "http://apache.org/xml/features/disallow-doctype-decl";
private static String documentBuilderFactoryName;
+ private static DocumentBuilderFactory documentBuilderFactory;
private static final boolean alwaysResolveFactoryName = Boolean.getBoolean(Constants.ALWAYS_RESOLVE_DOCUMENT_BUILDER_FACTORY);
private static final boolean disableDeferedNodeExpansion = Boolean.getBoolean(DISABLE_DEFERRED_NODE_EXPANSION);
private static final boolean enableDoctypeDeclaration = Boolean.getBoolean(ENABLE_DOCTYPE_DECL);
+ static
+ {
+ //load default document builder factory using the DOMUtils' defining classloader
+ final ClassLoader classLoader = SecurityActions.getContextClassLoader();
+ SecurityActions.setContextClassLoader(DOMUtils.class.getClassLoader());
+ try
+ {
+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+ initializeFactory(factory);
+ documentBuilderFactoryName = factory.getClass().getCanonicalName();
+ documentBuilderFactory = factory;
+ }
+ finally
+ {
+ SecurityActions.setContextClassLoader(classLoader);
+ }
+ }
+
// 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>() {
protected DocumentBuilder initialValue()
{
- DocumentBuilderFactory factory = null;
try
{
- //slow
- //factory = DocumentBuilderFactory.newInstance();
-
- //fast (requires JDK6 or greater)
- if (documentBuilderFactoryName == null || alwaysResolveFactoryName)
+ DocumentBuilderFactory factory = null;
+ if (alwaysResolveFactoryName)
{
factory = DocumentBuilderFactory.newInstance();
- if (!alwaysResolveFactoryName)
- {
- documentBuilderFactoryName = factory.getClass().getCanonicalName();
- }
}
else
{
+ //this is faster then DocumentBuilderFactory.newInstance(); but requires JDK6 or greater
factory = DocumentBuilderFactory.newInstance(documentBuilderFactoryName, SecurityActions.getContextClassLoader());
}
-
- factory.setValidating(false);
- factory.setNamespaceAware(true);
- factory.setExpandEntityReferences(false);
-
- try
+ //check if the factory we'd get for this thread is equivalent to the default one;
+ //in that case re-use the default one and skip the initialization, which is time-consuming
+ final DocumentBuilderFactory threadFactory ;
+ if (factory.getClass().getClassLoader() == documentBuilderFactory.getClass().getClassLoader() &&
+ (!alwaysResolveFactoryName || documentBuilderFactoryName.equals(factory.getClass().getCanonicalName())))
{
- factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- if (disableDeferedNodeExpansion)
- {
- factory.setFeature(DEFER_NODE_EXPANSION_FEATURE, false);
- }
- if (!enableDoctypeDeclaration)
- {
- factory.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, true);
- }
+ threadFactory = documentBuilderFactory ;
}
- catch (ParserConfigurationException pce)
+ else
{
- log.fatal("Serious security risk, not able to configure parser feature", pce);
+ threadFactory = factory ;
+ initializeFactory(threadFactory) ;
}
- DocumentBuilder builder = factory.newDocumentBuilder();
+ DocumentBuilder builder = threadFactory.newDocumentBuilder();
setEntityResolver(builder);
return builder;
}
@@ -172,6 +177,30 @@
}
};
+ private static void initializeFactory(final DocumentBuilderFactory factory)
+ {
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ factory.setExpandEntityReferences(false);
+
+ try
+ {
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ if (disableDeferedNodeExpansion)
+ {
+ factory.setFeature(DEFER_NODE_EXPANSION_FEATURE, false);
+ }
+ if (!enableDoctypeDeclaration)
+ {
+ factory.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, true);
+ }
+ }
+ catch (ParserConfigurationException pce)
+ {
+ log.error(pce);
+ }
+ }
+
public static void clearThreadLocals()
{
documentThreadLocal.remove();
Modified: common/trunk/src/main/java/org/jboss/ws/common/SecurityActions.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/SecurityActions.java 2011-09-01 07:21:16 UTC (rev 14917)
+++ common/trunk/src/main/java/org/jboss/ws/common/SecurityActions.java 2011-09-01 11:07:51 UTC (rev 14918)
@@ -57,8 +57,32 @@
});
}
}
-
+
/**
+ * Set context classloader.
+ *
+ * @param classLoader the context classloader
+ */
+ static void setContextClassLoader(final ClassLoader classLoader)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return null;
+ }
+ });
+ }
+ }
+
+ /**
* Load a class using the provided classloader
*
* @param name
13 years, 4 months
JBossWS SVN: r14917 - common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment.
by jbossws-commits@lists.jboss.org
Author: jim.ma
Date: 2011-09-01 03:21:16 -0400 (Thu, 01 Sep 2011)
New Revision: 14917
Modified:
common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java
common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/ContextRootDeploymentAspect.java
common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/DefaultService.java
common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointAddressDeploymentAspect.java
common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointNameDeploymentAspect.java
common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java
common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java
Log:
JBWS-3346:Change the implemenation
Modified: common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java
===================================================================
--- common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java 2011-09-01 07:12:23 UTC (rev 14916)
+++ common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/AbstractDefaultEndpoint.java 2011-09-01 07:21:16 UTC (rev 14917)
@@ -37,6 +37,7 @@
import org.jboss.wsf.spi.deployment.AbstractExtensible;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.deployment.Endpoint.EndpointState;
+import org.jboss.wsf.spi.deployment.Endpoint.EndpointType;
import org.jboss.wsf.spi.deployment.LifecycleHandler;
import org.jboss.wsf.spi.deployment.Service;
import org.jboss.wsf.spi.deployment.WSFDeploymentException;
@@ -68,6 +69,8 @@
protected String address;
protected List<RecordProcessor> recordProcessors = new Vector<RecordProcessor>();
protected SecurityDomainContext securityDomainContext;
+ protected EndpointType type;
+ protected String contextRoot;
AbstractDefaultEndpoint(String targetBean)
{
@@ -295,5 +298,22 @@
{
this.securityDomainContext = securityDomainContext;
}
-
+ public void setType(EndpointType type)
+ {
+ this.type = type;
+ }
+
+ public EndpointType getType()
+ {
+ return this.type;
+ }
+
+ public String getContextRoot() {
+ return this.contextRoot;
+ }
+
+ public void setContextRoot(String contextRoot) {
+ this.contextRoot = contextRoot;
+ }
+
}
Modified: common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/ContextRootDeploymentAspect.java
===================================================================
--- common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/ContextRootDeploymentAspect.java 2011-09-01 07:12:23 UTC (rev 14916)
+++ common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/ContextRootDeploymentAspect.java 2011-09-01 07:21:16 UTC (rev 14917)
@@ -47,7 +47,9 @@
@Override
public void start(Deployment dep)
{
- String contextRoot = dep.getService().getContextRoot();
+ //TODO: set contextRoot to each endpoint
+ String contextRoot = null;
+ //dep.getService().getContextRoot();
if (contextRoot == null)
{
contextRoot = getExplicitContextRoot(dep);
@@ -58,7 +60,7 @@
if (contextRoot.startsWith("/") == false)
contextRoot = "/" + contextRoot;
- dep.getService().setContextRoot(contextRoot);
+ // dep.getService().setContextRoot(contextRoot);
}
}
Modified: common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/DefaultService.java
===================================================================
--- common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/DefaultService.java 2011-09-01 07:12:23 UTC (rev 14916)
+++ common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/DefaultService.java 2011-09-01 07:21:16 UTC (rev 14917)
@@ -25,6 +25,7 @@
import org.jboss.wsf.spi.deployment.Service;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.deployment.EndpointTypeFilter;
import java.util.LinkedList;
import java.util.List;
@@ -69,6 +70,20 @@
{
return endpoints;
}
+
+ public List<Endpoint> getEndpoints(EndpointTypeFilter filter)
+ {
+ List<Endpoint> result = new LinkedList<Endpoint>();
+ for (Endpoint endpoint : endpoints)
+ {
+ if (filter.accept(endpoint.getType()))
+ {
+ result.add(endpoint);
+ }
+ }
+ return result;
+ }
+
public Endpoint getEndpointByName(String shortName)
{
Modified: common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointAddressDeploymentAspect.java
===================================================================
--- common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointAddressDeploymentAspect.java 2011-09-01 07:12:23 UTC (rev 14916)
+++ common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointAddressDeploymentAspect.java 2011-09-01 07:21:16 UTC (rev 14917)
@@ -57,7 +57,9 @@
@Override
public void start(Deployment dep)
{
- String contextRoot = dep.getService().getContextRoot();
+ //TODO:set contextRoot to eache endpoint
+ //String contextRoot = dep.getService().getContextRoot();
+ String contextRoot = "";
if (contextRoot == null)
throw new IllegalStateException(BundleUtils.getMessage(bundle, "CANNOT_OBTAIN_CONTEXT_ROOT"));
Modified: common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointNameDeploymentAspect.java
===================================================================
--- common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointNameDeploymentAspect.java 2011-09-01 07:12:23 UTC (rev 14916)
+++ common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/EndpointNameDeploymentAspect.java 2011-09-01 07:21:16 UTC (rev 14917)
@@ -44,7 +44,9 @@
@Override
public void start(Deployment dep)
{
- String contextRoot = dep.getService().getContextRoot();
+ //TODO:set contextRoot to eache endpoint
+ //String contextRoot = dep.getService().getContextRoot();
+ String contextRoot = "";
if (contextRoot == null || contextRoot.startsWith("/") == false)
throw new IllegalStateException(BundleUtils.getMessage(bundle, "CONTEXT_ROOT_EXPECTED_TO_START_WITH_LEADING_SLASH", contextRoot));
Modified: common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java
===================================================================
--- common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java 2011-09-01 07:12:23 UTC (rev 14916)
+++ common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/JAXBIntroDeploymentAspect.java 2011-09-01 07:21:16 UTC (rev 14917)
@@ -107,7 +107,8 @@
try {
introsConfigStream.close();
} catch (IOException e) {
- logger.error(BundleUtils.getMessage(bundle, "ERROR_CLOSING_JAXB_INTRODUCTIONS", deployment.getService().getContextRoot() ), e);
+ //TODO:logger.error(BundleUtils.getMessage(bundle, "ERROR_CLOSING_JAXB_INTRODUCTIONS", deployment.getService().getContextRoot() ), e);
+ logger.error(BundleUtils.getMessage(bundle, "ERROR_CLOSING_JAXB_INTRODUCTIONS", deployment.getService()), e);
}
}
}
Modified: common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java
===================================================================
--- common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java 2011-09-01 07:12:23 UTC (rev 14916)
+++ common/branches/JBWS-3343/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java 2011-09-01 07:21:16 UTC (rev 14917)
@@ -94,7 +94,9 @@
urlPattern = bmd.getPortComponentURI();
if (urlPattern != null)
{
- String contextRoot = dep.getService().getContextRoot();
+ //TODO:set contextRoot to eache endpoint
+ //String contextRoot = dep.getService().getContextRoot();
+ String contextRoot = null;
if (urlPattern.startsWith("/") == false)
urlPattern = "/" + urlPattern;
13 years, 4 months
JBossWS SVN: r14916 - spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment.
by jbossws-commits@lists.jboss.org
Author: jim.ma
Date: 2011-09-01 03:12:23 -0400 (Thu, 01 Sep 2011)
New Revision: 14916
Added:
spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/EndpointTypeFilter.java
Modified:
spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Endpoint.java
spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Service.java
Log:
JBWS-3346:Add EndpointType and remove the context root from service
Modified: spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Endpoint.java
===================================================================
--- spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Endpoint.java 2011-09-01 05:10:22 UTC (rev 14915)
+++ spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Endpoint.java 2011-09-01 07:12:23 UTC (rev 14916)
@@ -46,6 +46,11 @@
static final String SEPID_PROPERTY_ENDPOINT = "endpoint";
static final String SEPID_DOMAIN_ENDPOINT = SEPID_DOMAIN + "." + SEPID_PROPERTY_ENDPOINT;
+
+ public enum EndpointType
+ {
+ JAXRPC_JSE, JAXRPC_EJB21, JAXWS_JSE, JAXWS_EJB3, JAXWS_JMS;
+ };
public enum EndpointState
{
@@ -132,4 +137,18 @@
/** Set security domain context */
void setSecurityDomainContext(SecurityDomainContext context);
+
+
+ /** Set endpoint type */
+ void setType(EndpointType type);
+
+ /** get endpoint type */
+ EndpointType getType();
+
+
+ /** Get the context root for this service */
+ String getContextRoot();
+
+ /** Set the context root for this service */
+ void setContextRoot(String contextRoot);
}
Added: spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/EndpointTypeFilter.java
===================================================================
--- spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/EndpointTypeFilter.java (rev 0)
+++ spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/EndpointTypeFilter.java 2011-09-01 07:12:23 UTC (rev 14916)
@@ -0,0 +1,9 @@
+package org.jboss.wsf.spi.deployment;
+
+import org.jboss.wsf.spi.deployment.Endpoint.EndpointType;
+
+public interface EndpointTypeFilter
+{
+ boolean accept(EndpointType type);
+
+}
Modified: spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Service.java
===================================================================
--- spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Service.java 2011-09-01 05:10:22 UTC (rev 14915)
+++ spi/branches/JBWS-3343/src/main/java/org/jboss/wsf/spi/deployment/Service.java 2011-09-01 07:12:23 UTC (rev 14916)
@@ -23,6 +23,8 @@
import java.util.List;
+import org.jboss.wsf.spi.deployment.Endpoint.EndpointType;
+
/**
* A general service deployment.
*
@@ -42,18 +44,15 @@
/** Add an endpoint to the service */
void addEndpoint(Endpoint endpoint);
- /** Get the list of endpoints */
+ /** Get the list of endpoints*/
List<Endpoint> getEndpoints();
+ /** Get the list of endpoints with EndpointTypeFilter*/
+ List<Endpoint> getEndpoints(EndpointTypeFilter filter);
+
/** Get an endpoint by name */
Endpoint getEndpointByName(String simpleName);
- /** Get the context root for this service */
- String getContextRoot();
-
- /** Set the context root for this service */
- void setContextRoot(String contextRoot);
-
/** Get the virtual hosts for this service */
List<String> getVirtualHosts();
13 years, 4 months
JBossWS SVN: r14915 - common/branches.
by jbossws-commits@lists.jboss.org
Author: jim.ma
Date: 2011-09-01 01:10:22 -0400 (Thu, 01 Sep 2011)
New Revision: 14915
Added:
common/branches/JBWS-3343/
Log:
Create workspace for JBWS-3343
13 years, 4 months
JBossWS SVN: r14914 - spi/branches.
by jbossws-commits@lists.jboss.org
Author: jim.ma
Date: 2011-08-31 22:34:21 -0400 (Wed, 31 Aug 2011)
New Revision: 14914
Added:
spi/branches/JBWS-3343/
Log:
Create workspace for JBWS-3343
13 years, 4 months