java.lang.Object
org.apache.wicket.session.HttpSessionStore
- All Implemented Interfaces:
ISessionStore
Implementation of
ISessionStore
that works with web applications and provides some
specific http servlet/ session related functionality.- Author:
- jcompagner, Eelco Hillenius, Matej Knopp
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static final class
Reacts on unbinding from the session by cleaning up the session related data.Nested classes/interfaces inherited from interface org.apache.wicket.session.ISessionStore
ISessionStore.BindListener, ISessionStore.UnboundListener
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds the provided new session to this facade using the provided request.void
destroy()
Called when the WebApplication is destroyed.void
flushSession
(Request request, Session session) Flushes the session.final Serializable
getAttribute
(Request request, String name) Gets the attribute value with the given namegetAttributeNames
(Request request) protected final jakarta.servlet.http.HttpServletRequest
getHttpServletRequest
(Request request) getSessionId
(Request request, boolean create) Get the session id for the provided request.final Set<ISessionStore.UnboundListener>
protected Session
getWicketSession
(Request request) Reads the WicketSession
from theHttpSession
's attributefinal void
invalidate
(Request request) Invalidates the session.final Session
Retrieves the session for the provided request from this facade.protected void
Template method that is called when a session is being bound to the session store.protected void
Template method that is called when the session is being detached from the store, which typically happens when theHttpSession
was invalidated.void
Registers listener invoked when session is bound.final void
Registers listener invoked when session is unbound.final void
removeAttribute
(Request request, String name) Removes the attribute with the given name.final void
setAttribute
(Request request, String name, Serializable value) Adds or replaces the attribute with the given name and value.protected void
setWicketSession
(Request request, Session session) Stores the WicketSession
in an attribute in theHttpSession
void
Unregisters listener invoked when session is bound.final void
Unregisters listener invoked when session is unbound.
-
Constructor Details
-
HttpSessionStore
public HttpSessionStore()
-
-
Method Details
-
getHttpServletRequest
- Parameters:
request
- The Wicket request- Returns:
- The http servlet request
-
bind
Description copied from interface:ISessionStore
Adds the provided new session to this facade using the provided request.- Specified by:
bind
in interfaceISessionStore
- Parameters:
request
- The request that triggered making a new sessionnewSession
- The new session
-
flushSession
Description copied from interface:ISessionStore
Flushes the session. Flushing the session generally means setting the attribute with the value of the current session. Some servlet containers use the setAttribute() as a signal that the value is dirty and needs to be replicated. Essentially this call comes down to:String attr=getSessionAttributeName(); Session session=getAttribute(attr); setAttribute(attr, session);
If the session is not yet bound it will be.- Specified by:
flushSession
in interfaceISessionStore
- Parameters:
request
- current requestsession
- session to be flushed
-
destroy
Description copied from interface:ISessionStore
Called when the WebApplication is destroyed.- Specified by:
destroy
in interfaceISessionStore
-
getSessionId
Description copied from interface:ISessionStore
Get the session id for the provided request. If create is false and the creation of the actual session is deferred, this method should return null to reflect it doesn't have one.- Specified by:
getSessionId
in interfaceISessionStore
- Parameters:
request
- The requestcreate
- Whether to create an actual session (typically an instance ofHttpSession
) when not already done so- Returns:
- The session id for the provided request, possibly null if create is false and the creation of the actual session was deferred
-
invalidate
Description copied from interface:ISessionStore
Invalidates the session.- Specified by:
invalidate
in interfaceISessionStore
- Parameters:
request
- the current request
-
lookup
Description copied from interface:ISessionStore
Retrieves the session for the provided request from this facade.This method should return null if it is not bound yet, so that Wicket can recognize that it should create a session and call
ISessionStore.bind(Request, Session)
right after that.- Specified by:
lookup
in interfaceISessionStore
- Parameters:
request
- The current request- Returns:
- The session for the provided request or null if the session was not bound
-
getWicketSession
Reads the WicketSession
from theHttpSession
's attribute- Parameters:
request
- The Wicket request- Returns:
- The Wicket Session or
null
-
setWicketSession
Stores the WicketSession
in an attribute in theHttpSession
- Parameters:
request
- The Wicket requestsession
- The Wicket session
-
onBind
Template method that is called when a session is being bound to the session store. It is called before the session object itself is added to this store (which is done by callingISessionStore.setAttribute(Request, String, Serializable)
with keySession.SESSION_ATTRIBUTE_NAME
.- Parameters:
request
- The requestnewSession
- The new session
-
onUnbind
Template method that is called when the session is being detached from the store, which typically happens when theHttpSession
was invalidated.- Parameters:
sessionId
- The session id of the session that was invalidated.
-
getAttribute
Description copied from interface:ISessionStore
Gets the attribute value with the given name- Specified by:
getAttribute
in interfaceISessionStore
- Parameters:
request
- the current requestname
- The name of the attribute to store- Returns:
- The value of the attribute
-
getAttributeNames
- Specified by:
getAttributeNames
in interfaceISessionStore
- Parameters:
request
- the current request- Returns:
- List of attributes for this session
-
removeAttribute
Description copied from interface:ISessionStore
Removes the attribute with the given name.- Specified by:
removeAttribute
in interfaceISessionStore
- Parameters:
request
- the current requestname
- the name of the attribute to remove
-
setAttribute
Description copied from interface:ISessionStore
Adds or replaces the attribute with the given name and value.- Specified by:
setAttribute
in interfaceISessionStore
- Parameters:
request
- the current requestname
- the name of the attributevalue
- the value of the attribute
-
registerUnboundListener
Description copied from interface:ISessionStore
Registers listener invoked when session is unbound.- Specified by:
registerUnboundListener
in interfaceISessionStore
-
unregisterUnboundListener
Description copied from interface:ISessionStore
Unregisters listener invoked when session is unbound.- Specified by:
unregisterUnboundListener
in interfaceISessionStore
-
getUnboundListener
- Specified by:
getUnboundListener
in interfaceISessionStore
- Returns:
- The list of registered unbound listeners
-
registerBindListener
Registers listener invoked when session is bound.- Specified by:
registerBindListener
in interfaceISessionStore
- Parameters:
listener
-
-
unregisterBindListener
Unregisters listener invoked when session is bound.- Specified by:
unregisterBindListener
in interfaceISessionStore
- Parameters:
listener
-
-
getBindListeners
- Specified by:
getBindListeners
in interfaceISessionStore
- Returns:
- The list of registered bind listeners
-