users
[Top] [All Lists]

Re: [cinjug-users] Tomcat Question

To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] Tomcat Question
From: Robert Fries <rgf@xxxxxxxxx>
Date: Tue, 20 Apr 2004 14:49:33 -0400
Delivered-to: mailing list users@cinjug.org
In-reply-to: <E452629ED566E342BAA54DDEC2349385C967A4@napmail1.na.ipsos>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Organization: Objective Synthesis LLC
References: <E452629ED566E342BAA54DDEC2349385C967A4@napmail1.na.ipsos>
On Tue, 2004-04-20 at 13:21, Brian Engel wrote:
> Does anybody know if there is a way to "turn off" URL Rewriting in
> Tomcat for session ID's? 
> i.e. So that ;jsessionid=blah doesn't get appended to the URL.
> 

I am not sure if there is a way to do this without
violating the Servlet spec, but I do it selectively
(based on agent name, for instance) by using a Filter
and a HttpServletResponseFilter like so:

(formatting mangled a bit for 80 cols...)
----------------------------------------------------------------------------

public class SessionIdFilter implements Filter
{
...
  public void doFilter( ServletRequest req,
                       ServletResponse resp,
                       FilterChain chain )
                       throws IOException,
                              ServletException {
    if ( <some condition> ) {
      resp = new HttpServletResponseWrapper((HttpServletResponse)resp) {
        public String encodeURL(String s) {
          return s;
        }

        public String encodeRedirectURL(String s) {
          return s;
        }

        public String encodeUrl(String s) {
          return s;
        }
        public String encodeRedirectUrl(String s) {
          return s;
        }
      };
    }
    chain.doFilter( req, resp );
  }
}

The filter needs to be defined in web.xml as well, like this:

<web-app>

    <filter>
        <filter-name>Session Id Filter</filter-name>
        <filter-class>some.name.SessionIdFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>Session Id Filter</filter-name>
        <servlet-name>yourServlet</servlet-name>
    </filter-mapping>
    
    [...other stuff...]

</web-app>

Hope this is helpful,

--
Robert Fries
Objective Synthesis



<Prev in Thread] Current Thread [Next in Thread>