How can I get HttpServletRequest when in an HttpSessionListener?

jakarta-ee, java, jsf, request, session

Solution

The `HttpSessionListener` does not have access to the request because it is invoked when no request has been made—to notify of session destruction.

So, a `Filter` or `Servlet` would be better places to examine the request and specify the session timeout.

Problem

How can I access request headers from a SessionListener? I need to set a timeout on the current session when it is created. The timeout needs to vary based on a header in the HttpServletRequest. I already have a SessionListener (implements HttpSessionListener) that logs the creation and destruction of new sessions, and it seems to be the most logical place to set the timeout. I've tried the following, but it always sets ctx to null. ``` FacesContext ctx = FacesContext.getCurrentInstance(); ```

Original source