001: // InboundCASLR.java
002: // Stateless Session bean
003:
004: package org.objectweb.jonas.jtests.beans.jca15;
005:
006: import java.rmi.RemoteException;
007: import javax.ejb.CreateException;
008: import javax.ejb.EJBException;
009: import javax.ejb.RemoveException;
010: import javax.ejb.EJBObject;
011: import javax.ejb.SessionBean;
012: import javax.ejb.SessionContext;
013: import javax.naming.Context;
014: import javax.naming.InitialContext;
015: import javax.naming.NamingException;
016: import javax.resource.cci.Connection;
017: import javax.resource.spi.ManagedConnection;
018: import javax.resource.spi.ConnectionEvent;
019: import javax.resource.spi.ResourceAdapter;
020: import ersatz.resourceadapter.ManagedConnectionFactoryImpl;
021: import ersatz.resourceadapter.ConnectionImpl;
022: import ersatz.resourceadapter.ConnectionFactoryImpl;
023: import ersatz.resourceadapter.ResourceAdapterImpl;
024:
025: /**
026: *
027: */
028: public class InboundCASLR implements SessionBean {
029:
030: SessionContext ejbContext;
031: private ConnectionFactoryImpl cccf = null; //Common Client Connection Factory
032: private ManagedConnectionFactoryImpl mcf = null;
033: private ConnectionImpl conn = null;
034: InitialContext ic = null;
035: String cName = "InboundCASLR";
036:
037: // ------------------------------------------------------------------
038: // SessionBean implementation
039: // ------------------------------------------------------------------
040:
041: public void setSessionContext(SessionContext ctx) {
042: Utility.log(cName + "setSessionContext");
043: ejbContext = ctx;
044: }
045:
046: public void ejbRemove() {
047: Utility.log("");
048: }
049:
050: public void ejbCreate() throws CreateException {
051: Utility.log("");
052: }
053:
054: public void ejbPassivate() {
055: Utility.log("");
056: }
057:
058: public void ejbActivate() {
059: Utility.log("");
060: }
061:
062: // ------------------------------------------------------------------
063: // InboundCA implementation
064: // ------------------------------------------------------------------
065:
066: /**
067: * method1
068: */
069: public void method1(String rar_jndi_name, String testName)
070: throws Exception {
071: Utility.log("============================ " + testName);
072: try {
073: ic = new InitialContext();
074: } catch (Exception e1) {
075: Utility
076: .log(cName
077: + ".method1 error: InitialContext failed");
078: throw e1;
079: }
080: try {
081: cccf = (ConnectionFactoryImpl) ic.lookup(rar_jndi_name);
082: Utility.log(cName + ".method1 : found " + rar_jndi_name);
083: } catch (Exception e2) {
084: Utility.log(cName + ".method1 error: lookup failed for "
085: + rar_jndi_name);
086: throw e2;
087: }
088:
089: try {
090: conn = (ConnectionImpl) cccf.getConnection();
091: Utility
092: .log(cName + ".method1 : getConnection conn="
093: + conn);
094: if (conn == null) {
095: Utility
096: .log(cName
097: + ".method1 error: getConnection returned null connection.");
098: throw new Exception("");
099: }
100: } catch (Exception e3) {
101: Utility.log(cName + ".method1 error: getConnection failed "
102: + e3.toString());
103: throw e3;
104: }
105:
106: }
107:
108: /**
109: * closeUp
110: */
111: public void closeUp(int w) {
112: try {
113: if (w > 0) {
114: // The CONNECTION_ERROR_OCCURRED indicates that the associated
115: // ManagedConnection instance is now invalid and unusable.
116: conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED);
117: Utility.log(cName
118: + ".closeUp : closed physical connection");
119: } else {
120: // The CONNECTION_CLOSED indicates that connection handle
121: // is closed, but physical connection still exists
122: conn.close();
123: Utility.log(cName + ".closeUp : closed connection");
124: }
125: } catch (Exception e) {
126: Utility
127: .log(cName
128: + ".closeUp error: close handle/physical connection failed");
129: }
130: }
131:
132: /**
133: * JUnit tests
134: */
135:
136: /**
137: * ra.xml contains value, used by Application Server to set EIS_URL in ra
138: */
139: public String getEIS_URL() throws Exception {
140: Utility.log(cName + ".getEIS_URL");
141: mcf = (ManagedConnectionFactoryImpl) cccf.getMcf();
142: ResourceAdapterImpl ra = (ResourceAdapterImpl) mcf
143: .getResourceAdapter();
144:
145: String cp1 = "none";
146: if (ra == null)
147: return cp1;
148: try {
149: cp1 = ra.getEIS_URL();
150: } catch (Exception e) {
151: Utility
152: .log(cName
153: + ".getEIS_URL get <configuration-property> error: failed");
154: throw e;
155: }
156: return cp1;
157: }
158:
159: public boolean deliverMsg(String msg) throws Exception {
160: boolean success;
161:
162: Utility.log(cName + ".deliverMsg to resource adapter");
163: mcf = (ManagedConnectionFactoryImpl) cccf.getMcf();
164: ResourceAdapterImpl ra = (ResourceAdapterImpl) mcf
165: .getResourceAdapter();
166: try {
167: success = ra.deliverMsg(msg);
168: Utility.log(cName + ".deliverMsg o.k. msg=" + msg);
169: } catch (Exception e) {
170: Utility.log(cName + ".deliverMsg error: e=" + e.toString());
171: success = false;
172: }
173: return success;
174: }
175: }
|