org.apache.wicket
public abstract class Session extends Object implements IClusterable, IEventSink
Component.getSession()
or by directly calling the static method Session.get(). All classes which extend directly or indirectly
WebMarkupContainer
can also use its convenience method
WebMarkupContainer.getWebSession()
setLocale(Locale)
. The Locale for a Session
determines how localized resources are found and loaded.
Application
for details). To
discourage non-typesafe access to Session properties, no setProperty() or getProperty() method is
provided. In a clustered environment, you should take care to call the dirty() method when you
change a property on your own. This way the session will be reset again in the http session so
that the http session knows the session is changed.
IClassResolver
)
implementation that is used to locate classes for components such as pages.
IPageFactory
is used to
instantiate pages for the session.
Modifier and Type | Field and Description |
---|---|
protected ClientInfo |
clientInfo
Cached instance of agent info which is typically designated by calling
getClientInfo() . |
static String |
SESSION_ATTRIBUTE_NAME
Name of session attribute under which this session is stored
|
Modifier and Type | Method and Description |
---|---|
void |
bind()
Force binding this session to the application's
session store if not
already done so. |
void |
cleanupFeedbackMessages()
Deprecated.
|
void |
clear()
Removes all pages from the session.
|
void |
debug(Serializable message)
Registers an debug feedback message for this session
|
void |
detach()
Any detach logic for session subclasses.
|
void |
dirty()
Marks session state as dirty so that it will be (re)stored in the ISessionStore
at the end of the request.
|
void |
dirty(boolean forced)
Marks session state as dirty so that it will be re-stored in the ISessionStore
at the end of the request.
|
void |
error(Serializable message)
Registers an error feedback message for this session
|
static boolean |
exists()
Checks existence of a
Session associated with the current thread. |
void |
fatal(Serializable message)
Registers an fatal feedback message for this session
|
static Session |
get()
Returns session associated to current thread.
|
Application |
getApplication()
Get the application that is currently working with this session.
|
Serializable |
getAttribute(String name)
Gets the attribute value with the given name
|
List<String> |
getAttributeNames() |
IAuthorizationStrategy |
getAuthorizationStrategy() |
IClassResolver |
getClassResolver() |
abstract ClientInfo |
getClientInfo()
Gets the client info object for this session.
|
FeedbackMessages |
getFeedbackMessages()
Gets feedback messages stored in session
|
String |
getId()
Gets the unique id for this session from the underlying SessionStore.
|
Locale |
getLocale()
Get this session's locale.
|
<M extends Serializable> |
getMetaData(MetaDataKey<M> key)
Gets metadata for this session using the given key.
|
IPageFactory |
getPageFactory() |
IPageManager |
getPageManager()
Returns the
IPageManager instance. |
protected ISessionStore |
getSessionStore()
Gets the session store.
|
long |
getSizeInBytes() |
String |
getStyle()
Get the style (see
Session ). |
void |
info(Serializable message)
Registers an informational feedback message for this session
|
void |
internalDetach()
NOT PART OF PUBLIC API, DO NOT CALL
Detaches internal state of
Session |
void |
invalidate()
Invalidates this session at the end of the current request.
|
void |
invalidateNow()
Invalidates this session immediately.
|
protected boolean |
isCurrentRequestValid(RequestCycle lockedRequestCycle)
Deprecated.
Not used since Wicket 1.5.0
|
boolean |
isSessionInvalidated()
Whether the session is invalid now, or will be invalidated by the end of the request.
|
boolean |
isTemporary()
Whether this session is temporary.
|
protected PageAccessSynchronizer |
newPageAccessSynchronizer(Duration timeout)
Factory method for PageAccessSynchronizer instances
|
int |
nextPageId() |
int |
nextSequenceValue()
Retrieves the next available session-unique value
|
void |
onEvent(IEvent<?> event)
Called when an event is sent to this sink
|
void |
onInvalidate()
A callback method that is executed when the user session is invalidated
either by explicit call to
invalidate()
or due to HttpSession expiration. |
void |
removeAttribute(String name)
Removes the attribute with the given name.
|
void |
replaceSession()
Replaces the underlying (Web)Session, invalidating the current one and creating a new one.
|
void |
setAttribute(String name,
Serializable value)
Adds or replaces the attribute with the given name and value.
|
void |
setClientInfo(ClientInfo clientInfo)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
setLocale(Locale locale)
Set the locale for this session.
|
void |
setMetaData(MetaDataKey<?> key,
Serializable object)
Sets the metadata for this session using the given key.
|
Session |
setStyle(String style)
Set the style (see
Session ). |
void |
success(Serializable message)
Registers an success feedback message for this session
|
void |
warn(Serializable message)
Registers a warning feedback message for this session
|
public static final String SESSION_ATTRIBUTE_NAME
protected ClientInfo clientInfo
getClientInfo()
.public Session(Request request)
RequestCycle
is not available until this constructor returns.request
- The current requestpublic static boolean exists()
Session
associated with the current thread.true
if get()
can return the instance of session,
false
otherwisepublic static Session get()
public final void bind()
session store
if not
already done so.
A Wicket application can operate in a session-less mode as long as stateless pages are used.
Session objects will be then created for each request, but they will only live for that
request. You can recognize temporary sessions by calling isTemporary()
which
basically checks whether the session's id is null. Hence, temporary sessions have no session
id.
By calling this method, the session will be bound (made not-temporary) if it was not bound
yet. It is useful for cases where you want to be absolutely sure this session object will be
available in next requests. If the session was already bound (
returns a session
), this call will be a noop.
@Deprecated public final void cleanupFeedbackMessages()
IApplicationSettings.setFeedbackMessageCleanupFilter(org.apache.wicket.feedback.IFeedbackMessageFilter)
for cleanup during testing see BaseWicketTester.cleanupFeedbackMessages()
public final void clear()
public final void error(Serializable message)
message
- The feedback messagepublic final void fatal(Serializable message)
message
- The feedback messagepublic final void debug(Serializable message)
message
- The feedback messagepublic final Application getApplication()
public IAuthorizationStrategy getAuthorizationStrategy()
public final IClassResolver getClassResolver()
public abstract ClientInfo getClientInfo()
setClientInfo(ClientInfo)
)
client info object.public final FeedbackMessages getFeedbackMessages()
public final String getId()
null
if a concrete session is not yet created.public Locale getLocale()
public final <M extends Serializable> M getMetaData(MetaDataKey<M> key)
M
- The type of the metadata.key
- The key for the dataMetaDataKey
@Deprecated protected boolean isCurrentRequestValid(RequestCycle lockedRequestCycle)
lockedRequestCycle
- public IPageFactory getPageFactory()
public final long getSizeInBytes()
public final String getStyle()
Session
).Session
)public final void info(Serializable message)
message
- The feedback messagepublic final void success(Serializable message)
message
- The feedback messagepublic void invalidate()
public void invalidateNow()
public void replaceSession()
ISessionStore.invalidate(Request)
and bind()
Call upon login to protect against session fixation.
public final boolean isSessionInvalidated()
invalidate()
,
invalidateNow()
public final boolean isTemporary()
public final void setClientInfo(ClientInfo clientInfo)
Sets the client info object for this session. This will only work when
getClientInfo()
is not overridden.
clientInfo
- the client info objectpublic void setLocale(Locale locale)
locale
- New localepublic final void setMetaData(MetaDataKey<?> key, Serializable object)
MetaDataKey
.key
- The singleton key for the metadataobject
- The metadata objectIllegalArgumentException
MetaDataKey
public final Session setStyle(String style)
Session
).style
- The style to set.public final void warn(Serializable message)
message
- The feedback messagepublic void detach()
public void internalDetach()
Session
public final void dirty()
public final void dirty(boolean forced)
forced
- A flag indicating whether the session should be marked as dirty even
when it is temporary. If true
the Session will be bound.public final Serializable getAttribute(String name)
name
- The name of the attribute to storepublic final List<String> getAttributeNames()
protected ISessionStore getSessionStore()
public final void removeAttribute(String name)
name
- the name of the attribute to removepublic final void setAttribute(String name, Serializable value)
name
- The name of the attributevalue
- The value of the attributepublic int nextSequenceValue()
public int nextPageId()
public final IPageManager getPageManager()
IPageManager
instance.IPageManager
instance.public void onEvent(IEvent<?> event)
onEvent
in interface IEventSink
public void onInvalidate()
invalidate()
or due to HttpSession expiration.
In case of session expiration this method is called in a non-worker thread, i.e.
there are no thread locals exported for the Application, RequestCycle and Session.
The Session is the current instance. The Application can be found by using
Application.get(String)
. There is no way to get a reference to a RequestCycle
protected PageAccessSynchronizer newPageAccessSynchronizer(Duration timeout)
timeout
- The configured timeout. See IRequestCycleSettings.getTimeout()
Copyright © 2006–2018 Apache Software Foundation. All rights reserved.