Created
August 19, 2010 21:00
-
-
Save loganj/538901 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 1f44e0b6df61729b4fdc7be6fc4ec145bb89a8b9 | |
Author: Logan Johnson <ljohnson@mobilizationlabs.com> | |
Date: Thu Aug 19 16:11:30 2010 -0400 | |
choose root based on host for each request | |
diff --git a/tim-session-common/src/main/java/com/terracotta/session/SessionFilter.java b/tim-session-common/src/main/java/com/terracotta/session/SessionFilter.java | |
index 6d4f3b4..523945a 100644 | |
--- a/tim-session-common/src/main/java/com/terracotta/session/SessionFilter.java | |
+++ b/tim-session-common/src/main/java/com/terracotta/session/SessionFilter.java | |
@@ -17,6 +17,8 @@ import com.terracotta.session.util.SessionCookieWriter; | |
import com.terracotta.session.util.SessionIdGenerator; | |
import java.io.IOException; | |
+import java.util.HashMap; | |
+import java.util.Map; | |
import javax.servlet.Filter; | |
import javax.servlet.FilterChain; | |
@@ -32,7 +34,7 @@ public class SessionFilter implements Filter { | |
public final static String REQUEST_RESPONSE_FACTORY_KEY = SessionFilter.class.getName() | |
+ ".REQUEST_RESPONSE_FACTORY_KEY"; | |
- private SessionManager mgr = null; | |
+ private Map<String,SessionManager> sessionManagers = new HashMap<String,SessionManager>(); | |
private ServletContext servletContext = null; | |
private String requestResponseFactory = null; | |
@@ -78,12 +80,15 @@ public class SessionFilter implements Filter { | |
} | |
protected synchronized SessionManager getManager(HttpServletRequest req) { | |
+ String host = getHost(req); | |
+ SessionManager mgr = sessionManagers.get(host); | |
if (mgr == null) { | |
if (servletContext instanceof WebAppConfig) { | |
mgr = createWebAppConfigManager(req, (WebAppConfig) servletContext, servletContext); | |
} else { | |
mgr = createDefaultManager(req, servletContext); | |
} | |
+ sessionManagers.put(host, mgr); | |
} | |
Assert.post(mgr != null); | |
return mgr; | |
@@ -111,17 +116,7 @@ public class SessionFilter implements Filter { | |
final SessionCookieWriter scw = DefaultCookieWriter.makeInstance(cp); | |
final LifecycleEventMgr eventMgr = DefaultLifecycleEventMgr.makeInstance(cp); | |
- String host = req.getHeader("Host"); | |
- if (host != null) { | |
- host = host.trim(); | |
- | |
- int colon = host.lastIndexOf(':'); | |
- if (colon >= 0) { | |
- host = host.substring(0, colon); | |
- } | |
- } | |
- if (host == null || host.length() == 0) { throw new RuntimeException("Request is missing \"Host\" header"); } | |
- | |
+ String host = getHost(req); | |
final ContextMgr contextMgr = DefaultContextMgr.makeInstance(req, sc, host); | |
final SessionManager rv = new TerracottaSessionManager(sig, scw, eventMgr, contextMgr, factory, cp); | |
return rv; | |
@@ -138,4 +133,19 @@ public class SessionFilter implements Filter { | |
throw new AssertionError(e); | |
} | |
} | |
+ | |
+ private String getHost(HttpServletRequest req) { | |
+ String host = req.getHeader("Host"); | |
+ if (host != null) { | |
+ host = host.trim(); | |
+ | |
+ int colon = host.lastIndexOf(':'); | |
+ if (colon >= 0) { | |
+ host = host.substring(0, colon); | |
+ } | |
+ } | |
+ if (host == null || host.length() == 0) { throw new RuntimeException("Request is missing \"Host\" header"); } | |
+ return host; | |
+ } | |
+ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment