geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject svn commit: r493201 - in /geronimo/server/trunk/modules: geronimo-jetty6-clustering-wadi/src/main/java/org/apache/geronimo/jetty6/cluster/wadi/ geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/ geronimo-jetty6/src/main/java/org/apache/geronimo/...
Date Fri, 05 Jan 2007 21:39:36 GMT
Author: gdamour
Date: Fri Jan  5 13:39:34 2007
New Revision: 493201

URL: http://svn.apache.org/viewvc?view=rev&rev=493201
Log:
Fix build following recent Jetty6 AbstractSessionManager updates.

There are two core changes:
1. update ClusteredSessionHandler to leverage the new API provided
by AbstractSessionManager, which simplifies the implementation and
remove a hack around the initialization of the session attributes
following a session migration.
2. move pre-handle logic from ServletHandler to SessionHandler.

Also, fix a lame type in WADIClusteredPreHandlerFactory: the
expose interface is PreHandlerFactory and not SessionHandlerFactory.

This fixes GERONIMO-2677 - HttpSession Relocation - Sticky load-balancing via HTTP Cookie

Removed:
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHandler.java
Modified:
    geronimo/server/trunk/modules/geronimo-jetty6-clustering-wadi/src/main/java/org/apache/geronimo/jetty6/cluster/wadi/WADIClusteredPreHandlerFactory.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/SessionHandlerFactory.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandler.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandlerFactory.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionManager.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/ApplicationTest.java

Modified: geronimo/server/trunk/modules/geronimo-jetty6-clustering-wadi/src/main/java/org/apache/geronimo/jetty6/cluster/wadi/WADIClusteredPreHandlerFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6-clustering-wadi/src/main/java/org/apache/geronimo/jetty6/cluster/wadi/WADIClusteredPreHandlerFactory.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6-clustering-wadi/src/main/java/org/apache/geronimo/jetty6/cluster/wadi/WADIClusteredPreHandlerFactory.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6-clustering-wadi/src/main/java/org/apache/geronimo/jetty6/cluster/wadi/WADIClusteredPreHandlerFactory.java
Fri Jan  5 13:39:34 2007
@@ -23,7 +23,6 @@
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.jetty6.PreHandler;
 import org.apache.geronimo.jetty6.PreHandlerFactory;
-import org.apache.geronimo.jetty6.SessionHandlerFactory;
 import org.codehaus.wadi.impl.ClusteredManager;
 
 
@@ -64,7 +63,7 @@
         infoFactory.addReference(GBEAN_REF_WADI_SESSION_MANAGER, WADISessionManager.class,

                 NameFactory.GERONIMO_SERVICE);
 
-        infoFactory.addInterface(SessionHandlerFactory.class);
+        infoFactory.addInterface(PreHandlerFactory.class);
 
         infoFactory.setConstructor(new String[]{GBEAN_REF_WADI_SESSION_MANAGER});
 

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
Fri Jan  5 13:39:34 2007
@@ -155,7 +155,17 @@
         assert transactionManager != null;
         assert trackedConnectionAssociator != null;
         assert jettyContainer != null;
