Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 98190 invoked from network); 4 Jun 2002 21:36:02 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 4 Jun 2002 21:36:02 -0000 Received: (qmail 15817 invoked by uid 97); 4 Jun 2002 21:31:18 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 15669 invoked by uid 97); 4 Jun 2002 21:31:17 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 15525 invoked by uid 98); 4 Jun 2002 21:31:16 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Message-ID: From: Subir Sengupta To: 'Tomcat Users List' Subject: RE: AW: How to use setRequestedSessionId Date: Tue, 4 Jun 2002 12:42:52 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="ISO-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I'm still unclear about how to do this. Once a request has been associated with a session, how do we associate it with a different session. I'm probably wrong but it seems the only way is to use setRequestedSessionId(). Once I call getSession(), the session gets associated with the request, and I'm not sure how to associate it with another session. I tried setting up an HttpRequestWrapper but it needs a bunch of abstract methods implemented. Here's what I'm trying to do: - In a filter, get the session ID (getSession().getId()) and compare the value with a value set in another cookie - if they don't match, create a new session - associate the new session with the request So, it's the last step that I don't know how to do. Any help is appreciated. Thanks, Subir -----Original Message----- From: Craig R. McClanahan [mailto:craigmcc@apache.org] Sent: Monday, June 03, 2002 11:23 AM To: Tomcat Users List Subject: Re: AW: How to use setRequestedSessionId On Mon, 3 Jun 2002, Ralph Einfeldt wrote: > Date: Mon, 3 Jun 2002 19:03:46 +0200 > From: Ralph Einfeldt > Reply-To: Tomcat Users List > To: Tomcat Users List > Subject: AW: How to use setRequestedSessionId > > Have a look at: > http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg41615.html > Ralph, thanks for pointing people to the archives :-). There is lots of good stuff there. This one, happens to be a ResponseWrapper -- the principles of writing a request wrapper are really similar. The outline of a "conditionally create the session" filter might be lke this: public class MyFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequestWrapper wrapper = new MyWrapper((HttpServletRequest) request; chain.doFilter(wrapper, response); } } and the corresponding wrapper class would look like: public class MyWrapper extends HttpServletRequestWrapper { public HttpSession getSession() { if (ok to create session) { return super.getSession(); } else { return (null); } public HttpSession getSession(boolean create) { if (ok to create session) { return super.getSession(create); } else { return (null); } } } All of the rest of the HttpServletRequest methods get delegated through to the original request -- you only need to override the stuff you want to customize. The wrapper instance is ultimately passed on to your servlet or JSP page, which doesn't necessarily know that the wrapping took place. Filters and wrappers are very cool -- it's worth your time learning how to use them. One source of information is the tutorial on web applications that is availavle with the Java Web Services Developer Pack (http://java.sun.com/webservices/), which includes Tomcat 4 as its server. Useful homework exercise - write a Filter and request wrapper that add a new request parameter to the request, under certain conditions. Craig -- To unsubscribe, e-mail: For additional commands, e-mail: -- To unsubscribe, e-mail: For additional commands, e-mail: