Use resource adapters from an application
The following example shows how you might access the CICS ECI resource adapter from an application. This code snippet assumes you have a resource reference called...
eis/ref/ECICICS
...that points to a...
javax.resource.cci.ConnectionFactory
...with the JNDI name...
eis/ECICICS
It is a minimal sample, with no connection factory caching, and so on.
private int getRate(String source) throws java.lang.Exception { // get JNDI context javax.naming.InitialContext ctx = new javax.naming.InitialContext(); // get local JNDI environment javax.naming.Context env = (javax.naming.Context)ctx.lookup("java:comp/env"); javax.resource.cci.ConnectionFactory connectionFactory connectionFactory = (javax.resource.cci.ConnectionFactory) env.lookup("eis/ref/ECICICS"); // get a connection to the EIS javax.resource.cci.Connection connection = connectionFactory.getConnection(); // create an interaction and a CICS ECI specific interaction spec javax.resource.cci.Interaction interaction = connection.createInteraction(); com.ibm.connector2.cics.ECIInteractionSpec interactionSpec = new com.ibm.connector2.cics.ECIInteractionSpec(); // create the comm area record source = (source.trim().toUpperCase()+" ").substring(0, 12); GenericRecord record = new GenericRecord((source).getBytes("IBM037")); // set the CICS program name we want to call interactionSpec.setFunctionName("CALCRATE"); // invoke the CICS program interaction.execute(interactionSpec, record, record); // close the interation and the connection interaction.close(); connection.close(); // get the results from the return comm area record byte[] commarea = record.getCommarea(); int value = Integer.parseInt(new String(commarea, "IBM037").substring(8,12).trim()); return value; }