Package org.apache.wicket.session
Class HttpSessionStore
- java.lang.Object
-
- org.apache.wicket.session.HttpSessionStore
-
- All Implemented Interfaces:
ISessionStore
public class HttpSessionStore extends java.lang.Object implements ISessionStore
Implementation ofISessionStorethat works with web applications and provides some specific http servlet/ session related functionality.- Author:
- jcompagner, Eelco Hillenius, Matej Knopp
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classHttpSessionStore.SessionBindingListenerReacts 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
Constructors Constructor Description HttpSessionStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(org.apache.wicket.request.Request request, Session newSession)Adds the provided new session to this facade using the provided request.voiddestroy()Called when the WebApplication is destroyed.voidflushSession(org.apache.wicket.request.Request request, Session session)Flushes the session.java.io.SerializablegetAttribute(org.apache.wicket.request.Request request, java.lang.String name)Gets the attribute value with the given namejava.util.List<java.lang.String>getAttributeNames(org.apache.wicket.request.Request request)java.util.Set<ISessionStore.BindListener>getBindListeners()protected javax.servlet.http.HttpServletRequestgetHttpServletRequest(org.apache.wicket.request.Request request)java.lang.StringgetSessionId(org.apache.wicket.request.Request request, boolean create)Get the session id for the provided request.java.util.Set<ISessionStore.UnboundListener>getUnboundListener()protected SessiongetWicketSession(org.apache.wicket.request.Request request)Reads the WicketSessionfrom theHttpSession's attributevoidinvalidate(org.apache.wicket.request.Request request)Invalidates the session.Sessionlookup(org.apache.wicket.request.Request request)Retrieves the session for the provided request from this facade.protected voidonBind(org.apache.wicket.request.Request request, Session newSession)Template method that is called when a session is being bound to the session store.protected voidonUnbind(java.lang.String sessionId)Template method that is called when the session is being detached from the store, which typically happens when theHttpSessionwas invalidated.voidregisterBindListener(ISessionStore.BindListener listener)Registers listener invoked when session is bound.voidregisterUnboundListener(ISessionStore.UnboundListener listener)Registers listener invoked when session is unbound.voidremoveAttribute(org.apache.wicket.request.Request request, java.lang.String name)Removes the attribute with the given name.voidsetAttribute(org.apache.wicket.request.Request request, java.lang.String name, java.io.Serializable value)Adds or replaces the attribute with the given name and value.protected voidsetWicketSession(org.apache.wicket.request.Request request, Session session)Stores the WicketSessionin an attribute in theHttpSessionvoidunregisterBindListener(ISessionStore.BindListener listener)Unregisters listener invoked when session is bound.voidunregisterUnboundListener(ISessionStore.UnboundListener listener)Unregisters listener invoked when session is unbound.
-
-
-
Method Detail
-
getHttpServletRequest
protected final javax.servlet.http.HttpServletRequest getHttpServletRequest(org.apache.wicket.request.Request request)
- Parameters:
request- The Wicket request- Returns:
- The http servlet request
-
bind
public final void bind(org.apache.wicket.request.Request request, Session newSession)Description copied from interface:ISessionStoreAdds the provided new session to this facade using the provided request.- Specified by:
bindin interfaceISessionStore- Parameters:
request- The request that triggered making a new sessionnewSession- The new session
-
flushSession
public void flushSession(org.apache.wicket.request.Request request, Session session)Description copied from interface:ISessionStoreFlushes 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:
flushSessionin interfaceISessionStore- Parameters:
request- current requestsession- session to be flushed
-
destroy
public void destroy()
Description copied from interface:ISessionStoreCalled when the WebApplication is destroyed.- Specified by:
destroyin interfaceISessionStore
-
getSessionId
public java.lang.String getSessionId(org.apache.wicket.request.Request request, boolean create)Description copied from interface:ISessionStoreGet 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:
getSessionIdin 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
public final void invalidate(org.apache.wicket.request.Request request)
Description copied from interface:ISessionStoreInvalidates the session.- Specified by:
invalidatein interfaceISessionStore- Parameters:
request- the current request
-
lookup
public final Session lookup(org.apache.wicket.request.Request request)
Description copied from interface:ISessionStoreRetrieves 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:
lookupin interfaceISessionStore- Parameters:
request- The current request- Returns:
- The session for the provided request or null if the session was not bound
-
getWicketSession
protected Session getWicketSession(org.apache.wicket.request.Request request)
Reads the WicketSessionfrom theHttpSession's attribute- Parameters:
request- The Wicket request- Returns:
- The Wicket Session or
null
-
setWicketSession
protected void setWicketSession(org.apache.wicket.request.Request request, Session session)Stores the WicketSessionin an attribute in theHttpSession- Parameters:
request- The Wicket requestsession- The Wicket session
-
onBind
protected void onBind(org.apache.wicket.request.Request request, Session newSession)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
protected void onUnbind(java.lang.String sessionId)
Template method that is called when the session is being detached from the store, which typically happens when theHttpSessionwas invalidated.- Parameters:
sessionId- The session id of the session that was invalidated.
-
getAttribute
public final java.io.Serializable getAttribute(org.apache.wicket.request.Request request, java.lang.String name)Description copied from interface:ISessionStoreGets the attribute value with the given name- Specified by:
getAttributein interfaceISessionStore- Parameters:
request- the current requestname- The name of the attribute to store- Returns:
- The value of the attribute
-
getAttributeNames
public final java.util.List<java.lang.String> getAttributeNames(org.apache.wicket.request.Request request)
- Specified by:
getAttributeNamesin interfaceISessionStore- Parameters:
request- the current request- Returns:
- List of attributes for this session
-
removeAttribute
public final void removeAttribute(org.apache.wicket.request.Request request, java.lang.String name)Description copied from interface:ISessionStoreRemoves the attribute with the given name.- Specified by:
removeAttributein interfaceISessionStore- Parameters:
request- the current requestname- the name of the attribute to remove
-
setAttribute
public final void setAttribute(org.apache.wicket.request.Request request, java.lang.String name, java.io.Serializable value)Description copied from interface:ISessionStoreAdds or replaces the attribute with the given name and value.- Specified by:
setAttributein interfaceISessionStore- Parameters:
request- the current requestname- the name of the attributevalue- the value of the attribute
-
registerUnboundListener
public final void registerUnboundListener(ISessionStore.UnboundListener listener)
Description copied from interface:ISessionStoreRegisters listener invoked when session is unbound.- Specified by:
registerUnboundListenerin interfaceISessionStore
-
unregisterUnboundListener
public final void unregisterUnboundListener(ISessionStore.UnboundListener listener)
Description copied from interface:ISessionStoreUnregisters listener invoked when session is unbound.- Specified by:
unregisterUnboundListenerin interfaceISessionStore
-
getUnboundListener
public final java.util.Set<ISessionStore.UnboundListener> getUnboundListener()
- Specified by:
getUnboundListenerin interfaceISessionStore- Returns:
- The list of registered unbound listeners
-
registerBindListener
public void registerBindListener(ISessionStore.BindListener listener)
Registers listener invoked when session is bound.- Specified by:
registerBindListenerin interfaceISessionStore- Parameters:
listener-
-
unregisterBindListener
public void unregisterBindListener(ISessionStore.BindListener listener)
Unregisters listener invoked when session is bound.- Specified by:
unregisterBindListenerin interfaceISessionStore- Parameters:
listener-
-
getBindListeners
public java.util.Set<ISessionStore.BindListener> getBindListeners()
- Specified by:
getBindListenersin interfaceISessionStore- Returns:
- The list of registered bind listeners
-
-