This is a helper class for other samples. This sample demonstrates how to implement reusable session-specific methods, logon and logoff, which can be accessed by other classes or applications. (The sample code creates a session from a router_URL and a user-supplied user name and password with appropriate access privileges.)
Note For a detailed explanation of the command line, see the Run the sample application section of the Run the Unmodified Samples topic.
The constructor code initializes variables for the user name, password, router_URL specification, and the logger object. Session logon and logoff are managed by the logon and logoff methods, respectively.
public SessionHelper(String user, String pw, String router, Logger){
m_userName = user;
m_password = pw;
m_routerPath = router;
m_logger = logger;
}
This logon method invokes the VWSession.logon() method and checks for errors.
try
{
// The following code initializes a session object.
m_vwSession = new VWSession(m_userName, m_password, m_routerPath);
}
catch (Exception ex)
{
if (m_logger != null)
m_logger.log(ex);
else
ex.printStackTrace();
}
return m_vwSession;
The logoff method invokes the VWSession.logoff() method and checks for errors. It can either log exceptions or print a stack trace, as shown below:
try {
// Logoff the session.
if (m_vwSession != null)
m_vwSession.logoff();
}
catch (Exception ex){
if (m_logger != null)
m_logger.log(ex);
else
ex.printStackTrace();
}
finally {
m_vwSession = null;
}