[jbossws-commits] JBossWS SVN: r8364 - framework/trunk/src/main/java/org/jboss/wsf/framework/deployment.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Tue Oct 7 05:24:54 EDT 2008
Author: richard.opalka at jboss.com
Date: 2008-10-07 05:24:54 -0400 (Tue, 07 Oct 2008)
New Revision: 8364
Added:
framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractAspectizedEndpointServlet.java
framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractEndpointServlet.java
Log:
[JBWS-2246][JBWS-2264][JBAS-5732] refactoring endpoint servlets
Added: framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractAspectizedEndpointServlet.java
===================================================================
--- framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractAspectizedEndpointServlet.java (rev 0)
+++ framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractAspectizedEndpointServlet.java 2008-10-07 09:24:54 UTC (rev 8364)
@@ -0,0 +1,102 @@
+/*
+ * 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.wsf.framework.deployment;
+
+import org.jboss.wsf.spi.DeploymentAspectManagerLocator;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.DeploymentAspectManager;
+
+/**
+ * A cross stack aspectized webservice servlet that is installed for every web service endpoint on AS 5.x series
+ * @author richard.opalka at jboss.com
+ */
+public abstract class AbstractAspectizedEndpointServlet extends AbstractEndpointServlet
+{
+
+ private static final String PROPERTY_NAME = "org.jboss.ws.webapp.ServletAspectManagerName";
+ protected DeploymentAspectManager aspectsManager;
+
+ /**
+ * Constructor
+ */
+ protected AbstractAspectizedEndpointServlet() {}
+
+ /**
+ * Initializes aspect manager
+ */
+ @Override
+ protected final void initAspectManager()
+ {
+ final String managerName = (String)this.endpoint.getService().getDeployment().getProperty(PROPERTY_NAME);
+ if (managerName == null)
+ throw new IllegalStateException("Endpoint servlet manager name must be specified with key: " + PROPERTY_NAME);
+
+ final DeploymentAspectManagerLocator locator = this.spiProvider.getSPI(DeploymentAspectManagerLocator.class);
+ this.aspectsManager = locator.locateDeploymentAspectManager(managerName);
+ }
+
+ /**
+ * Starts servlet related aspects
+ */
+ @Override
+ protected final void startAspectManager()
+ {
+ this.assertCorrectState();
+ final Deployment dep = this.endpoint.getService().getDeployment();
+
+ this.aspectsManager.create(dep, null);
+ this.aspectsManager.start(dep, null);
+ }
+
+ /**
+ * Stops servlet related aspects
+ */
+ @Override
+ protected final void stopAspectManager()
+ {
+ this.assertCorrectState();
+ final Deployment dep = this.endpoint.getService().getDeployment();
+
+ try
+ {
+ this.aspectsManager.stop(dep, null);
+ this.aspectsManager.destroy(dep, null);
+ }
+ finally
+ {
+ this.aspectsManager = null;
+ super.stopAspectManager();
+ }
+ }
+
+ /**
+ * Asserts this object correct state
+ */
+ private void assertCorrectState()
+ {
+ if (this.endpoint == null || this.aspectsManager == null)
+ {
+ throw new IllegalStateException();
+ }
+ }
+
+}
Added: framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractEndpointServlet.java
===================================================================
--- framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractEndpointServlet.java (rev 0)
+++ framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/AbstractEndpointServlet.java 2008-10-07 09:24:54 UTC (rev 8364)
@@ -0,0 +1,205 @@
+/*
+ * 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.wsf.framework.deployment;
+
+import java.io.IOException;
+
+import javax.management.ObjectName;
+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.common.ObjectNameFactory;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.EndpointAssociation;
+import org.jboss.wsf.spi.invocation.RequestHandler;
+import org.jboss.wsf.spi.management.EndpointRegistry;
+import org.jboss.wsf.spi.management.EndpointRegistryFactory;
+import org.jboss.wsf.spi.management.EndpointResolver;
+
+import javax.xml.ws.WebServiceException;
+
+/**
+ * A cross stack webservice servlet that is installed for every web service endpoint on AS 4.2.x series
+ * @author thomas.diesler at jboss.org
+ * @author heiko.braun at jboss.com
+ * @author richard.opalka at jboss.com
+ */
+public abstract class AbstractEndpointServlet extends HttpServlet
+{
+
+ protected final SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ protected Endpoint endpoint;
+ protected EndpointRegistry epRegistry;
+
+ /**
+ * Constructor
+ */
+ protected AbstractEndpointServlet() {}
+
+ /**
+ * Servlet lifecycle init method
+ * @param servletConfig servlet configuration
+ */
+ public final void init(ServletConfig servletConfig) throws ServletException
+ {
+ super.init(servletConfig);
+ this.initRegistry();
+ this.initAspectManager();
+ this.initServiceEndpoint(servletConfig.getServletContext().getContextPath());
+ this.postInit(servletConfig);
+ }
+
+ /**
+ * Servlet lifecycle destroy method
+ */
+ public final void destroy()
+ {
+ try
+ {
+ this.stopAspectManager();
+ }
+ finally
+ {
+ super.destroy();
+ }
+ }
+
+ /**
+ * Serves the requests
+ */
+ public final void service(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ try
+ {
+ EndpointAssociation.setEndpoint(endpoint);
+ RequestHandler requestHandler = endpoint.getRequestHandler();
+ requestHandler.handleHttpRequest(endpoint, req, res, getServletContext());
+ }
+ finally
+ {
+ EndpointAssociation.removeEndpoint();
+ }
+ }
+
+ /**
+ * Template method
+ * @param cfg servlet config
+ */
+ protected void postInit(ServletConfig cfg)
+ {
+ // does nothing (because of BC)
+ }
+
+ /**
+ * Template method
+ */
+ protected void initAspectManager()
+ {
+ // does nothing (because of BC)
+ }
+
+ /**
+ * Template method
+ */
+ protected void startAspectManager()
+ {
+ // does nothing (because of BC)
+ }
+
+ /**
+ * Template method
+ */
+ protected void stopAspectManager()
+ {
+ // does nothing (because of BC)
+ }
+
+ /**
+ * Abstract method that must be overriden by each stack servlet endpoint
+ * @param servletContext servlet context
+ * @param servletName servlet name
+ * @return new stack specific endpoint resolver
+ */
+ protected abstract EndpointResolver newEndpointResolver(String servletContext, String servletName);
+
+ /**
+ * Initialize the service endpoint
+ */
+ private void initServiceEndpoint(String contextPath)
+ {
+ this.initEndpoint(contextPath, getServletName());
+ this.setRuntimeLoader();
+ this.startAspectManager();
+ }
+
+ /**
+ * Initializes endpoint registry
+ */
+ private void initRegistry()
+ {
+ epRegistry = spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
+ }
+
+ /**
+ * Initialize the service endpoint
+ * @param contextPath context path
+ * @param servletName servlet name
+ */
+ private void initEndpoint(String contextPath, String servletName)
+ {
+ final EndpointResolver resolver = newEndpointResolver(contextPath, servletName);
+ this.endpoint = epRegistry.resolve(resolver);
+
+ if (this.endpoint == null)
+ {
+ ObjectName oname = ObjectNameFactory.create(Endpoint.SEPID_DOMAIN + ":" +
+ Endpoint.SEPID_PROPERTY_CONTEXT + "=" + contextPath + "," +
+ Endpoint.SEPID_PROPERTY_ENDPOINT + "=" + servletName
+ );
+ throw new WebServiceException("Cannot obtain endpoint for: " + oname);
+ }
+ }
+
+ /**
+ * Sets runtime classloader for JSE endpoints
+ */
+ private void setRuntimeLoader()
+ {
+ final Deployment dep = endpoint.getService().getDeployment();
+ final boolean isJaxrpcJse = dep.getType() == Deployment.DeploymentType.JAXRPC_JSE;
+ final boolean isJaxwsJse = dep.getType() == Deployment.DeploymentType.JAXWS_JSE;
+
+ if (isJaxrpcJse || isJaxwsJse)
+ {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ dep.setRuntimeClassLoader(classLoader);
+ }
+ }
+
+}
More information about the jbossws-commits
mailing list