This final section provides the complete code for the main program used in this example. Every example program in the EPX installation takes at a minimum three arguments:
-server — the unique identifier of the server to log into. This parameter defaults to the first server returned by the EPX application server.
-user — the login identifier of the user to log in, defaults to the EPX super user system
-password — the password of the user to log in as, which defaults to the installation password of the EPX super user system, which is system
For example:
C:\Enterworks\EPX\examples\api\run.bat LoginExample
-server EPX_somehost -user system -password system public static void main(String args[]) throws Exception
{
try
{
String serverUID = null;
String user = "system";
String password = "system";
for ( int i=0 ; i < args.length; i++)
{
String arg = args[i];
if (arg.startsWith("-"))
{
if (arg.substring(1).equals("server"))
serverUID = args[++i];
else if (arg.substring(1).equals("user"))
user = args[++i];
else if (arg.substring(1).equals("password"))
password = args[++i];
}
}
LoginExample example =
new loginExample(serverUID,user,password);
// login
example.login();
if ( example.getSessionProfile() != null )
{
// show the session id
String vargs[] = {
example.getServerProfile().getDisplayLabel(),
String.valueOf (
example.getSessionProfile().getSessionId() ) };
System.out.println(
example.getMessage( "login.session", vargs) );
// log out example.logout();
}
}
catch( Exception e )
{
System.err.println ( "LoginExample.main(exception):" + e );
e.printStackTrace();
}
}
}