Interface SessionInterceptor<A,B extends Session<A>,C extends SessionContext.Intercepted<A,B>,D extends Exchange<C>>

Type Parameters:
A - the session data type
B - the session type
C - the exchange context type
D - the exchange type
All Superinterfaces:
ExchangeInterceptor<C,D>

public interface SessionInterceptor<A,B extends Session<A>,C extends SessionContext.Intercepted<A,B>,D extends Exchange<C>> extends ExchangeInterceptor<C,D>

The session interceptor extracts the session identifier send by a requester, resolves the session, populates the session context in the exchange, injects the session into the exchange and saves the session after the request has been processed.

It typically executes session related operations at various steps during the processing of an exchange:

  • Before the exchange handler is invoked: it tries to extract the session identifier using a SessionIdExtractor and resolve the session and eventually populates the SessionContext.
  • When a session is created: it injects the session in the exchange using a SessionInjector.
  • Before sending the response: it injects the session in the exchange if the session identifier needed to be refreshed, or it removes the session from the exchange if the session has been invalidated.
  • After the response was sent: it saves the session if it hasn't been invalidated.

It is important to keep above sequence in mind when interacting with the session. For instance, changes that would result in a stale session identifier must be performed before sending the response so this cannot happen in the response body publisher and must be done by invoking ResponseBody.before(Mono). Otherwise, the session identifier is eventually refreshed when the session is saved, but the client might not be able to see it because the session is only injected before sending the response since it is not possible to set response headers after.

The session is only saved after the response has been completely sent which means it is possible to update session data while sending the response payload. It also means that any change is only persisted after the exchange has been processed successfully, it can hopefully be saved explicitly before that.

Since:
1.13
Author:
Jeremy Kuhn
  • Method Details

    • of

      static <A, B extends Session<A>, C extends SessionContext.Intercepted<A, B>, D extends Exchange<C>> SessionInterceptor<A,B,C,D> of(SessionIdExtractor<C,D> sessionIdExtractor, SessionStore<A,B> sessionStore, SessionInjector<A,B,C,D> sessionInjector)

      Creates a session interceptor with the specified session identifier extractor, session store and session injector.

      Type Parameters:
      A - the session data type
      B - the session type
      C - the exchange context type
      D - the exchange type
      Parameters:
      sessionIdExtractor - the session identifier extractor
      sessionStore - the session store
      sessionInjector - the session injector
      Returns:
      a new session interceptor