-        SessionHandler sessionHandler = handlerFactory == null ? new SessionHandler() : handlerFactory.createHandler();
+        
+        SessionHandler sessionHandler;
+        if (null != handlerFactory) {
+            if (null == preHandlerFactory) {
+                throw new IllegalStateException("A preHandlerFactory must be set if an handler
factory is set.");
+            }
+            PreHandler preHandler = preHandlerFactory.createHandler();
+            sessionHandler = handlerFactory.createHandler(preHandler);
+        } else {
+            sessionHandler = new SessionHandler();
+        }
         //TODO construct an interceptor chain inside one of the Handlers.
         JettySecurityHandler securityHandler = null;
         if (securityRealmName != null) {
@@ -168,8 +178,7 @@
             securityHandler.init(policyContextID, defaultPrincipal, checkedPermissions, excludedPermissions,
classLoader);
         }
 
-        PreHandler preHandler = null == preHandlerFactory ? null : preHandlerFactory.createHandler();
-        ServletHandler servletHandler = new JettyServletHandler(preHandler);
+        ServletHandler servletHandler = new ServletHandler();
 
         webAppContext = new WebAppContext(securityHandler, sessionHandler, servletHandler,
null);
         AbstractHandler next = sessionHandler;

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/SessionHandlerFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/SessionHandlerFactory.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/SessionHandlerFactory.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/SessionHandlerFactory.java
Fri Jan  5 13:39:34 2007
@@ -23,5 +23,5 @@
  * @version $Rev$ $Date$
  */
 public interface SessionHandlerFactory {
-    SessionHandler createHandler();
+    SessionHandler createHandler(PreHandler preHandler);
 }

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandler.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandler.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandler.java
Fri Jan  5 13:39:34 2007
@@ -16,6 +16,14 @@
  */
 package org.apache.geronimo.jetty6.cluster;
 
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.geronimo.jetty6.AbstractPreHandler;
+import org.apache.geronimo.jetty6.PreHandler;
 import org.mortbay.jetty.servlet.SessionHandler;
 
 /**
@@ -23,8 +31,40 @@
  * @version $Rev$ $Date$
  */
 public class ClusteredSessionHandler extends SessionHandler {
+    private final PreHandler chainedHandler;
+    
+    public ClusteredSessionHandler(ClusteredSessionManager sessionManager, PreHandler chainedHandler)
{
+        if (null == chainedHandler) {
+            throw new IllegalArgumentException("chainedHandler is required");
+        }
+        this.chainedHandler = chainedHandler;
+        chainedHandler.setNextHandler(new ActualHandler());
 
-    public ClusteredSessionHandler(ClusteredSessionManager sessionManager) {
         setSessionManager(sessionManager);
     }
+    
+    @Override
+    public void handle(String target, HttpServletRequest request, HttpServletResponse response,
int dispatch)
+            throws IOException, ServletException {
+        setRequestedId(request, dispatch);
+        try {
+            chainedHandler.handle(target, request, response, dispatch);
+        } catch (ServletException e) {
+            throw (IOException) new IOException().initCause(e);
+        }
+    }
+    
+    protected void doHandle(String target, HttpServletRequest request, HttpServletResponse
response, int dispatch)
+            throws IOException, ServletException {
+        super.handle(target, request, response, dispatch);
+    }
+
+    private class ActualHandler extends AbstractPreHandler {
+
+        public void handle(String target, HttpServletRequest request, HttpServletResponse
response, int dispatch)
+                throws IOException, ServletException {
+            doHandle(target, request, response, dispatch);
+        }
+    }
+
 }

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandlerFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandlerFactory.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandlerFactory.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionHandlerFactory.java
Fri Jan  5 13:39:34 2007
@@ -20,6 +20,7 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.jetty6.PreHandler;
 import org.apache.geronimo.jetty6.SessionHandlerFactory;
 import org.mortbay.jetty.servlet.SessionHandler;
 
@@ -34,9 +35,9 @@
         this.sessionManager = sessionManager;
     }
 
-    public SessionHandler createHandler() {
+    public SessionHandler createHandler(PreHandler preHandler) {
         ClusteredSessionManager clusteredSessionManager = new ClusteredSessionManager(sessionManager);
-        return new ClusteredSessionHandler(clusteredSessionManager);
+        return new ClusteredSessionHandler(clusteredSessionManager, preHandler);
     }
 
     public static final GBeanInfo GBEAN_INFO;

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionManager.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionManager.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/cluster/ClusteredSessionManager.java
Fri Jan  5 13:39:34 2007
@@ -99,15 +99,15 @@
 
     @Override
     protected void invalidateSessions() {
-        synchronized (idToSession) {
-            idToSession.clear();
-        }
+        // We do not need to clear idToSession: when the SessionManager GBean is stopped,
all the sessions
+        // it defines are migrated to other SessionManagers. These outbound session migrations
will remove 
+        // them from idToSession.
     }
 
     private class MigrationListener implements SessionListener {
 
         public void notifyInboundSessionMigration(org.apache.geronimo.clustering.Session
session) {
-            addSession(new MigratedClusteredSession(session), false);
+            addSession(new ClusteredSession(session), false);
         }
 
         public void notifyOutboundSessionMigration(org.apache.geronimo.clustering.Session
session) {
@@ -132,16 +132,13 @@
             } catch (SessionAlreadyExistException e) {
                 throw (IllegalStateException) new IllegalStateException().initCause(e);
             }
-            synchronized (idToSession) {
-                idToSession.put(getClusterId(), this);
-            }
-            forceDefinitionOfSessionValues();
+            initValues();
         }
 
         protected ClusteredSession(org.apache.geronimo.clustering.Session session) {
             super(System.currentTimeMillis(), session.getSessionId());
             this.session = session;
-            forceDefinitionOfSessionValues();
+            initValues();
         }
 
         @Override
@@ -158,34 +155,6 @@
         public void invalidate() throws IllegalStateException {
             super.invalidate();
             session.release();
-        }
-
-        private void forceDefinitionOfSessionValues() {
-            String TOKEN = "GeronimoIntegration_forceDefinitionOfSessionValues";
-            setAttribute(TOKEN, TOKEN);
-            removeAttribute(TOKEN);
-        }
-    }
-
-    public class MigratedClusteredSession extends ClusteredSession {
-        private final String clusterId;
-
-        protected MigratedClusteredSession(org.apache.geronimo.clustering.Session session)
{
-            super(session);
-            clusterId = session.getSessionId();
-            synchronized (idToSession) {
-                idToSession.put(clusterId, this);
-            }
-        }
-
-        /**
-         * Implementation note: we need to override this method as the constructor Session(String)
has a bug:
-         * it should also set _clusterId. W/o this override, this Session is bound to the
null key during inbound
-         * session migration.
-         */
-        @Override
-        protected String getClusterId() {
-            return clusterId;
         }
     }
 

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java
Fri Jan  5 13:39:34 2007
@@ -62,6 +62,7 @@
     private TransactionManager transactionManager;
     private ConnectionTrackingCoordinator connectionTrackingCoordinator;
     private URL configurationBaseURL;
+    protected PreHandlerFactory preHandlerFactory = null;
     protected SessionHandlerFactory sessionHandlerFactory = null;
 
     protected void setUpStaticContentServlet(JettyServletRegistration webModule) throws Exception
{
@@ -107,7 +108,7 @@
                 null,
                 0,
                 sessionHandlerFactory,
-                null,
+                preHandlerFactory,
                 policyContextId,
                 securityRealmName,
                 defaultPrincipal,

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/ApplicationTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/ApplicationTest.java?view=diff&rev=493201&r1=493200&r2=493201
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/ApplicationTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/ApplicationTest.java
Fri Jan  5 13:39:34 2007
@@ -18,16 +18,21 @@
 package org.apache.geronimo.jetty6;
 
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 
-import org.apache.geronimo.clustering.SessionManager;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.geronimo.clustering.BasicNode;
+import org.apache.geronimo.clustering.Node;
 import org.apache.geronimo.clustering.Session;
 import org.apache.geronimo.clustering.SessionAlreadyExistException;
 import org.apache.geronimo.clustering.SessionListener;
-import org.apache.geronimo.clustering.Node;
-import org.apache.geronimo.clustering.BasicNode;
+import org.apache.geronimo.clustering.SessionManager;
 import org.apache.geronimo.jetty6.cluster.ClusteredSessionHandlerFactory;
 
 /**
@@ -49,6 +54,7 @@
 
     public void testApplicationWithSessionHandler() throws Exception {
         SessionManager sessionManager = new MockSessionManager();
+        preHandlerFactory = new MockPreHandlerFactory();
         sessionHandlerFactory = new ClusteredSessionHandlerFactory(sessionManager);
         JettyWebAppContext app = setUpAppContext(null, null, null, null, null, null, null,
"war1/");
 
@@ -79,5 +85,20 @@
             return node;
         }
     }
+
+    public class MockPreHandlerFactory implements PreHandlerFactory {
+        public PreHandler createHandler() {
+            return new AbstractPreHandler() {
+
+                public void handle(String target, HttpServletRequest request, HttpServletResponse
response, int dispatch)
+                        throws IOException, ServletException {
+                    next.handle(target, request, response, dispatch);
+                }
+                
+            };
+        }
+
+    }
+
 
 }



Mime
View raw message