Author: alessio.soldano(a)jboss.com
Date: 2011-04-06 13:10:02 -0400 (Wed, 06 Apr 2011)
New Revision: 14017
Added:
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java
Log:
Adding servlet delegation facilities
Added:
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
(rev 0)
+++
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/classloading/ClassLoaderProvider.java 2011-04-06
17:10:02 UTC (rev 14017)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+/**
+ * SPI for getting AS classloaders
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 06-Apr-2011
+ *
+ */
+public abstract class ClassLoaderProvider
+{
+ private static ClassLoaderProvider provider = null;
+
+ public static void setDefaultProvider(ClassLoaderProvider p)
+ {
+ provider = p;
+ }
+
+ public static ClassLoaderProvider getDefaultProvider()
+ {
+ return provider;
+ }
+
+ public abstract ClassLoader getWebServiceSubsystemClassLoader();
+
+ public abstract ClassLoader getServerIntegrationClassLoader();
+
+}
Added:
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java
===================================================================
--- spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java
(rev 0)
+++
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegate.java 2011-04-06
17:10:02 UTC (rev 14017)
@@ -0,0 +1,59 @@
+/*
+ * 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 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;
+}
Added:
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java
===================================================================
---
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java
(rev 0)
+++
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/ServletDelegateFactory.java 2011-04-06
17:10:02 UTC (rev 14017)
@@ -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);
+}
Added: 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
(rev 0)
+++
spi/branches/asoldano/src/main/java/org/jboss/wsf/spi/deployment/WSFServlet.java 2011-04-06
17:10:02 UTC (rev 14017)
@@ -0,0 +1,144 @@
+/*
+ * 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 != null) ?
clProvider.getWebServiceSubsystemClassLoader() : getContextClassLoader();
+ ServiceLoader<ServletDelegateFactory> sl =
ServiceLoader.load(ServletDelegateFactory.class, cl);
+ ServletDelegateFactory factory = sl.iterator().next();
+ return
factory.newServletDelegate(servletConfig.getInitParameter(STACK_SERVLET_DELEGATE_CLASS));
+ }
+
+ @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();
+ }
+ });
+ }
+ }
+}