public class HttpSessionStore extends Object implements ISessionStore
ISessionStore
that works with web applications and provides some
specific http servlet/ session related functionality.Modifier and Type | Class and Description |
---|---|
protected static class |
HttpSessionStore.SessionBindingListener
Reacts on unbinding from the session by cleaning up the session related data.
|
ISessionStore.BindListener, ISessionStore.UnboundListener
Constructor and Description |
---|
HttpSessionStore() |
Modifier and Type | Method and Description |
---|---|
void |
bind(Request request,
Session newSession)
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.
|
Serializable |
getAttribute(Request request,
String name)
Gets the attribute value with the given name
|
List<String> |
getAttributeNames(Request request) |
Set<ISessionStore.BindListener> |
getBindListeners() |
protected javax.servlet.http.HttpServletRequest |
getHttpServletRequest(Request request) |
String |
getSessionId(Request request,
boolean create)
Get the session id for the provided request.
|
Set<ISessionStore.UnboundListener> |
getUnboundListener() |
protected Session |
getWicketSession(Request request)
Reads the Wicket
Session from the HttpSession 's attribute |
void |
invalidate(Request request)
Invalidates the session.
|
Session |
lookup(Request request)
Retrieves the session for the provided request from this facade.
|
protected void |
onBind(Request request,
Session newSession)
Template method that is called when a session is being bound to the session store.
|
protected void |
onUnbind(String sessionId)
Template method that is called when the session is being detached from the store, which
typically happens when the
HttpSession was invalidated. |
void |
registerBindListener(ISessionStore.BindListener listener)
Registers listener invoked when session is bound.
|
void |
registerUnboundListener(ISessionStore.UnboundListener listener)
Registers listener invoked when session is unbound.
|
void |
removeAttribute(Request request,
String name)
Removes the attribute with the given name.
|
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 Wicket
Session in an attribute in the HttpSession |
void |
unregisterBindListener(ISessionStore.BindListener listener)
Unregisters listener invoked when session is bound.
|
void |
unregisterUnboundListener(ISessionStore.UnboundListener listener)
Unregisters listener invoked when session is unbound.
|
protected final javax.servlet.http.HttpServletRequest getHttpServletRequest(Request request)
request
- The Wicket requestpublic final void bind(Request request, Session newSession)
ISessionStore
bind
in interface ISessionStore
request
- The request that triggered making a new sessionnewSession
- The new sessionpublic void flushSession(Request request, Session session)
ISessionStore
String attr=getSessionAttributeName();
Session session=getAttribute(attr);
setAttribute(attr, session);
If the session is not yet bound it will be.flushSession
in interface ISessionStore
request
- current requestsession
- session to be flushedpublic void destroy()
ISessionStore
destroy
in interface ISessionStore
public String getSessionId(Request request, boolean create)
ISessionStore
getSessionId
in interface ISessionStore
request
- The requestcreate
- Whether to create an actual session (typically an instance of HttpSession
)
when not already done sopublic final void invalidate(Request request)
ISessionStore
invalidate
in interface ISessionStore
request
- the current requestpublic final Session lookup(Request request)
ISessionStore
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.
lookup
in interface ISessionStore
request
- The current requestprotected Session getWicketSession(Request request)
Session
from the HttpSession
's attributerequest
- The Wicket requestnull
protected void setWicketSession(Request request, Session session)
Session
in an attribute in the HttpSession
request
- The Wicket requestsession
- The Wicket sessionprotected void onBind(Request request, Session newSession)
ISessionStore.setAttribute(Request, String, Serializable)
with key
Session.SESSION_ATTRIBUTE_NAME
.request
- The requestnewSession
- The new sessionprotected void onUnbind(String sessionId)
HttpSession
was invalidated.sessionId
- The session id of the session that was invalidated.public final Serializable getAttribute(Request request, String name)
ISessionStore
getAttribute
in interface ISessionStore
request
- the current requestname
- The name of the attribute to storepublic final List<String> getAttributeNames(Request request)
getAttributeNames
in interface ISessionStore
request
- the current requestpublic final void removeAttribute(Request request, String name)
ISessionStore
removeAttribute
in interface ISessionStore
request
- the current requestname
- the name of the attribute to removepublic final void setAttribute(Request request, String name, Serializable value)
ISessionStore
setAttribute
in interface ISessionStore
request
- the current requestname
- the name of the attributevalue
- the value of the attributepublic final void registerUnboundListener(ISessionStore.UnboundListener listener)
ISessionStore
registerUnboundListener
in interface ISessionStore
public final void unregisterUnboundListener(ISessionStore.UnboundListener listener)
ISessionStore
unregisterUnboundListener
in interface ISessionStore
public final Set<ISessionStore.UnboundListener> getUnboundListener()
getUnboundListener
in interface ISessionStore
public void registerBindListener(ISessionStore.BindListener listener)
registerBindListener
in interface ISessionStore
listener
- public void unregisterBindListener(ISessionStore.BindListener listener)
unregisterBindListener
in interface ISessionStore
listener
- public Set<ISessionStore.BindListener> getBindListeners()
getBindListeners
in interface ISessionStore
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.