NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.0+)
myRequest.setLast(Gupta);
This example assumes that the server will accept a request that does not contain all of the fields in the definition.
Sending a Request
To send a request to a Pathway server, you must instantiate a TsmpServer object and call its service() method. The
TsmpServer object represents a communication session with a particular Pathway server or server class.
When you create the TsmpServer object, you must supply the following:
The name of the PATHMON process that monitors the Pathway server with which you want to communicate (as a
String)
●
The name of the Pathway server class with which you want to communicate (as a String)●
When you call the TsmpServer's service() method, you must supply the following:
A request object, instantiated from the generated request class created by ddl2java.●
A reply object, instantiated from the generated request class created by ddl2java. If the server can return multiple
replies, use a TsmpGenericServerReply object here.
●
The TsmpServer object transparently handles data conversion. Before it sends the request object, the TsmpServer calls a
protected method in the generated request class to convert data into the C or COBOL data types expected by the Pathway
server. After receiving the server's reply, TsmpServer converts the reply data to Java Strings. For more information, see
Data Conversion.
Continuing the example from the preceding section, create a TsmpServer called myServer to send the request
myRequest to the Pathway server JPSVR, monitored by the PATHMON process $PATHY:
TsmpServer myServer = new TsmpServer($PATHY, JPSVR);
myServer.service(myRequest, myGenReply);
The TsmpGenericServerReply object myGenReply will contain the reply.
Reading a Reply
To read a reply from a Pathway server, use either TsmpGenericServerReply or the getXXX() methods of the
generated reply class (each of which returns a Java String). Use TsmpGenericServerReply if the server can return
multiple replies and you need to determine which type of reply the server sent (for example, an error reply or the expected
reply).
Methods in the TsmpGenericServerReply class let you read both the reply code and the reply length. Use a method
appropriate for the DDL data type of the reply code. For example, if the reply code is a PIC X, retrieve it with getString.
Continuing the example from the preceding section, print the reply code and the message sent in response to the request
shown in Sending a Request:
// Create a generic server reply object called myGenReply
TsmpGenericServerReply myGenReply = new myGenReply();
// Call the generic server reply method getString to return the reply code.
// The reply code is at offset 20 within the reply buffer and a length of 1.
System.out.println(Reply code: + myGenReply.getString(20,1));