Femto Web Server V1.4-F

dfischer.femtowebserver.httpd
Class HttpdSession

java.lang.Object
  |
  +--dfischer.femtowebserver.httpd.HttpdSession

public class HttpdSession
extends java.lang.Object

HTTP sessions can be used to overlay the stateless HTTP protocol with stateful information, valid over the whole surfing session of an user.

The Femto Web Server supports HTTP sessions, if a special HttpdFilter has been added first to the Httpd, which generates and manages all sessions. Implementing an own HttpdFilter to manage the sessions in collaboration with the HttpdSessionHashtable is fully supported - but the easier way is to use the already implemented HttpSessionCookieHandler.

See Also:
Httpd.addFilter(String, String[]), HttpdFilter, HttpdSessionHashtable, HttpdProperties.getSessionHashtable(), HttpRequest.getSession(), HttpResponse.getSession()

Constructor Summary
HttpdSession(java.lang.String sessionId)
          Creates a new session, initializes the session creation time and sets the access count to 1.
HttpdSession(java.lang.String sessionId, java.lang.String remoteAddress)
          Creates a new session, initializes the session creation time, sets the access count to 1 and sets the TCP/IP remote address.
HttpdSession(java.lang.String sessionId, java.lang.String remoteAddress, java.lang.String lastSessionInfo)
          Creates a new session, initializes the session creation time, sets the access count to 1, sets the TCP/IP remote address and sets an informational text about the session.
 
Method Summary
 long getAccessCount()
          Returns the total number a HTTP request which have made during the session.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the object bound with a specific name to the session.
 java.util.Enumeration getAttributNames()
          Returns an Enumeration of Strings of all object names bound to this session.
 long getCreationTime()
          Returns the time when this session was created.
 java.lang.String getId()
          Returns the session id.
 long getLastAccessTime()
          Returns the last time when the user has sent a HTTP request, bound on this session.
 java.lang.String getLastSessionInfo()
          Returns the informational text about the session.
 java.lang.String getRemoteAddress()
          Returns the raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd).
 void invalidate()
          Invalidates the session.
 boolean isNew()
          Returns true if the session was newly created.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Allows to bind an object to the session, so that it's accessible during the whole HTTP session.
 void setLastSessionInfo(java.lang.String lastSessionInfo)
          Updates the informational text about the session.
 void setRemoteAddress(java.lang.String remoteAddress)
          Allows to alternate the remote address of agent (because it has changed: DHCP).
 void updateLastAccess(java.lang.String remoteAddress)
          Updates the last access time, increments the access count and updates the remote TCP/IP address of the agent.
 void updateLastAccess(java.lang.String remoteAddress, java.lang.String lastSessionInfo)
          Updates the last access time, increments the access count, updates the remote TCP/IP address of the agent and updates the informational text about the session.
 void updateLastAccessTime()
          Updates the last access time and increments the access count.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpdSession

public HttpdSession(java.lang.String sessionId)
Creates a new session, initializes the session creation time and sets the access count to 1. Used in filters. After creating the session it must be added to the HttpdSessionHashtable.
Parameters:
sessionId - the new session id. This is the key to the session und must be unique over all already existing session ids.
See Also:
HttpdProperties.getSessionHashtable(), HttpdSessionHashtable.addSession(java.lang.String, dfischer.femtowebserver.httpd.HttpdSession)

HttpdSession

public HttpdSession(java.lang.String sessionId,
                    java.lang.String remoteAddress)
Creates a new session, initializes the session creation time, sets the access count to 1 and sets the TCP/IP remote address. Used in filters. After creating the session it must be added to the HttpdSessionHashtable.
Parameters:
sessionId - the new session id. This is the key to the session und must be unique over all already existing session ids.
remoteAddress - raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd) without DNS lookup.
See Also:
HttpdProperties.getSessionHashtable(), HttpdSessionHashtable.addSession(java.lang.String, dfischer.femtowebserver.httpd.HttpdSession), getId(), getRemoteAddress(), setRemoteAddress(java.lang.String)

HttpdSession

public HttpdSession(java.lang.String sessionId,
                    java.lang.String remoteAddress,
                    java.lang.String lastSessionInfo)
Creates a new session, initializes the session creation time, sets the access count to 1, sets the TCP/IP remote address and sets an informational text about the session. Used in filters. After creating the session it must be added to the HttpdSessionHashtable.
Parameters:
sessionId - the new session id. This is the key to the session und must be unique over all already existing session ids.
remoteAddress - raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd) without DNS lookup.
lastSessionInfo - informational text about the session. Used for debugging or visualizing sessions.
See Also:
HttpdProperties.getSessionHashtable(), HttpdSessionHashtable.addSession(java.lang.String, dfischer.femtowebserver.httpd.HttpdSession), getId(), getRemoteAddress(), setRemoteAddress(java.lang.String)
Method Detail

getId

