An alternative is to change the RetryWithHttpEntryPoint used by the InsecureChannelProcessor to add "jsessionid=" to the end of all redirections from HTTPS to HTTP.
Code
Code:
/**
* Overrides implementation to handle HTTPS to HTTP issue with tomcat. Tomcat will not pass secured cookie
* to unsecured channel so session is lost when transitioning from HTTPS to HTTP.
* @author Craig Baker
* @version $Id$
*/
public class TomcatRetryWithHttpEntryPoint extends RetryWithHttpEntryPoint
{
private static final Log logger = LogFactory.getLog(TomcatRetryWithHttpEntryPoint.class);
private PortMapper portMapper = new PortMapperImpl();
private PortResolver portResolver = new PortResolverImpl();
public void commence(ServletRequest request, ServletResponse response)
throws IOException, ServletException
{
HttpServletRequest req = (HttpServletRequest) request;
String pathInfo = req.getPathInfo();
String queryString = req.getQueryString();
String contextPath = req.getContextPath();
String destination = req.getServletPath()
+ ((pathInfo == null) ? "" : pathInfo)
+ ((queryString == null) ? "" : ("?" + queryString));
String redirectUrl = contextPath;
Integer httpsPort = new Integer(portResolver.getServerPort(req));
Integer httpPort = portMapper.lookupHttpPort(httpsPort);
if (httpPort != null)
{
boolean includePort = true;
if (httpPort.intValue() == 80)
{
includePort = false;
}
redirectUrl = "http://" + req.getServerName()
+ ((includePort) ? (":" + httpPort) : "") + contextPath
+ destination;
// Add jsession id to end of redirection URL
if (req.getSession(false) != null)
{
redirectUrl = redirectUrl + ";jsessionid=" + req.getSession(false).getId();
}
}
if (logger.isDebugEnabled())
{
logger.debug("Redirecting to: " + redirectUrl);
}
((HttpServletResponse) response)
.sendRedirect(((HttpServletResponse) response)
.encodeRedirectURL(redirectUrl));
}
}