public class SimpleSession extends java.lang.Object implements Session, SessionCtrl
Session
.
Note:
Though this class is serializable, it is meaningless to serialize
it directly. Reason: it doesn't serialize any session attributes.
Rather, it is serialized when Web server serialized HttpSession.
Also, notice that SimpleSession
is stored as an attribute
HttpSession.
Modifier | Constructor and Description |
---|---|
protected |
SimpleSession()
Used by the deriving class,
only if the deriving class implements java.io.Serializable.
|
|
SimpleSession(WebApp wapp,
javax.servlet.http.HttpSession hsess,
java.lang.Object request)
Constructs a ZK session with a HTTP session.
|
|
SimpleSession(WebApp wapp,
java.lang.Object navsess,
java.lang.Object request)
Constructs a ZK session with either a HTTP session or a Portlet session.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addScopeListener(ScopeListener listener)
Adds a listener to listen whether this scope is changed.
|
java.lang.Object |
getAttribute(java.lang.String name)
Returns the value of the specified custom attribute.
|
java.lang.Object |
getAttribute(java.lang.String name,
boolean recurse)
Returns the custom attribute associated with this object.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Returns a map of custom attributes associated with this session.
|
DesktopCache |
getDesktopCache()
Returns the desktop cache, or null if not available.
|
java.lang.String |
getDeviceType()
Returns the device type that this session belongs to.
|
java.lang.String |
getLocalAddr()
Returns the Internet Protocol (IP) address of the interface on which
the first request was received (and creates this session).
|
java.lang.String |
getLocalName()
Returns the host name of the Internet Protocol (IP) interface
on which the first request was received (and creates this session).
|
int |
getMaxInactiveInterval()
Return the time, in seconds, between client requests before
the servlet container will invalidate this session.
|
java.lang.Object |
getNativeSession()
Returns the native session, or null if not available.
|
java.lang.String |
getRemoteAddr()
Returns the Internet Protocol (IP) address of the client or last
proxy that sent the first request creating this session.
|
java.lang.String |
getRemoteHost()
Returns the fully qualified name of the client or the last proxy
that sent the first request creating this session.
|
java.lang.String |
getServerName()
Returns the host name of the server to which the first request was sent
(and created this session).
|
WebApp |
getWebApp()
Returns the Web application that this session belongs to.
|
boolean |
hasAttribute(java.lang.String name)
Returns if a custom attribute is associated with this object (scope).
|
boolean |
hasAttribute(java.lang.String name,
boolean recurse)
Returns if a custom attribute is associated with this object.
|
void |
invalidate()
Invalidates this session then unbinds any objects bound to it.
|
void |
invalidateNow()
Really invalidates the session.
|
boolean |
isInvalidated()
Returns whether this session is invalidated
(i.e.,
Session.invalidate() was called). |
boolean |
notifyClientRequest(boolean keepAlive)
Notifies the session that a client request is received.
|
void |
onDestroyed()
Called when the session is destroyed.
|
protected void |
readThis(java.io.ObjectInputStream s)
Used by the deriving class to read back this object,
only if the deriving class implements java.io.Serializable.
|
void |
recover(java.lang.Object nativeSession)
Called when ZK detects
Session.getNativeSession()
is not initialized properly. |
java.lang.Object |
removeAttribute(java.lang.String name)
Removes the specified custom attribute.
|
java.lang.Object |
removeAttribute(java.lang.String name,
boolean recurse)
Removes the custom attribute associated with this scope.
|
boolean |
removeScopeListener(ScopeListener listener)
Removes a change listener from this scope.
|
protected void |
sessionDidActivate(javax.servlet.http.HttpSession hsess)
Used by the deriving class to post-process a session after
it is read back.
|
protected void |
sessionWillPassivate()
Used by the deriving class to pre-process a session before writing
the session
|
java.lang.Object |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets the value of the specified custom attribute.
|
java.lang.Object |
setAttribute(java.lang.String name,
java.lang.Object value,
boolean recurse)
Sets the custom attribute associated with this scope, or the parent
scope.
|
void |
setDesktopCache(DesktopCache cache)
Sets the desktop cache.
|
void |
setDeviceType(java.lang.String deviceType)
Sets the device type that this session belongs to.
|
void |
setMaxInactiveInterval(int interval)
Specifies the time, in seconds, between client requests before
the servlet container will invalidate this session.
|
protected void |
writeThis(java.io.ObjectOutputStream s)
Used by the deriving class to write this object,
only if the deriving class implements java.io.Serializable.
|
public SimpleSession(WebApp wapp, javax.servlet.http.HttpSession hsess, java.lang.Object request)
hsess
- the original HTTP session.request
- the original request causing this session to be created.
If HTTP and servlet, it is javax.servlet.http.HttpServletRequest.
If portlet, it is javax.portlet.RenderRequest.public SimpleSession(WebApp wapp, java.lang.Object navsess, java.lang.Object request)
Note: it assumes the scope of attributes is PortletSession.APPLICATION_SCOPE.
navsess
- the original session, either an instance of
HttpSession or PortletSession.
Notice: we don't declare PortletSession in API
to avoid this class failed to be loaded in some system (without
portlet-api.jar)request
- the original request causing this session to be created.
If portlet, it is javax.portlet.RenderRequest.protected SimpleSession()
public java.lang.String getDeviceType()
Session
A device type identifies the type of a client. For example, "ajax" represents the Web browsers with Ajax support, while "mil" represents clients that supports Mobile Interactive markup Language (on Limited Connected Device, such as mobile phones).
All desktops of the same session must belong to the same device type.
The session's device type is determined by the first desktop's device type.
getDeviceType
in interface Session
public void setDeviceType(java.lang.String deviceType)
SessionCtrl
It is called by the desktop when Desktop.setDeviceType(java.lang.String)
is called.
Don't call this method directly. Otherwise, the result is unpredictable.
setDeviceType
in interface SessionCtrl
public java.lang.Object getAttribute(java.lang.String name)
Session
getAttribute
in interface Scope
getAttribute
in interface Session
public java.lang.Object getAttribute(java.lang.String name, boolean recurse)
Scope
getAttribute
in interface Scope
recurse
- whether to search its ancestor scope.
If true and the current scope doen't define the attribute,
it searches up its ancestor to see
any of them has defined the specified attribute.public boolean hasAttribute(java.lang.String name)
Scope
Notice that null
is a valid value, so you can
tell if an attribute is associated by examining the return value
of Scope.getAttribute(java.lang.String)
.
hasAttribute
in interface Scope
public boolean hasAttribute(java.lang.String name, boolean recurse)
Scope
Notice that null
is a valid value, so you can
tell if an attribute is associated by examining the return value
of Scope.getAttribute(java.lang.String)
.
hasAttribute
in interface Scope
recurse
- whether to search its ancestor scope.
If true and the current scope doen't define the attribute,
it searches up its ancestor to see
any of them has defined the specified attribute.public java.lang.Object setAttribute(java.lang.String name, java.lang.Object value)
Session
setAttribute
in interface Scope
setAttribute
in interface Session
public java.lang.Object setAttribute(java.lang.String name, java.lang.Object value, boolean recurse)
Scope
setAttribute
in interface Scope
recurse
- whether to look up the parent scope for the
existence of the attribute.Scope.setAttribute(String,Object)
.public java.lang.Object removeAttribute(java.lang.String name, boolean recurse)
Scope
removeAttribute
in interface Scope
recurse
- whether to look up the parent scope for the
existence of the attribute.Scope.removeAttribute(String)
.public java.lang.Object removeAttribute(java.lang.String name)
Session
removeAttribute
in interface Scope
removeAttribute
in interface Session
public boolean addScopeListener(ScopeListener listener)
Scope
addScopeListener
in interface Scope
public boolean removeScopeListener(ScopeListener listener)
Scope
removeScopeListener
in interface Scope
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Session
getAttributes
in interface Scope
getAttributes
in interface Session
public java.lang.String getRemoteAddr()
Session
getRemoteAddr
in interface Session
public java.lang.String getRemoteHost()
Session
getRemoteHost
in interface Session
public java.lang.String getServerName()
Session
getServerName
in interface Session
Session.getLocalName()
public java.lang.String getLocalName()
Session
Note: it is the host name defined in the server. To retrieve the name
in URL, use Session.getServerName()
.
getLocalName
in interface Session
Session.getServerName()
public java.lang.String getLocalAddr()
Session
getLocalAddr
in interface Session
public void invalidateNow()
SessionCtrl
Application shall never access this method.
invalidateNow
in interface SessionCtrl
public void setMaxInactiveInterval(int interval)
Session
setMaxInactiveInterval
in interface Session
Configuration.setTimerKeepAlive(boolean)
,
Configuration.setSessionMaxInactiveInterval(int)
public int getMaxInactiveInterval()
Session
getMaxInactiveInterval
in interface Session
Configuration.isTimerKeepAlive()
,
Configuration.getSessionMaxInactiveInterval()
public java.lang.Object getNativeSession()
Session
getNativeSession
in interface Session
public boolean notifyClientRequest(boolean keepAlive)
SessionCtrl
notifyClientRequest
in interface SessionCtrl
keepAlive
- if the request will keep the session alive,
or the request shall be ignored.
If the request shall be ignored and the session is timeout,
it will cause the session to expire (i.e., be invalidated).public final WebApp getWebApp()
Session
public final void invalidate()
Session
Note: you usually have to ask the client to redirect to another page
(or reload the same page) by use of Executions.sendRedirect(java.lang.String)
.
The session is not invalidated immediately. Rather, it is invalidated after processing the current request.
invalidate
in interface Session
public final boolean isInvalidated()
SessionCtrl
Session.invalidate()
was called).
Note: ZK doesn't invalidate it immediately (until the event has been processed), so the session might be still alive.
isInvalidated
in interface SessionCtrl
public DesktopCache getDesktopCache()
SessionCtrl
Note: this is an utility to implement DesktopCacheProvider
,
which might or might not use this method. Other part of ZK shall not
access this method.
getDesktopCache
in interface SessionCtrl
public void setDesktopCache(DesktopCache cache)
SessionCtrl
Note: this is an utility to implement DesktopCacheProvider
,
which might or might not use this method. Other part of ZK shall not
access this method.
setDesktopCache
in interface SessionCtrl
cache
- the desktop cache; null to denote no cache available.public void recover(java.lang.Object nativeSession)
SessionCtrl
Session.getNativeSession()
is not initialized properly.
It is actually a workaround to solve the issue that some Web container fails to call HttpSessionActivationListener.sessionDidActivate() upon failover.
It can be used to solve the issue that the mapping between the native session and the ZK session is changed. For example, you might manually invalidate the http session and recreate one. Then, you have to call this method to associate the ZK session with the new created session.
recover
in interface SessionCtrl
public void onDestroyed()
SessionCtrl
Application shall never access this method.
onDestroyed
in interface SessionCtrl
protected void writeThis(java.io.ObjectOutputStream s) throws java.io.IOException
java.io.IOException
protected void readThis(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
protected void sessionWillPassivate()
protected void sessionDidActivate(javax.servlet.http.HttpSession hsess)
Application shall not call this method directly.
Copyright © 2005-2023 Potix Corporation. All Rights Reserved.