Class AbstractSessionAwareRequestHandler

java.lang.Object
com.aquima.web.session.AbstractSessionAwareRequestHandler
Direct Known Subclasses:
AbstractSessionAwareFilter, AbstractSessionAwareInterceptor

public class AbstractSessionAwareRequestHandler extends Object
Base class for handler interceptors and filters which require access to the AquimaSession for the current request.

This base class is able to intercept HandlerMethod handlers which have the session ID as a RequestParam or PathVariable that is also annotated with AquimaSessionId.

This class gives the following interpretation to FlushMode.AUTO:

  • a POST, PUT, PATCH or DELETE request is an intent to modify - FlushMode.ALWAYS is used
  • for all other request methods, FlushMode.NEVER is used

However, the actual flush mode may be influenced by prior interceptors/filters that also inherit from this base class, as well as by the annotations on the target controller. See getSession(HttpServletRequest, Object, FlushMode) for more details.

Since:
12.1
Author:
Petru Galanton
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    AbstractSessionAwareRequestHandler(com.blueriq.component.api.IAquimaSessionsMap sessionManager)
     
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    final com.blueriq.component.api.FlushMode
    extractEffectiveFlushMode(jakarta.servlet.http.HttpServletRequest request, com.blueriq.component.api.annotation.AquimaSessionId aquimaSessionId, com.blueriq.component.api.FlushMode interceptorFlushMode)
     
    final String
    extractSessionId(jakarta.servlet.http.HttpServletRequest request, org.springframework.core.MethodParameter parameter, com.blueriq.component.api.annotation.AquimaSessionId annotation)
    Extracts the session ID from the request.
    final com.blueriq.component.api.IAquimaSession
    getSession(jakarta.servlet.http.HttpServletRequest request, Object handler)
    final com.blueriq.component.api.IAquimaSession
    getSession(jakarta.servlet.http.HttpServletRequest request, Object handler, com.blueriq.component.api.FlushMode flushMode)
    Returns the AquimaSession for this request.
    final com.blueriq.component.api.IAquimaSessionsMap
     

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details Link icon

    • AbstractSessionAwareRequestHandler Link icon

      public AbstractSessionAwareRequestHandler(com.blueriq.component.api.IAquimaSessionsMap sessionManager)
  • Method Details Link icon

    • getSessionManager Link icon

      public final com.blueriq.component.api.IAquimaSessionsMap getSessionManager()
    • getSession Link icon

      public final com.blueriq.component.api.IAquimaSession getSession(jakarta.servlet.http.HttpServletRequest request, Object handler)
      Same as getSession(HttpServletRequest, Object, FlushMode) with FlushMode.AUTO. The flush mode is automatically determined from the annotations of the target controller and the request method.
      Parameters:
      request - the HTTP request
      handler - the Spring handler
      Returns:
      the AquimaSession corresponding to the request or null
    • getSession Link icon

      public final com.blueriq.component.api.IAquimaSession getSession(jakarta.servlet.http.HttpServletRequest request, Object handler, com.blueriq.component.api.FlushMode flushMode)
      Returns the AquimaSession for this request.

      The session is obtained from the session manager using a flush mode with a priority equal or higher than the provided flush mode. For example:

      • if the controller declares FlushMode.ALWAYS and this method is called with FlushMode.NEVER, the session is obtained using FlushMode.ALWAYS
      • if the controller declares FlushMode.NEVER and this method is called with FlushMode.ALWAYS, the session is obtained using FlushMode.ALWAYS
      • if neither the controller or the interceptor provide a flush mode (i.e. they use the implicit FlushMode.AUTO), the effective flush mode is determined based on the HTTP request method: POST, PUT, PATCH and DELETE imply intent to modify the session, so FlushMode.ALWAYS is used. Otherwise, FlushMode.NEVER is used.

      The identified session is cached as a request attribute. When multiple subclasses intercept the same request, only the first interceptor has to inspect the controller, as long as the FlushMode used by the interceptor has equal or lower precendence than the FlushMode used to obtain the session. When the FlushMode requested by an interceptor has higher precendence than a previously used FlushMode, the session is obtained again from the session manager using the new, higher precendence FlushMode.

      Parameters:
      request - the HTTP request
      handler - the Spring handler
      flushMode - the intent for the requested session
      Returns:
      the AquimaSession corresponding to the request or null
    • extractSessionId Link icon

      public final String extractSessionId(jakarta.servlet.http.HttpServletRequest request, org.springframework.core.MethodParameter parameter, com.blueriq.component.api.annotation.AquimaSessionId annotation)
      Extracts the session ID from the request.
      Parameters:
      request - the HTTP request
      parameter - the parameter of a controller method
      annotation - the annotation that contains the named parameter value
      Returns:
      the session ID or null if the session ID could not be extracted
    • extractEffectiveFlushMode Link icon

      public final com.blueriq.component.api.FlushMode extractEffectiveFlushMode(jakarta.servlet.http.HttpServletRequest request, com.blueriq.component.api.annotation.AquimaSessionId aquimaSessionId, com.blueriq.component.api.FlushMode interceptorFlushMode)