When deploying a managed connection factory in BeanConnect you specify the EIS partner to be addressed via this managed connection factory. You use the lookup()
method to search for the connection factory and obtain a connectivity object by calling the getCon
nection()
method.
You can request an interaction object via the CCI connection which you obtain from the CCI connection factory. This interaction object implements an execute()
method for initiating an interaction. The execute()
method also knows a BCCciInteractionSpec
object in addition to the input record and output record. In this BCCciInteractionSpec
you define an interactionVerb
(SYNC_SEND
, SYNC_SEND_RECEIVE
or SYNC_RECEIVE
) and, at the same time, the name of the EIS application. This enables you to control an interaction by providing suitable data instead of calling methods. The default value of the interactionVerb is SYNC_SEND_RECEIVE
.
For details, see the JavaDoc of BeanConnect.
Program framework for dialog communication (CCI)
For dialog communication with your server application over the CCI Interface in BeanConnect, proceed as follows:
Set up the initial context:
javax.naming.InitialContext ic = new InitialContext();
Reference a connection factory:
javax.resource.cci.ConnectionFactory cf = (ConnectionFactory)ic.lookup("java:comp/env/eis/myEIS");
A dialog service is assigned as the default service to the connection factory referenced by
eis/myEIS
.Set up the connection
javax.resource.cci.Connection con = (Connection)cf.getConnection();
Alternatively, an EJB may pass security-related information (user ID/password) to BeanConnect in a
BCCciConnectionSpec
object. In this case you specify:net.fsc.jca.communication.cci.BCCciConnectionSpec; cred = new BCCciConnectionSpec("myuser", "mypass"); javax.resource.cci.Connection con = (Connection)cf.getConnection(cred);
Create an
Interaction
object and anInteractionSpec
object:Interaction ix = (Interaction)con.createInteraction(); BCCciInteractionSpec is = new BCCciInteractionSpec(InteractionSpec.SYNC_SEND_RECEIVE);
Whereas an
Interaction
object is created from theConnection
object on which it is to be used, theInteractionSpec
object is created using a constructor of the implementation class.An
Interaction
object enables an EJB to communicate with an EIS application.
AnInteractionSpec
object holds properties for driving an interaction with this EIS application. It is used by an interaction to execute the specified function in the EIS application.Create a
BCRecord
object that serves as a container for the message to the EIS and anotherBCRecord
object that serves as a container for the reply message. This is done by means of aBCRecordFactory
object:net.fsc.jca.communication.cci.BCRecordFactory rf = (BCRecordFactory)cf.getRecordFactory(); net.fsc.jca.communication.cci.BCRecord reqrec = (BCRecord) rf.createB- CRecord("request"); net.fsc.jca.communication.cci.BCRecord replrec = (BCRecord) rf.createB- CRecord("reply");
After creation, a
BCRecord
object contains an emptyOltpMessage
object, which can be retrieved from theBCRecord
object. Subsequently, theBCRecord
object can be populated withOltpMessageRecord
orOltpMessagePart
objects.Populate the
OltpMessage
object of the message which is destined for the EIS with data (here: with twoOltpMessagePart
objects):net.fsc.jca.communication.OltpMessage request = reqrec.getOltpMessage(); request.addMessagePart("request - message part1"); request.addMessagePart("request - message part2");
Execute the interaction:
ix.execute(is, reqrec, replrec);
The
BCRecord
object returned from this call again holds anOltpMessage
object, which in turn contains the reply sent by the EISapplication in anOltpMessageRecord
orOltpMessagePart
object.Receive the reply message:
net.fsc.jca.communication.OltpMessage reply = replrec.getOltpMessage(); java.util.Iterator<net.fsc.jca.communication.OltpMessagePart> it = reply.getMessageParts(); net.fsc.jca.communication.OltpMessagePart msgPart; String msgText=""; while (it.hasNext()) { msgPart = (OltpMessagePart) it.next(); msgText += msgPart.getText(); }
Close the connection:
con.close();
Further information on how to program the CCI interfaces is provided in the JavaDoc of the CCI.
You will find a code sample in Example 14 on Code samples for outbound communication .
Program framework for asynchronous communication (CCI)
For asynchronous communication with your server application over the CCI Interface in BeanConnect, proceed as follows:
Set up the initial context:
javax.naming.Context ic = new InitialContext();
Reference a ConnectionFactory:
javax.resource.cci.ConnectionFactory cf = (ConnectionFactory)ic.lookup("java:comp/env/eis/myAsyncEIS");
Set up the connection:
javax.resource.cci.Connection con = (Connection)cf.getConnection();
Alternatively, an EJB may pass security-related information (user ID/password) to BeanConnect in a
BCCciConnectionSpec
object. In this case you specify:net.fsc.jca.communication.cci.BCCciConnectionSpec cred = new BCCciConnectionSpec("myuser", "mypass"); javax.resource.cci.Connection con = (Connection)cf.getConnection(cred);
Create an
Interaction
object and anInteractionSpec
object:An
Interaction
object enables an EJB to communicate with a partner application. AnInteractionSpec
object holds properties for driving an interaction with a partner application. It is used by an interaction to execute the specified function in the EIS application.Whereas an
Interaction
object is created from theconnection
object on which it is to be used, theInteractionSpec
is created using a constructor of the implementation class:Interaction ix = (Interaction)con.createInteraction(); net.fsc.jca.communication.cci.BCCciInteractionSpec is = new BCCciInteractionSpec(InteractionSpec.SYNC_SEND, "ASYNTAC");
The assignment of the asynchronous service
ASYNTAC
specifies that communication will be asynchronous.Here, the
SYNC_SEND
has the same effect as aflush()
call when using the BeanConnect-specific interfaces.Create a
BCRecord
object that serves as a container for the request message. This is done by means of arecordFactory
:net.fsc.jca.communication.cci.BCRecordFactory rf= (BCRecordFactory)cf.getRecordFactory(); net.fsc.jca.communication.cci.BCRecord reqrec = rf.createBCRecord("request");
After creation, a
BCRecord
object contains an emptyOltpMessage
object, which can be retrieved from theBCRecord
object and then can be assigned withOltpMessageRecord
and/orOltpMessagePart
objects.Populate the
OltpMessage
object of the request record with data (here: with twoOltpMessagePart
objects):net.fsc.jca.communication.OltpMessage request = reqrec.getOltpMessage(); request.addMessagePart("request - message part1"); request.addMessagePart("request - message part2");
Execute the interaction:
ix.execute(is, reqrec);
Close the connection:
con.close();