This sample application uses a single class to handle all of the login and logout process. This is an example of a TN5250 application running in an unmanaged environment. Similar samples are located in the directory ../../../toolkit/connector2/samples/tn5250/.
/** * An implementation of the simple application client. * It accesses the J2EE Connector directly without providing * any additional Quality of Service. */ // Import necessary packages and classes needed import java.util.*; import com.ibm.connector2.hod.*; import javax.naming.*; import javax.naming.directory.*; import java.util.Hashtable; import com.ibm.eNetwork.ECL.*; import com.ibm.eNetwork.ECL.screenreco.*; public class J2HODConnectorSample1 { public static void main(String[] args) { try { // Create session specific(TN5250) ManagedConnectionFactory J2HOD5250ManagedConnectionFactory mcf = new J2HOD5250ManagedConnectionFactory(); // Set trace level property mcf.setTraceLevel(new Integer(J2HODBaseManagedConnectionFactory.RAS_TRACE_ENTRY_EXIT)); // Set Host property mcf.setServerName("a_host_name"); // Set admin logWriter to System.err mcf.setLogWriter(new java.io.PrintWriter(System.err)); // Create EIS specific(HOD) connection factory from Managed Connection Factory J2HODConnectionFactory cf = (J2HODConnectionFactory)mcf.createConnectionFactory(); // set up ID and Password properties for ConnectionSpec J2HODConnectionSpec connectionSpec = new J2HODConnectionSpec(); connectionSpec.setUserName("user_id"); connectionSpec.setPassword("password"); // Create a connection from Connection Factory instance J2HODConnection connection = (J2HODConnection)cf.getConnection(connectionSpec); // Create an Host On-Demandinteraction from Connection instance J2HODInteraction interaction = (J2HODInteraction)connection.createInteraction(); // A record of input and output screen J2HODScreenRecord input = null; J2HODScreenRecord output = new J2HODScreenRecord(24, 80); // Check for Login screen (receive only for this execution) J2HODInteractionSpec interactionSpec = new J2HODInteractionSpec(); interactionSpec.setInteractionVerb(new Integer(J2HODInteractionSpec.SYNC_RECEIVE)); interactionSpec.setRecognizeRow(new Integer(1)); // Specify Row location to recognize interactionSpec.setRecognizeColumn(new Integer(36)); // Specify Column location to recognize interactionSpec.setRecognizeString("Sign On"); // Specify a string to recognized interactionSpec.setScreenName("Logon screen"); // Set the output screen name // Execute interaction and output gets updated connection.execute(interactionSpec, input, output); // Also used to check for output screen (optional) output.checkBytes("Sign On", 1, 36, false, true); // Use previous execution's output as next execution's input // and enter inputs for user ID and password at specified location. input = output; input.setString("user_id", 6, 53); input.setString("password", 7, 53); // For more complex description of output screen, a vector of ECLScreenDesc instances // can be used to describe the possible next output screen. // ( ** Refer to Host Access Client Library (HACL) document for more information on // ECLScreenDesc class and other HACL classes. ) // In this case after entering ID and PW, "Main Menu" or "Messages" screen is expected. Vector v = new Vector(); ECLScreenDesc screenDesc1 = new ECLScreenDesc(); screenDesc1.AddOIAInhibitStatus(ECLScreenDesc.NOTINHIBITED); screenDesc1.AddStringInRect("AS/400 Main Menu", 1, 1, 1, -1, true); screenDesc1.SetName("Main Menu"); v.add(screenDesc1); ECLScreenDesc screenDesc2 = new ECLScreenDesc(); screenDesc2.AddOIAInhibitStatus(ECLScreenDesc.NOTINHIBITED); screenDesc2.AddStringInRect("Press Enter to continue", 10, 1, 24, -1, true); screenDesc2.SetName("Messages"); v.add(screenDesc2); // Sets interaction specs (ENTER in this case) interactionSpec = new J2HODInteractionSpec(); //uses default properties interactionSpec.setScreenDescriptors(v); interactionSpec.setKeyName(J2HODInteractionSpec.ENTER); // Execute interaction connection.execute(interactionSpec, input, output); // Check to see if output screen is in "Main Menu" screen. boolean bOK = output.checkBytes("AS/400 Main Menu", 1, 1, 1, -1, false, false); if (!bOK) { // if not in "Main Menu" screen // type [enter] to exit the "Messages" screen and to get to the "Main Menu" screen input = output; output = new J2HODScreenRecord(24, 80); v.clear(); screenDesc1 = new ECLScreenDesc(); screenDesc1.AddOIAInhibitStatus(ECLScreenDesc.NOTINHIBITED); screenDesc1.AddStringInRect("AS/400 Main Menu", 1, 1, 1, -1, true); screenDesc1.SetName("Main Menu"); v.add(screenDesc1); interactionSpec = new J2HODInteractionSpec(); interactionSpec.setScreenDescriptors(v); interactionSpec.setKeyName(J2HODInteractionSpec.ENTER); // Execute interaction connection.execute(interactionSpec, input, output); } // in "Main Menu" screen input = output; output = new J2HODScreenRecord(24, 80); // Set string to select "90" for logoff as an input input.setString("90", 20, 7); // Specify what to recognize from the Output of execution interactionSpec = new J2HODInteractionSpec(); interactionSpec.setRecognizeRow(new Integer(1)); interactionSpec.setRecognizeColumn(new Integer(36)); interactionSpec.setRecognizeString("Sign On"); interactionSpec.setScreenName("Logon screen"); // Execute interaction and check output screen connection.execute(interactionSpec, input, output); output.checkBytes("Sign On", 1, 36, false, true); // Close interaction interaction.close(); // Close connection connection.close(); } catch (javax.resource.ResourceException exn2) { System.out.println("Operation failed: " + exn2); } catch (Exception ex) { System.out.println("***ERROR*** Operation failed: " + ex); } System.exit(0); } }
[ Top of Page | Previous Page | Next Page | Table of Contents ]