484 IMS Connectivity in an On Demand Environment: A Practical Guide to IMS Connectivity
Java sample source code
Example A-2 provides the Java sample source code.
Example: A-2 Sample Java code for an IMS Connect client (non-IMS Connector for Java)
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.Socket;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
/**
* IMS Connector sample client written in Java
* This class implements a basic IMS Connect client using the TCP/IP
* sockets interface.
*
* @author Jordi Guillaumes Pons and others
*
*/
public class Sample {
private Socket socket = null;
// connection information
private String hostName;
private int portNumber;
// IMS information
private String tranCode;
private String tranText;
private String datastoreID;
private String ltermName;
private Collection response;
// RACF security information
private String racfUserID;
private String racfGroupName;
private String password;
// IMS Connect information
private String clientID;
private String exitID;
private byte syncLevel;
private byte commitMode;
private boolean sendOnly;
private boolean resumeTpipe;
private boolean ackRequired;
private boolean nakRequired;
private int prefixLength = 96; // With IRM_ARCH = 0x01
private byte timer;
private boolean reRoute;
private boolean purgeAsync;
private String reRouteName;
private boolean RSM = false; // Response is RSM
private int returnCode = 0;
Appendix A. Sample code: Non-IMS Connector for Java client code 485
private int reasonCode = 0;
public static final byte CM0 = (byte) 0x40;
public static final byte CM1 = (byte) 0x20;
public static final byte SL_NONE = (byte) 0;
public static final byte SL_CONFIRM = (byte) 0x01;
public static final byte SL_SYNCPT = (byte) 0x02;
public static final byte SL_PURGE = (byte) 0x04;
public static final byte SL_REROUTE = (byte) 0x08;
public static final byte IRM_F5_NONE = (byte) 0x00;
public static final byte IRM_F5_SINGLE = (byte) 0x01;
public static final byte IRM_F5_AUTO = (byte) 0x02;
public static final byte IRM_F5_NOAUTO = (byte) 0x04;
///////////////////////////////////////////////////////////////////
// Constructor //
///////////////////////////////////////////////////////////////////
/**
* Constructor for a Sample object.
*
* @param hostName Host name or IP address in dot format
* @param portNumber Port number which IMS Connect listens
* @param datastoreID Name of the IMS System we want to send transactions
* @param ltermName LTERM override
* @param tranCode Transaction code
* @param tranText Transaction text
* @param clientID Unique client identification
* @param racfUserID RACF User id
* @param racfGroupName RACF Group name
* @param password RACF password
* @param syncLevel Sync Level coded value
* @param commitMode Commit Mode coded value
* @param sendOnly This interaction will be send only
* @param resumeTpipe This interaction is a RESUME TPIPE
*/
public Sample(
String hostName,
int portNumber,
String datastoreID,
String ltermName,
String tranCode,
String tranText,
String clientID,
String racfUserID,
String racfGroupName,
String password,
byte syncLevel,
byte commitMode,
boolean sendOnly,
boolean resumeTpipe,
byte timer,
boolean purge,
boolean reroute,
String rerouteName) {
// set the corresponding transaction data, making all strings 8
// characters long
this.hostName = hostName;
this.portNumber = portNumber;
this.datastoreID = stringPad(datastoreID, ' ', 8);
486 IMS Connectivity in an On Demand Environment: A Practical Guide to IMS Connectivity
this.ltermName = stringPad(ltermName, ' ', 8);
this.tranCode = stringPad(tranCode, ' ', 8);
this.tranText = tranText;
this.clientID = stringPad(clientID, ' ', 8);
this.racfUserID = stringPad(racfUserID, ' ', 8);
this.racfGroupName = stringPad(racfGroupName, ' ', 8);
this.password = stringPad(password, ' ', 8);
this.reRouteName = stringPad(rerouteName, ' ', 8);
// Set the interaction parameters
this.syncLevel = syncLevel;
this.commitMode = commitMode;
this.sendOnly = sendOnly;
this.resumeTpipe = resumeTpipe;
this.timer = timer;
this.purgeAsync = purge;
this.reRoute = reroute;
// We will use HWSSMPL0
this.exitID = "*SAMPLE*";
}
///////////////////////////////////////////////////////////////////
// Communications setup methods //
///////////////////////////////////////////////////////////////////
/**
* Establish a socket connection with the IMS Connect host
*/
public void connect() {
try {
// open a socket for the transaction
socket = new Socket(hostName, portNumber);
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
/**
* Drop the socket connection.
*/
public void disconnect() {
// verify socket open before attempting to disconnect
if (socket != null) {
try {
socket.close();
socket = null;
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
}
}
///////////////////////////////////////////////////////////////////
// Send and receive methods //
///////////////////////////////////////////////////////////////////
/**

Get IMS Connectivity in an On Demand Environment: A Practical Guide to IMS Connectivity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.