Loading...
Select Version
&pagelevel(4)&pagelevel
This section contains the following code samples:
Example 7 Dialog communication using the EISConnection interface
...
public String callService(String request) throws EJBException
{
net.fsc.jca.communication.EISConnectionFactory cf = null;
net.fsc.jca.communication.EISConnection con = null;
String reply = null;
try
{
javax.naming.InitialContext ic = new javax.naming.InitialContext();
cf = (net.fsc.jca.communication.EISConnectionFactory) ic.lookup("java:comp/env/eis/myEIS");
con= cf.getConnection();
reply = con.call(request);
con.close();
con = null;
return reply;
}
catch (Exception e)
{
if (con != null)
{
con.close();
}
throw new EJBException ("EJB Exception: " + e);
}
}
To allow you to use this method, the deployment descriptor of the EJB must contain the following information:
<resource-ref>
<res-ref-name>eis/myEIS</res-ref-name>
<res-type>net.fsc.jca.communication.EISConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
Example 8 Dialog communication using the CCI
...
public String sndRcvJavax(String user, String name, String data)
{
String retValue = "";
Connection connection = null;
try {
Context ic = new InitialContext();
ConnectionFactory cf = ConnectionFactory)ic.lookup("java:comp/env/eis/myEIS");
ConnectionSpec cred = new BCCciConnectionSpec (user, "");
connection = cf.getConnection(cred);
Interaction ix = connection.createInteraction();
InteractionSpec is = new BCCciInteractionSpec(InteractionSpec.SYNC_SEND_RECEIVE,"HELLO");
BCRecordFactory recordFactory = (BCRecordFactory)cf.getRecordFactory();
BCRecord in = recordFactory.createBCRecord("SendRecord");
BCRecord out = recordFactory.createBCRecord("ReceiveRecord");
OltpMessage inMsg = in.getOltpMessage();
inMsg.addMessagePart(data);
out = (BCRecord)ix.execute(is, in);
OltpMessage outMsg = out.getOltpMessage();
Iterator it<OltpMessagePart> = outMsg.getMessageParts();
OltpMessagePart msgPart;
while (it.hasNext()) {
msgPart = it.next();
retValue += msgPart.getText();
}
} catch ( Throwable ex) {
// Todo: Fehlerbehandlung
}// tryCatch
try {
if ( connection != null )
connection.close(); }
catch (ResourceException e){
retValue += "\n during connection.close():\n"+getStackInfo(e);
}
return retValue;
} // sndRcvJavax
To allow you to use this method, the deployment descriptor of the EJB must contain the following information:
<resource-ref>
<res-ref-name>eis/myEIS</res-ref-name>
<res-type>net.fsc.jca.communication.EISConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
Example 9 Associated connections using the EISConnectionGroup interface
...
EISOltpConnection con1 = null;
EISOltpConnection con2 = null;
try {
javax.naming.InitialContext ic = new javax.naming.InitialContext();
cf = (net.fsc.jca.communication.EISConnectionFactory)
ic.lookup("java:comp/env/eis/myEIS");
EISConnectionGroupFactory cgf = cf.getEISConnectionGroupFactory();
EISConnectionGroup cg = cgf.getConnectionGroup();
con1 = (EISOltpConnection)cf.getConnection(cg, new PasswordCredential("upicusea", ""));
con2 = (EISOltpConnection)cf.getConnection(cg, new PasswordCredential("upicuseb", ""));
OltpMessage om1 = con1.createMessage();
om1.addMessagePart("STAT");
OltpMessage om2 = con2.createMessage();
om2.addMessagePart("osi-con,l=kdcall");
con1.sndOltpMessage(om1);
con2.sndOltpMessage(om2);
cg.execute();
String s;
om2 = con2.rcvOltpMessage();
Iterator iter<OltpMessageRecord> = om2.getMessageRecords();
for (s = ""; iter.hasNext(); )
{ s+= iter.next()).getText(); }
String result_o = "";
result_o = result_o + "OltpConnection: KDCINF osi-con, l=kdcall\n" + s + "\n";
om1 = con1.rcvOltpMessage();
iter = om1.getMessageRecords();
for (s = ""; iter.hasNext(); ) {
s+= ((OltpMessageRecord)iter.next()).getText(); }
result_o = addResult_o(result_o, "OltpConnection: KDCINF STAT\n" + s + "\n");
s = cg.getGroupName();
result_o = result_o + "OltpConnection: KDCINF STAT\n" +s + "\n");
con1.close();
con2.close();
return result_o;
} catch(EISConnectionException ex) {
...