Previous Next Contents Index


ISession2 interface (deprecated)

The ISession2 interface is deprecated and is provided for backward compatibility only. New applications should use the methods provided by the standard javax.servlet.http.HttpSession interface. In addition, NAS provides the HttpSession2 interface, an extension to HttpSession that supports applications that must call AppLogics.

For more information, see Chapter 11, "Creating and Managing User Sessions," in the Programmer's Guide (Java) or the Migration Guide.

The ISession2 interface represents a session between a user and an application. AppLogics use sessions to store information about each user's interaction with the application. For example, a login AppLogic might create a session object to store the user's login name and password. This session data is then available to other AppLogics in the application.

Session data is stored in a distributed state layer in the Netscape Application Server, so that the data is available even when the server destroys the AppLogic when it has finished executing. Storing the session data in the distributed state layer also enables AppLogics running in different clusters or servers to access the data.

A session has the following attributes, which are set when the AppLogic creates a session:

The ISession2 interface defines methods for setting and retrieving data in a session. It also defines methods for retrieving the attributes—ID, associated application, timeout value, and scope—of a session.

To create an instance of the ISession2 interface, use the createSession( ) method in the AppLogic class.

If your application requires a custom session object, for example, to support additional methods, you can subclass the Session2 class (deprecated) and define your own methods.

Package
com.kivasoft

Methods
Method
Description
getSessionApp( )
Returns the name of the application associated with the session.
getSessionData( )
Returns session data.
getSessionFlags( )
Returns the flags associated with the session when it was created.
getSessionID( )
Returns the session ID.
getSessionTimeout( )
Returns the session's timeout value in seconds.
saveSession( )
Saves changes to a session.
setSessionData( )
Sets session data.

getSessionApp( )
Returns the name of the application associated with the session.

Syntax
public String getSessionApp()
Usage
Use getSessionApp( ) to retrieve the name of the application associated with the session. All AppLogics in an application have access to the same session data.

Return Value
A string representing the application name, or null for failure.

Example
The following code shows how to create a session and get the name of the application associated with the session:

ISession2 sess;

//Create a session and associate it with myApp application
sess=createSession(GXSESSION.GXSESSION_DISTRIB,
0, "myApp", null, null);

//Get the application name associated with the session
//getSessionApp() should return "myApp"
String appname;
appname = sess.getSessionApp();
if (appname == null)
return result("getSessionApp returned error");
log("Session application name:" + appname);
Related Topics
createSession( ) in the AppLogic class

getSessionData( )
Returns session data.

Syntax
public IValList getSessionData()
Usage
Use getSessionData( ) to retrieve session data for processing. Data is returned in an IValList object. This method retrieves the contents that were last saved in the distributed store with saveSession( ). Use methods in the IValList interface to iterate through and access items in the IValList object.

Return Value
IValList object containing the session information, or null for failure.

Example
public class OBSession extends Object

{
protected ISession2 systemSession;
public IValList sessionValList = null;

public OBSession(ISession2 app_session)
{
systemSession = app_session;

// Retrieve session data
sessionValList = systemSession.getSessionData();
}
// Method for retrieving the user name from session data
public String getUserName()
{
// Return the userName value
return sessionValList.getValString("userName");
Related Topics
createSession( ) in the AppLogic class

getSessionFlags( )
Returns the flags associated with the session when it was created.

Syntax
public int getSessionFlags()
Usage
Use getSessionFlags( ) to retrieve the flags that were specified when the session was created with createSession( ). The following table describes the valid session flags, which are static variables in the GXSESSION class:

Flag
Description
GXSESSION_LOCAL
The session is visible to the local process only.
GXSESSION_CLUSTER
The session is visible to all AppLogics within the cluster.
GXSESSION_DISTRIB
The session is visible to all AppLogics in the enterprise environment.
GXSESSION_TIMEOUT_CREATE
The session expires n seconds from the time the node was created.

Return Value
The flags listed in the previous table.

Example
The following code shows how to create a session and get the associated flags:

ISession2 sess;

//Create a session with distributed scope
sess=createSession(GXSESSION.GXSESSION_DISTRIB,
0, "myApp", null, null);

//Get the flag assigned to the session
//getSessionFlag() should return GXSESSION_DISTRIB
int flag;
flag = sess.getSessionFlags();
log("Session flag:" + flag);
Related Topics
createSession( ) in the AppLogic class

getSessionID( )
Returns the session ID.

Syntax
public String getSessionID()
Usage
Use getSessionID( ) to retrieve the unique ID associated with a session.

Return Value
A string representing the session ID, or null for failure.

Example
The following code shows how to create a session and get the session ID:

ISession2 sess;

//Create a session using the default ID generator
sess=createSession(GXSESSION.GXSESSION_DISTRIB,
0, "myApp", null, null);

//Get the session ID
String sessid;
sessid = sess.getSessionID();
if (sessid == null)
return result("getSessionID returned error");
log("Session ID:" + sessid);
Related Topics
createSession( ) in the AppLogic class

getSessionTimeout( )
Returns the session's timeout value in seconds.

Syntax
public int getSessionTimeout()
Usage
Use getSessionTimeout( ) to find out if a session is terminated after a specified time, or if it needs to be terminated explicitly. A timeout value of 0 means the session ends when it is explicitly terminated with the destroySession( ) method.

Return Value
Integer representing the timeout value in seconds.

Example
The following code shows how to create a session and get session's timeout value:

ISession2 sess;

//Create a session with no timeout value
sess=createSession(GXSESSION.GXSESSION_DISTRIB,
0, "myApp", null, null);

//Get the timeout value
//getSessionTimeout() should return 0
int timeout;
timeout = sess.getSessionTimeout();
log("Session timeout value:" + timeout);
Related Topics
createSession( ) in the AppLogic class

saveSession( )
Saves changes to a session.

Syntax
public int saveSession(
	int dwFlags)

dwFlags. Specify 0 (zero).

Usage
Use saveSession( ) to ensure changes are saved in the distributed state storage area, which stores the session information for subsequent use if any other AppLogic objects are invoked within the same session.

Tips
Return Value
GXE.SUCCESS if the method succeeds.

Related Topics
createSession( ) and saveSession( ) in the AppLogic class

setSessionData( )
Updates session with specified data.

Syntax
public int setSessionData(
	IValList pSessionData)

pSessionData. The IValList object containing the session data to set.

Usage
Use setSessionData( ) to write or update session data. Session data is stored in a distributed state layer in the Netscape Application Server, making session data accessible to distributed server processes.

Tips
Return Value
GXE.SUCCESS if the method succeeds.

Related Topics
createSession( ) in the AppLogic class

 

© Copyright 1999 Netscape Communications Corp.