Author: alessio.soldano(a)jboss.com
Date: 2012-01-30 11:41:54 -0500 (Mon, 30 Jan 2012)
New Revision: 15543
Added:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/SecurityActions.java
Modified:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/DOMUtils.java
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/ws-addr.xsd
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/wsdl20.xsd
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxrpc/jbws153/WEB-INF/web.xml
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/samples/wseventing/WEB-INF/wsdl/ws-addr.xsd
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/wseventing/WEB-INF/wsdl/ws-addr.xsd
Log:
[JBPAPP-7127] Caching default document builder factory to improve performances
Modified:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/DOMUtils.java
===================================================================
---
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/DOMUtils.java 2012-01-30
16:23:50 UTC (rev 15542)
+++
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/DOMUtils.java 2012-01-30
16:41:54 UTC (rev 15543)
@@ -67,7 +67,32 @@
public final class DOMUtils
{
private static Logger log = Logger.getLogger(DOMUtils.class);
+
+ private static final String ENABLE_DOCTYPE_DECL =
"org.jboss.ws.enable_doctype_decl";
+ private static final String DISALLOW_DOCTYPE_DECL_FEATURE =
"http://apache.org/xml/features/disallow-doctype-decl";
+
+ private static DocumentBuilderFactory documentBuilderFactory;
+
+ 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);
+ 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 documentThreadLocal = new ThreadLocal();
private static ThreadLocal builderThreadLocal = new ThreadLocal() {
@@ -75,9 +100,21 @@
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
+
+ //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())
+ {
+ threadFactory = documentBuilderFactory ;
+ }
+ else
+ {
+ threadFactory = factory ;
+ initializeFactory(threadFactory) ;
+ }
+
+ DocumentBuilder builder = threadFactory.newDocumentBuilder();
builder.setEntityResolver(new JBossWSEntityResolver());
return builder;
}
@@ -93,6 +130,24 @@
{
}
+ private static void initializeFactory(final DocumentBuilderFactory factory)
+ {
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+
+ try
+ {
+ if (!enableDoctypeDeclaration)
+ {
+ factory.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, true);
+ }
+ }
+ catch (ParserConfigurationException pce)
+ {
+ log.error(pce);
+ }
+ }
+
public static void clearThreadLocals()
{
documentThreadLocal.remove();
Added:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/SecurityActions.java
===================================================================
---
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/SecurityActions.java
(rev 0)
+++
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/java/org/jboss/ws/core/utils/SecurityActions.java 2012-01-30
16:41:54 UTC (rev 15543)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ws.core.utils;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * Security actions for this package
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 19-Jun-2009
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * 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
+ * @return
+ * @throws PrivilegedActionException
+ */
+ static Class<?> loadClass(final ClassLoader cl, final String name) throws
PrivilegedActionException, ClassNotFoundException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return cl.loadClass(name);
+ }
+ else
+ {
+ return AccessController.doPrivileged(new
PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws PrivilegedActionException
+ {
+ try
+ {
+ return cl.loadClass(name);
+ }
+ catch (Exception e)
+ {
+ throw new PrivilegedActionException(e);
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * 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
Modified:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/ws-addr.xsd
===================================================================
---
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/ws-addr.xsd 2012-01-30
16:23:50 UTC (rev 15542)
+++
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/ws-addr.xsd 2012-01-30
16:41:54 UTC (rev 15543)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd">
+<!--DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd"-->
<!--
W3C XML Schema defined in the Web Services Addressing 1.0 specification
http://www.w3.org/TR/ws-addr-core
Modified:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/wsdl20.xsd
===================================================================
---
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/wsdl20.xsd 2012-01-30
16:23:50 UTC (rev 15542)
+++
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-core/src/resources/schema/wsdl20.xsd 2012-01-30
16:41:54 UTC (rev 15543)
@@ -15,7 +15,7 @@
[1]
http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
-->
-<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd">
+<!--DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd"-->
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://www.w3.org/2003/11/wsdl"
targetNamespace="http://www.w3.org/2003/11/wsdl"
elementFormDefault="qualified" finalDefault=""
blockDefault="" attributeFormDefault="unqualified">
Modified:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxrpc/jbws153/WEB-INF/web.xml
===================================================================
---
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxrpc/jbws153/WEB-INF/web.xml 2012-01-30
16:23:50 UTC (rev 15542)
+++
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxrpc/jbws153/WEB-INF/web.xml 2012-01-30
16:41:54 UTC (rev 15543)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+<!--DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"-->
<web-app id="WebApp_ID">
<display-name>include-test</display-name>
Modified:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/samples/wseventing/WEB-INF/wsdl/ws-addr.xsd
===================================================================
---
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/samples/wseventing/WEB-INF/wsdl/ws-addr.xsd 2012-01-30
16:23:50 UTC (rev 15542)
+++
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/samples/wseventing/WEB-INF/wsdl/ws-addr.xsd 2012-01-30
16:41:54 UTC (rev 15543)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd">
+<!--DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd"-->
<!--
W3C XML Schema defined in the Web Services Addressing 1.0 specification
http://www.w3.org/TR/ws-addr-core
Modified:
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/wseventing/WEB-INF/wsdl/ws-addr.xsd
===================================================================
---
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/wseventing/WEB-INF/wsdl/ws-addr.xsd 2012-01-30
16:23:50 UTC (rev 15542)
+++
legacy/branches/jbossws-1.2.1.GA_CP/jbossws-tests/src/resources/jaxws/wseventing/WEB-INF/wsdl/ws-addr.xsd 2012-01-30
16:41:54 UTC (rev 15543)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd">
+<!--DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN"
"http://www.w3.org/2001/XMLSchema.dtd"-->
<!--
W3C XML Schema defined in the Web Services Addressing 1.0 specification
http://www.w3.org/TR/ws-addr-core