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);
}