Loading...
Select Version
Dieser Abschnitt erhält die folgenden Code-Beispiele:
Dialogbasierte Kommunikation unter Verwendung des Interfaces EISConnection.
Dialogbasierte Kommunikation unter Verwendung des Interfaces CCI.
Connection Groups unter Verwendung des Interfaces EISConnectionGroup.
Beispiel 14 Dialogbasierte Kommunikation unter Verwendung des Interfaces EISConnection
... 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); } }
Damit Sie diese Methode verwenden können, muss der Deployment Descriptor der EJB folgende Informationen beinhalten:
<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>
Beispiel 15 Dialogbasierte Kommunikation unter Verwendung des Interfaces 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 bei connection.close():\n"+getStackInfo(e); } return retValue; } // sndRcvJavax
Damit Sie diese Methode verwenden können, muss der Deployment Descriptor der EJB folgende Informationen beinhalten:
<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>
Beispiel 16 Connection Groups unter Verwendung des Interfaces EISConnectionGroup
... 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) { ...