geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r711230 - /geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
Date Tue, 04 Nov 2008 11:38:22 GMT
Author: vamsic007
Date: Tue Nov  4 03:38:21 2008
New Revision: 711230

URL: http://svn.apache.org/viewvc?rev=711230&view=rev
Log:
GERONIMO-4338 Update Geronimo Jetty ServletHost to account for G3609 changes
 o Updated to use TwistyWebAppContext instead of WebAppContext

Modified:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java?rev=711230&r1=711229&r2=711230&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-jetty/src/main/java/org/apache/geronimo/tuscany/http/jetty/GeronimoServletHost.java
Tue Nov  4 03:38:21 2008
@@ -47,6 +47,10 @@
 import org.apache.geronimo.jetty6.JettyContainer;
 import org.apache.geronimo.jetty6.JettyWebAppContext;
 import org.apache.geronimo.jetty6.handler.ComponentContextHandler;
+import org.apache.geronimo.jetty6.handler.LifecycleCommand;
+import org.apache.geronimo.jetty6.handler.ThreadClassloaderHandler;
+import org.apache.geronimo.jetty6.handler.TwistyWebAppContext;
+import org.apache.geronimo.jetty6.handler.UserTransactionHandler;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.Kernel;
@@ -58,13 +62,13 @@
 import org.apache.tuscany.sca.host.http.DefaultResourceServlet;
 import org.apache.tuscany.sca.host.http.ServletHost;
 import org.apache.tuscany.sca.host.http.ServletMappingException;
+import org.mortbay.jetty.Handler;
 import org.mortbay.jetty.security.SecurityHandler;
 import org.mortbay.jetty.servlet.DefaultServlet;
 import org.mortbay.jetty.servlet.ServletHandler;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.servlet.ServletMapping;
 import org.mortbay.jetty.servlet.SessionHandler;
