--Using SessionContext
1 post
• Page 1 of 1
--Using SessionContext
This article is outdated - please use our new system at
https://doc.sibvisions.com
SessionContext is an object available only at the server that enables access to session information as well as certain objects related to a session during the handling of a client request.
Example
We have developed an application that reviews all existing messages in an e-mail account and displays the number of messages. The request is initiated at the client by clicking a button.
The call using a button is illustrated in Client Actions or Server Actions
The server action accesses the mail server; the required access data is obtained from the application configuration.
Sample code for the server action:
- Code: Select all
/**
* Returns the number of mails from a preconfigured email account.
*
* @return the number of mails
*/
public int getEmailCount()
{
IConfiguration cfgSession = SessionContext.getCurrentSessionConfig();
String sServer = cfgSession.getProperty("/application/email/server");
String sPort = cfgSession.getProperty("/application/email/port");
String sProtocol = cfgSession.getProperty("/application/email/protocol");
String sUser = cfgSession.getProperty("/application/email/username");
String sPwd = cfgSession.getProperty("/application/email/password");
MailCheck mcheck = new MailCheck(sServer, sPort, sProtocol);
return mcheck.getMails(sUser, sPwd).size();
}
Excerpt from the configuration file:
- Code: Select all
...
...
<email>
<server>servername or ip</server>
<port>110</port>
<protocol>pop3</protocol>
<username>username</username>
<password>password</password>
</email>
</application>
SessionContext Life Cycle
Additional examples
SessionContext can also be used for the following:
- Access session properties (e.g. application name, username, client properties)
- Request the name of the current action
- Access the server configuration
- Use of the direct server connection
- Add or remove objects related to a call
-
Development@SIB - Posts: 325
- Joined: Mon Sep 28, 2009 1:54 pm
1 post
• Page 1 of 1