Author: alessio.soldano(a)jboss.com
Date: 2011-04-07 09:12:36 -0400 (Thu, 07 Apr 2011)
New Revision: 14024
Added:
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SecurityActions.java
Modified:
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProvider.java
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java
Log:
Adding default classloader provider and adding options for providing the classloader to be
used for SPI resolution
Modified: spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProvider.java
===================================================================
--- spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProvider.java 2011-04-07
13:06:57 UTC (rev 14023)
+++ spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProvider.java 2011-04-07
13:12:36 UTC (rev 14024)
@@ -29,8 +29,25 @@
*/
public abstract class SPIProvider
{
- /*
- * Gets the specified SPI.
- */
- public abstract <T> T getSPI(java.lang.Class<T> spiType);
+ /**
+ * Gets the specified SPI, using the current thread context classloader
+ *
+ * @param <T>
+ * @param spiType
+ * @return
+ */
+ public <T> T getSPI(Class<T> spiType)
+ {
+ return getSPI(spiType, SecurityActions.getContextClassLoader());
+ }
+
+ /**
+ * Gets the specified SPI, using the provided classloader
+ *
+ * @param <T>
+ * @param spiType
+ * @param loader
+ * @return
+ */
+ public abstract <T> T getSPI(Class<T> spiType, ClassLoader loader);
}
Modified: spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java
===================================================================
---
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java 2011-04-07
13:06:57 UTC (rev 14023)
+++
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java 2011-04-07
13:12:36 UTC (rev 14024)
@@ -32,13 +32,28 @@
public abstract class SPIProviderResolver
{
public final static String DEFAULT_SPI_PROVIDER_RESOLVER =
"org.jboss.wsf.framework.DefaultSPIProviderResolver";
-
+
+ /**
+ * Get the SPIProviderResolver instance using the thread context classloader for
lookup
+ *
+ * @return
+ */
public static SPIProviderResolver getInstance()
{
- SPIProviderResolver resolver =
(SPIProviderResolver)ServiceLoader.loadService(SPIProviderResolver.class.getName(),
DEFAULT_SPI_PROVIDER_RESOLVER);
+ return getInstance(SecurityActions.getContextClassLoader());
+ }
+
+ /**
+ * Get the SPIProviderResolver instance using the provided classloader for lookup
+ *
+ * @return
+ */
+ public static SPIProviderResolver getInstance(ClassLoader cl)
+ {
+ SPIProviderResolver resolver =
(SPIProviderResolver)ServiceLoader.loadService(SPIProviderResolver.class.getName(),
DEFAULT_SPI_PROVIDER_RESOLVER, cl);
return resolver;
}
public abstract SPIProvider getProvider();
-
+
}
Added: spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SecurityActions.java
===================================================================
--- spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SecurityActions.java
(rev 0)
+++ spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SecurityActions.java 2011-04-07
13:12:36 UTC (rev 14024)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.spi;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Security actions helper.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 17-Feb-2010
+ */
+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 classloader
+ */
+ static void setContextClassLoader(final ClassLoader classLoader) {
+ if (System.getSecurityManager() == null) {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ } else {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return null;
+ }
+ });
+ }
+ }
+}
Modified:
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java
===================================================================
---
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java 2011-04-07
13:06:57 UTC (rev 14023)
+++
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java 2011-04-07
13:12:36 UTC (rev 14024)
@@ -21,6 +21,9 @@
*/
package org.jboss.wsf.spi.classloading;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
/**
* SPI for getting AS classloaders
*
@@ -30,20 +33,60 @@
*/
public abstract class ClassLoaderProvider
{
- private static ClassLoaderProvider provider = null;
-
+ private static ClassLoaderProvider provider = new ClassLoaderProvider()
+ {
+ @Override
+ public ClassLoader getWebServiceSubsystemClassLoader()
+ {
+ return getContextClassLoader();
+ }
+
+ @Override
+ public ClassLoader getServerIntegrationClassLoader()
+ {
+ return getContextClassLoader();
+ }
+ };
+
public static void setDefaultProvider(ClassLoaderProvider p)
{
provider = p;
}
-
+
public static ClassLoaderProvider getDefaultProvider()
{
return provider;
}
-
+
+ /**
+ * Return the ClassLoader instance having visibility over the application server ws
subsystem only
+ *
+ * @return
+ */
public abstract ClassLoader getWebServiceSubsystemClassLoader();
-
+
+ /**
+ * Return the ClassLoader instance having visibility over the all server side ws
libraries
+ *
+ * @return
+ */
public abstract ClassLoader getServerIntegrationClassLoader();
-
+
+ static ClassLoader getContextClassLoader()
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
}
Modified:
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java
===================================================================
---
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java 2011-04-07
13:06:57 UTC (rev 14023)
+++
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java 2011-04-07
13:12:36 UTC (rev 14024)
@@ -70,7 +70,7 @@
protected ServletDelegate getDelegate(ServletConfig servletConfig)
{
ClassLoaderProvider clProvider = ClassLoaderProvider.getDefaultProvider();
- ClassLoader cl = (clProvider != null) ?
clProvider.getWebServiceSubsystemClassLoader() : getContextClassLoader();
+ ClassLoader cl = clProvider.getWebServiceSubsystemClassLoader();
ServiceLoader<ServletDelegateFactory> sl =
ServiceLoader.load(ServletDelegateFactory.class, cl);
ServletDelegateFactory factory = sl.iterator().next();
return
factory.newServletDelegate(servletConfig.getInitParameter(STACK_SERVLET_DELEGATE_CLASS));