public java.lang.String getId()
Returns the session id. This is the unique key to this session.
Returns:
the session id.
See Also:
HttpdFilter, HttpdProperties.getSessionHashtable(), HttpdSessionHashtable.addSession(java.lang.String, dfischer.femtowebserver.httpd.HttpdSession), HttpdSessionHashtable.getSession(java.lang.String), HttpdSessionHashtable.removeSession(java.lang.String)

getRemoteAddress

public java.lang.String getRemoteAddress()
Returns the raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd).
Returns:
the raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd) or null, if no remote address is available.
See Also:
setRemoteAddress(java.lang.String)

setRemoteAddress

public void setRemoteAddress(java.lang.String remoteAddress)
Allows to alternate the remote address of agent (because it has changed: DHCP). Used in filters.
Parameters:
remoteAddress - new raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd) without DNS lookup.
See Also:
getRemoteAddress()

isNew

public boolean isNew()
Returns true if the session was newly created.
Returns:
true if the session was newly created.

invalidate

public void invalidate()
Invalidates the session. For the same user, a new session will be created at the next HTTP request.

The session will only be removed from the HttpdSessionHashtable if (thereafter) one of the methods dropInactiveSessions() or dropLongSessions() is called.

See Also:
HttpdSessionHashtable.dropInactiveSessions(int), HttpdSessionHashtable.dropLongSessions(int)

getCreationTime

public long getCreationTime()
Returns the time when this session was created.
Returns:
the time when this session was created, measured in milliseconds since first January 1970
See Also:
HttpdSessionHashtable.dropLongSessions(int), getLastAccessTime(), getAccessCount()

getLastAccessTime

public long getLastAccessTime()
Returns the last time when the user has sent a HTTP request, bound on this session.
Returns:
the last time when the user has sent a HTTP request, bound on this session. Measured in milliseconds since first January 1970.
See Also:
HttpdSessionHashtable.dropInactiveSessions(int), getCreationTime(), updateLastAccess(java.lang.String), updateLastAccessTime(), getAccessCount()

updateLastAccess

public void updateLastAccess(java.lang.String remoteAddress)
Updates the last access time, increments the access count and updates the remote TCP/IP address of the agent. Used in Filters.
Parameters:
remoteAddress - the current raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd) without DNS lookup.
See Also:
HttpdFilter, HttpdSessionHashtable, updateLastAccessTime(), getLastAccessTime(), getAccessCount(), getRemoteAddress()

updateLastAccess

public void updateLastAccess(java.lang.String remoteAddress,
                             java.lang.String lastSessionInfo)
Updates the last access time, increments the access count, updates the remote TCP/IP address of the agent and updates the informational text about the session. Used in Filters.
Parameters:
remoteAddress - the current raw TCP/IP remote address of agent (aaa.bbb.ccc.ddd) without DNS lookup.
lastSessionInfo - informational text about the session. Used for debugging or visualizing sessions.
See Also:
HttpdFilter, HttpdSessionHashtable, updateLastAccessTime(), getLastAccessTime(), getAccessCount(), getRemoteAddress()

updateLastAccessTime

public void updateLastAccessTime()
Updates the last access time and increments the access count. Used in Filters.
See Also:
HttpdFilter, HttpdSessionHashtable, getLastAccessTime(), getAccessCount()

getAccessCount

public long getAccessCount()
Returns the total number a HTTP request which have made during the session.
Returns:
the total number a HTTP request which have made during the session
See Also:
getCreationTime(), getLastAccessTime()

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Allows to bind an object to the session, so that it's accessible during the whole HTTP session.
Parameters:
name - the arbitrary name of the object. If an other object has already been bound with the same name, the (old) object will be overwritten.
value - the object to bind
See Also:
getAttribute(java.lang.String), getAttributNames()

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the object bound with a specific name to the session.
Parameters:
name - the name of the object
Returns:
the bounded object or null, if no object with that name was found.
See Also:
setAttribute(java.lang.String, java.lang.Object), getAttributNames()

getAttributNames

public java.util.Enumeration getAttributNames()
Returns an Enumeration of Strings of all object names bound to this session.
Returns:
Enumeration of Strings of all object names bound to this session.
See Also:
setAttribute(java.lang.String, java.lang.Object), getAttribute(java.lang.String)

setLastSessionInfo

public void setLastSessionInfo(java.lang.String lastSessionInfo)
Updates the informational text about the session. Used in Filters.
Parameters:
lastSessionInfo - informational text about the session. Used for debugging or visualizing sessions.
See Also:
getLastSessionInfo()

getLastSessionInfo

public java.lang.String getLastSessionInfo()
Returns the informational text about the session. Used in Filters.
Returns:
The informational text about the session. Used for debugging or visualizing sessions.
See Also:
setLastSessionInfo(java.lang.String)

Femto Web Server V1.4-F

Copyright 2002, 2003, 2006 by Ingenieurbüro David Fischer GmbH, Switzerland. All rights reserved.