public class MockWebSession extends Object implements WebSession
WebSession
that delegates to a session instance
obtained via InMemoryWebSessionStore
.
This is intended for use with the
session(WebSession)
method of the MockServerWebExchange
builder, eliminating the need
to use WebSessionManager
or WebSessionStore
altogether.
Constructor and Description |
---|
MockWebSession() |
MockWebSession(Clock clock) |
Modifier and Type | Method and Description |
---|---|
reactor.core.publisher.Mono<Void> |
changeSessionId()
Generate a new id for the session and update the underlying session
storage to reflect the new id.
|
Map<String,Object> |
getAttributes()
Return a map that holds session attributes.
|
Instant |
getCreationTime()
Return the time when the session was created.
|
String |
getId()
Return a unique session identifier.
|
Instant |
getLastAccessTime()
Return the last time of session access as a result of user activity such
as an HTTP request.
|
Duration |
getMaxIdleTime()
Return the maximum time after the
lastAccessTime before a session expires. |
reactor.core.publisher.Mono<Void> |
invalidate()
Invalidate the current session and clear session storage.
|
boolean |
isExpired()
Return
true if the session expired after maxIdleTime elapsed. |
boolean |
isStarted()
Whether a session with the client has been started explicitly via
WebSession.start() or implicitly by adding session attributes. |
reactor.core.publisher.Mono<Void> |
save()
Save the session through the
WebSessionStore as follows:
If the session is new (i.e. |
void |
setMaxIdleTime(Duration maxIdleTime)
Configure the max amount of time that may elapse after the
lastAccessTime before a session is considered
expired. |
void |
start()
Force the creation of a session causing the session id to be sent when
WebSession.save() is called. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAttribute, getAttributeOrDefault, getRequiredAttribute
public String getId()
WebSession
getId
in interface WebSession
public Map<String,Object> getAttributes()
WebSession
getAttributes
in interface WebSession
public void start()
WebSession
WebSession.save()
is called.start
in interface WebSession
public boolean isStarted()
WebSession
WebSession.start()
or implicitly by adding session attributes.
If "false" then the session id is not sent to the client and the
WebSession.save()
method is essentially a no-op.isStarted
in interface WebSession
public reactor.core.publisher.Mono<Void> changeSessionId()
WebSession
WebSession.getId()
reflects the new session id.changeSessionId
in interface WebSession
public reactor.core.publisher.Mono<Void> invalidate()
WebSession
invalidate
in interface WebSession
public reactor.core.publisher.Mono<Void> save()
WebSession
WebSessionStore
as follows:
WebSession.start()
or implicitly by adding
attributes, or otherwise this method should have no effect.
WebSessionStore
,
the implementation for this method must check whether the session was
invalidated
and if so return an error.
Note that this method is not intended for direct use by applications. Instead it is automatically invoked just before the response is committed.
save
in interface WebSession
Mono
to indicate completion with success or errorpublic boolean isExpired()
WebSession
true
if the session expired after maxIdleTime
elapsed.
Typically expiration checks should be automatically made when a session
is accessed, a new WebSession
instance created if necessary, at
the start of request processing so that applications don't have to worry
about expired session by default.
isExpired
in interface WebSession
public Instant getCreationTime()
WebSession
getCreationTime
in interface WebSession
public Instant getLastAccessTime()
WebSession
maxIdleTimeInSeconds
this helps to determine when a session is
expired
.getLastAccessTime
in interface WebSession
public void setMaxIdleTime(Duration maxIdleTime)
WebSession
lastAccessTime
before a session is considered
expired. A negative value indicates the session should not expire.setMaxIdleTime
in interface WebSession
public Duration getMaxIdleTime()
WebSession
lastAccessTime
before a session expires. A negative time indicates the
session doesn't expire.getMaxIdleTime
in interface WebSession