-import org.mortbay.jetty.webapp.WebAppContext;
 
 /**
  * A Geronimo based implementation of ServletHost. This works only on those
@@ -87,13 +91,12 @@
     private JettyContainer container = null;
     private Kernel kernel = null;
     private ClassLoader cl = null;
-    private WebAppContext webAppContext = null;
     private Context componentContext = null;
     private static Map<String, ComponentContextHandler> contextHandlers = new Hashtable<String,
ComponentContextHandler>();
+    private static Map<String, TwistyWebAppContext> webAppContexts = new Hashtable<String,
TwistyWebAppContext>();
     private Map<String, JettyWebAppContext> jettyWebAppContexts = new HashMap<String,
JettyWebAppContext>();
     private TransactionManager transactionManager = null;
     private Host host = null;
-    private ComponentContextHandler contextHandler = null;
 
     private static final String JMX_APP_NAME = "Tuscany Service Context";
     private static final String JMX_SERVER_NAME = "geronimo";
@@ -179,6 +182,8 @@
             mapping = contextPath;
             contextPath = SEPARATOR;
         }
+        TwistyWebAppContext webAppContext = null;
+        ComponentContextHandler contextHandler = null;
         SessionHandler sessionHandler = null;
         ServletHandler servletHandler = null;
         SecurityHandler securityHandler = null;
@@ -188,19 +193,12 @@
                     "The context "
                             + contextPath
                             + "already exists for a web application and cannot be used by
the binding.");
-        } else if (contextHandlers.get(contextPath) == null) {
+        } else if (webAppContexts.get(contextPath) == null) {
             sessionHandler = new SessionHandler();
             servletHandler = new ServletHandler();
             securityHandler = new SecurityHandler();
-            webAppContext = new WebAppContext(securityHandler, sessionHandler,
+            webAppContext = new TwistyWebAppContext(securityHandler, sessionHandler,
                     servletHandler, null);
-            webAppContext.setContextPath(contextPath);
-            webAppContext.setAllowNullPathInfo(true);
-            webAppContext.setClassLoader(Thread.currentThread()
-                    .getContextClassLoader());
-            webAppContext.setCopyWebDir(false);
-            webAppContext.setExtractWAR(false);
-            webAppContext.setWar("./");
             GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(
                     transactionManager);
             try {
@@ -216,18 +214,28 @@
                                 + webAppContext.getContextPath()
                                 + " in the Tuscany Plugin");
             }
+            Handler next = webAppContext.newTwistyHandler();
+            next = new ThreadClassloaderHandler(next, Thread.currentThread().getContextClassLoader());
+
+            next = new UserTransactionHandler(next, userTransaction);
+            next = contextHandler = new ComponentContextHandler(next, this.componentContext);
+            webAppContext.setTwistyHandler(next);
+            
+            webAppContext.setContextPath(contextPath);
+            webAppContext.setAllowNullPathInfo(true);
+            webAppContext.setClassLoader(Thread.currentThread()
+                    .getContextClassLoader());
+            webAppContext.setCopyWebDir(false);
+            webAppContext.setExtractWAR(false);
+            webAppContext.setWar("./");
             webAppContext.getInitParams().put(
                     "org.mortbay.jetty.servlet.Default.dirAllowed", "false");
         
-            webAppContext.setVirtualHosts(new String[] { host });
-        
-            contextHandler = new ComponentContextHandler(webAppContext,
-                    this.componentContext);
+            //webAppContext.setVirtualHosts(new String[] { host });
         } else {
+            webAppContext = webAppContexts.get(contextPath);
             contextHandler = contextHandlers.get(contextPath);
-            // FIXME: GERONIMO-4338 
-            // servletHandler = (ServletHandler) contextHandler
-            //         .getChildHandlerByClass(ServletHandler.class);
+            servletHandler = webAppContext.getServletHandler();
         }
 
         // FIXME - Need to Assign JSR 77 Names to Context but How?        
@@ -253,7 +261,6 @@
             DefaultServlet defaultServlet = new JettyDefaultServlet(
                     servletPath, resourceServlet.getDocumentRoot());
             holder = new ServletHolder(defaultServlet);
-
         } else {
             holder = new ServletHolder(servlet);
         }
@@ -262,11 +269,9 @@
         servletMapping.setServletName(holder.getName());
         servletMapping.setPathSpec(mapping);
         servletHandler.addServletMapping(servletMapping);
-        if (contextHandlers.get(contextPath) == null) {
-        	// FIXME: GERONIMO-4338
-            // container.addContext(contextHandler);
+        if (webAppContexts.get(contextPath) == null) {
             try {
-                contextHandler.start();
+                contextHandler.lifecycleCommand(new StartCommand(webAppContext));
             } catch (Exception e) {
                 log.fatal("The context " + webAppContext.getContextPath()
                         + " failed to start", e);
@@ -274,6 +279,7 @@
                         + webAppContext.getContextPath() + " failed to start");
             }
             contextHandlers.put(contextPath, contextHandler);
+            webAppContexts.put(contextPath, webAppContext);
         } else {
             try {
                 holder.start();
@@ -300,10 +306,8 @@
             mapping = contextPath;
             contextPath = SEPARATOR;
         }
-        // FIXME: GERONIMO-4338
-        ServletHandler servletHandler = null;
-        //ServletHandler servletHandler = (ServletHandler) contextHandler
-        //        .getChildHandlerByClass(ServletHandler.class);
+        TwistyWebAppContext webAppContext = webAppContexts.get(contextPath);
+        ServletHandler servletHandler = webAppContext.getServletHandler();
         Servlet removedServlet = null;
         List<ServletMapping> mappings = new ArrayList<ServletMapping>(Arrays
                 .asList(servletHandler.getServletMappings()));
@@ -330,13 +334,12 @@
 
         try {
             if (mappings.size() < 3) {
-                contextHandler.stop();
-                contextHandler.destroy();
-                // FIXME: GERONIMO-4338
-                //container.removeContext(contextHandler);
+                ComponentContextHandler contextHandler = contextHandlers.get(contextPath);
+                contextHandler.lifecycleCommand(new StopCommand(webAppContext));
+                
                 contextHandlers.remove(contextPath);
+                webAppContexts.remove(contextPath);
             } else {
-
                 servletHandler.start();
             }
         } catch (Exception e) {
@@ -411,4 +414,30 @@
 		// TODO Auto-generated method stub
 		
 	}
+	
+    public class StartCommand implements LifecycleCommand {
+        TwistyWebAppContext webAppContext;
+        
+        public StartCommand(TwistyWebAppContext webAppContext) {
+            this.webAppContext = webAppContext;
+        }
+        
+        public void lifecycleMethod() throws Exception {
+            container.addContext(webAppContext);
+            webAppContext.start();
+        }
+    }
+
+    public class StopCommand implements LifecycleCommand {
+        TwistyWebAppContext webAppContext;
+        
+        public StopCommand(TwistyWebAppContext webAppContext) {
+            this.webAppContext = webAppContext;
+        }
+        
+        public void lifecycleMethod() throws Exception {
+            webAppContext.stop();
+            container.removeContext(webAppContext);
+        }
+    }
 }



Mime
View raw message