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
BCCciConnectionSpecobject. 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
Interactionobject and anInteractionSpecobject:Interaction ix = (Interaction)con.createInteraction(); BCCciInteractionSpec is = new BCCciInteractionSpec(InteractionSpec.SYNC_SEND_RECEIVE);
Whereas an
Interactionobject is created from theConnectionobject on which it is to be used, theInteractionSpecobject is created using a constructor of the implementation class.An
Interactionobject enables an EJB to communicate with an EIS application.
AnInteractionSpecobject 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
BCRecordobject that serves as a container for the message to the EIS and anotherBCRecordobject that serves as a container for the reply message. This is done by means of aBCRecordFactoryobject: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
BCRecordobject contains an emptyOltpMessageobject, which can be retrieved from theBCRecordobject. Subsequently, theBCRecordobject can be populated withOltpMessageRecordorOltpMessagePartobjects.Populate the
OltpMessageobject of the message which is destined for the EIS with data (here: with twoOltpMessagePartobjects):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
BCRecordobject returned from this call again holds anOltpMessageobject, which in turn contains the reply sent by the EISapplication in anOltpMessageRecordorOltpMessagePartobject.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 8 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
BCCciConnectionSpecobject. 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
Interactionobject and anInteractionSpecobject:An
Interactionobject enables an EJB to communicate with a partner application. AnInteractionSpecobject 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
Interactionobject is created from theconnectionobject on which it is to be used, theInteractionSpecis 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
ASYNTACspecifies that communication will be asynchronous.Here, the
SYNC_SENDhas the same effect as aflush()call when using the BeanConnect-specific interfaces.Create a
BCRecordobject 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
BCRecordobject contains an emptyOltpMessageobject, which can be retrieved from theBCRecordobject and then can be assigned withOltpMessageRecordand/orOltpMessagePartobjects.Populate the
OltpMessageobject of the request record with data (here: with twoOltpMessagePartobjects):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();