Index: Request.java =================================================================== --- Request.java (revision 24588) +++ Request.java (working copy) @@ -2942,14 +2942,20 @@ } if (getContext().getCookies()) { - String id = session.getIdInternal(); String jvmRoute = ((StandardContext) getContext()).getJvmRoute(); - if (jvmRoute != null) { - id += ("." + jvmRoute); + /* + * Check if context has been configured with jvmRoute for + * Apache LB. If it has, do not add the JSESSIONID cookie + * here, but rely on OutputBuffer#addSessionCookieWithJvmRoute + * to add the jvmRoute enhanced JSESSIONID as a cookie right + * before the response is flushed. + */ + if (jvmRoute == null) { + String id = session.getIdInternal(); + Cookie cookie = new Cookie(Globals.SESSION_COOKIE_NAME, id); + configureSessionCookie(cookie); + ((HttpServletResponse) response).addCookie(cookie); } - Cookie cookie = new Cookie(Globals.SESSION_COOKIE_NAME, id); - configureSessionCookie(cookie); - ((HttpServletResponse) response).addCookie(cookie); } } Index: OutputBuffer.java =================================================================== --- OutputBuffer.java (revision 24588) +++ OutputBuffer.java (working copy) @@ -699,20 +699,16 @@ } StandardContext ctx = (StandardContext) coyoteResponse.getContext(); - if (ctx == null || ctx.getJvmRoute() == null) { + if (ctx == null || ctx.getJvmRoute() == null || !ctx.getCookies()) { return; } - if (response.containsHeader(SET_COOKIE_HEADER)) { - return; - } - Session sess = req.getSessionInternal(false); if (sess == null) { return; } - // Creating JSESSIONID cookie that includes jvmRoute + // Create JSESSIONID cookie that includes jvmRoute Cookie cookie = new Cookie(Globals.SESSION_COOKIE_NAME, sess.getIdInternal() + "." + ctx.getJvmRoute());