tags:

views:

881

answers:

1

I'm deploying a JSF (myfaces, restfaces, and richfaces) app to OC4J. I don't want the jsessionid to appear in the status bar or the URL address. I have managed to suppress it in almost all cases. The one case that I still have problems with is when the site is first visited with a "clean" browser (with no cache, history, etc.). In this case, jsessionid appears on every link until any link is clicked on, then it disappears, and will not come back (even in subsequent sessions) until the browser's cache is cleared again.

It seems others have run into this problem, but I didn't find any resolutions or work arounds:

+1  A: 

The following code in a servlet filter has worked for us. The idea is override any URL-rewriting logic by employing a custom response wrapper.

public void doFilter( 
    ServletRequest req, 
    ServletResponse resp, 
    FilterChain filterChain ) 
    throws IOException, ServletException
{
    if ( req instanceof HttpServletRequest && 
      resp instanceof HttpServletResponse )
    {
     doFilter( 
      (HttpServletRequest) req, 
      (HttpServletResponse) resp, 
      filterChain );
    }
    else
    {
     filterChain.doFilter( req, resp );
    }
}

private void doFilter( 
    HttpServletRequest request, 
    HttpServletResponse response, 
    FilterChain filterChain ) 
    throws IOException, ServletException
{
    RequestHandler requestHandler = getRequestHandler( request );

    HttpServletResponse wrappedResponse = getWrappedResponse( response );

    filterChain.doFilter( request, wrappedResponse );
}

private HttpServletResponse getWrappedResponse( 
    HttpServletResponse response )
{
    return
     new HttpServletResponseWrapper( response )
     {
      public String encodeRedirectUrl( String url ) { return url; }

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

      public String encodeUrl( String url ) { return url; }

      public String encodeURL( String url ) { return url; }
     };
}
dstine

related questions