Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

Java Filter not Write Cookie in Apache/Tomcat 7 Load Balanced Environment

0

51 views

Hello,

I'm using tomcat 7 and the below filter in order to write the the JSESSIONID cookie across http to https to http requests in my application. Everything works fine when I just have on server in play, but when I add another server to the load balancer, the cookie can't be written. Does something besides the Cookie doman need to be set for this?

public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {
      final HttpServletRequest httpRequest = (HttpServletRequest) request;
      final HttpServletResponse httpResponse = (HttpServletResponse) response;
      final HttpSession session = httpRequest.getSession(false);

      if (session != null) {

            final Cookie sessionCookie = new Cookie("JSESSIONID", session.getId());
            sessionCookie.setMaxAge(-1);
            sessionCookie.setSecure(false);
            sessionCookie.setPath(httpRequest.getContextPath() );
            sessionCookie.setDomain(httpRequest.getRemoteHost());

            httpResponse.addCookie(sessionCookie);

      }
            chain.doFilter(request, response);
      }     

asked April 16, 2011 5:04 pm CDT
c12
posted via StackOverflow

0 Answers

Be the first to answer this question

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions
Java http cookie
February 8, 2011
Java/apache/tomcat
March 15, 2011