Author: alessio.soldano(a)jboss.com
Date: 2011-04-14 11:28:36 -0400 (Thu, 14 Apr 2011)
New Revision: 14094
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/SecurityActions.java
spi/trunk/src/main/java/org/jboss/wsf/spi/classloading/
spi/trunk/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java
spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java
spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java
spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java
Removed:
spi/trunk/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java
Modified:
spi/trunk/
spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProvider.java
spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java
Log:
[JBWS-3224][JBWS-3265] Isolate deployment classloader from ws server integration
Property changes on: spi/trunk
___________________________________________________________________
Added: svn:mergeinfo
+ /spi/branches/asoldano:14017-14042
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProvider.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProvider.java 2011-04-14 15:25:34 UTC
(rev 14093)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProvider.java 2011-04-14 15:28:36 UTC
(rev 14094)
@@ -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/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java 2011-04-14 15:25:34
UTC (rev 14093)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java 2011-04-14 15:28:36
UTC (rev 14094)
@@ -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();
-
+
}
Copied: spi/trunk/src/main/java/org/jboss/wsf/spi/SecurityActions.java (from rev 14042,
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/SecurityActions.java)
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/SecurityActions.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/SecurityActions.java 2011-04-14 15:28:36 UTC
(rev 14094)
@@ -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;
+ }
+ });
+ }
+ }
+}
Deleted: spi/trunk/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-08
15:49:09 UTC (rev 14042)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java 2011-04-14
15:28:36 UTC (rev 14094)
@@ -1,92 +0,0 @@
-/*
- * 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.classloading;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * SPI for getting AS classloaders
- *
- * @author alessio.soldano(a)jboss.com
- * @since 06-Apr-2011
- *
- */
-public abstract class ClassLoaderProvider
-{
- 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();
- }
- });
- }
- }
-}
Copied: spi/trunk/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java
(from rev 14042,
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java)
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java
(rev 0)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java 2011-04-14
15:28:36 UTC (rev 14094)
@@ -0,0 +1,92 @@
+/*
+ * 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.classloading;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SPI for getting AS classloaders
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Apr-2011
+ *
+ */
+public abstract class ClassLoaderProvider
+{
+ 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();
+ }
+ });
+ }
+ }
+}
Copied: spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java (from
rev 14042,
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java)
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java 2011-04-14
15:28:36 UTC (rev 14094)
@@ -0,0 +1,61 @@
+/*
+ * 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.deployment;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Apr-2011
+ *
+ */
+public interface ServletDelegate
+{
+ public void init(ServletConfig servletConfig) throws ServletException;
+
+ public void destroy();
+
+ public void doHead(HttpServletRequest request, HttpServletResponse response,
ServletContext context)
+ throws ServletException, IOException;
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response,
ServletContext context)
+ throws ServletException, IOException;
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response,
ServletContext context)
+ throws ServletException, IOException;
+
+ public void doPut(HttpServletRequest request, HttpServletResponse response,
ServletContext context)
+ throws ServletException, IOException;
+
+ public void doDelete(HttpServletRequest request, HttpServletResponse response,
ServletContext context)
+ throws ServletException, IOException;
+
+ public void service(HttpServletRequest request, HttpServletResponse response,
ServletContext context)
+ throws ServletException, IOException;
+}
Copied: spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java
(from rev 14042,
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java)
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java
(rev 0)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java 2011-04-14
15:28:36 UTC (rev 14094)
@@ -0,0 +1,34 @@
+/*
+ * 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.deployment;
+
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Apr-2011
+ *
+ */
+public interface ServletDelegateFactory
+{
+ public ServletDelegate newServletDelegate(String delegateClassName);
+}
Copied: spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java (from rev
14042, spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java)
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java 2011-04-14
15:28:36 UTC (rev 14094)
@@ -0,0 +1,153 @@
+/*
+ * 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.deployment;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ServiceLoader;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Apr-2011
+ *
+ */
+public class WSFServlet extends HttpServlet
+{
+ public static final String STACK_SERVLET_DELEGATE_CLASS =
"org.jboss.wsf.spi.deployment.stackServletDelegateClass";
+
+ private ServletDelegate delegate = null;
+
+ @Override
+ public void init(ServletConfig servletConfig) throws ServletException
+ {
+ super.init(servletConfig);
+ delegate = getDelegate(servletConfig);
+ if (delegate != null)
+ {
+ delegate.init(servletConfig);
+ }
+ }
+
+ /**
+ * Creates a ServletDelegate instance according to the STACK_SERVLET_DELEGATE_CLASS
init parameter.
+ * The class is loaded through a ServletDelegateFactory that's retrieved as
follows:
+ * - if a default ClassLoaderProvider is available, the webservice subsystem
classloader from it
+ * is used to lookup the factory
+ * - otherwise the current thread context classloader is used to lookup the factory.
+ *
+ * @param servletConfig
+ * @return the servlet delegate
+ */
+ protected ServletDelegate getDelegate(ServletConfig servletConfig)
+ {
+ ClassLoaderProvider clProvider = ClassLoaderProvider.getDefaultProvider();
+ 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));
+ }
+
+ @Override
+ public void destroy()
+ {
+ if (delegate != null)
+ {
+ delegate.destroy();
+ }
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
+ {
+ if (delegate != null)
+ {
+ delegate.doPost(request, response, getServletContext());
+ }
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
+ {
+ if (delegate != null)
+ {
+ delegate.doGet(request, response, getServletContext());
+ }
+ }
+
+ @Override
+ protected void doPut(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
+ {
+ if (delegate != null)
+ {
+ delegate.doPut(request, response, getServletContext());
+ }
+ }
+
+ @Override
+ protected void doDelete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
+ {
+ if (delegate != null)
+ {
+ delegate.doDelete(request, response, getServletContext());
+ }
+ }
+
+ @Override
+ protected void doHead(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
+ {
+ if (delegate != null)
+ {
+ delegate.doHead(request, response, getServletContext());
+ }
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
+ {
+ if (delegate != null)
+ {
+ delegate.service(request, response, getServletContext());
+ }
+ }
+
+ 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();
+ }
+ });
+ }
+ }
+}