1 22 package org.jboss.test.cts.ejb; 23 24 import java.rmi.RemoteException ; 25 import java.rmi.ServerException ; 26 import java.util.Properties ; 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBException ; 29 import javax.naming.Context ; 30 import javax.naming.InitialContext ; 31 import javax.naming.NamingException ; 32 33 import org.jboss.logging.Logger; 34 import org.jboss.test.cts.interfaces.CallerSession; 35 import org.jboss.test.cts.interfaces.CallerSessionHome; 36 import org.jboss.test.cts.interfaces.ReferenceTest; 37 import org.jboss.test.cts.interfaces.CalleeData; 38 import org.jboss.test.cts.interfaces.CalleeException; 39 import org.jboss.test.util.ejb.SessionSupport; 40 import org.jboss.util.Classes; 41 import org.jboss.mx.loading.ClassLoaderUtils; 42 43 48 public class CallerSessionBean 49 extends SessionSupport 50 { 51 private static Logger log = Logger.getLogger(CallerSessionBean.class); 52 53 private CallerSessionHome cachedHome; 54 55 public void ejbCreate() throws CreateException 56 { 57 } 58 59 public CalleeData simpleCall2(boolean isCaller) throws RemoteException 60 { 61 StringBuffer info = new StringBuffer ("simpleCall2, isCaller: "+isCaller); 62 info.append(" CalleeData, "); 63 try 64 { 65 Classes.displayClassInfo(CalleeData.class, info); 66 log.info(info.toString()); 67 } 68 catch(Exception e) 69 { 70 e.printStackTrace(); 72 } 73 74 if( isCaller == false ) 76 return new CalleeData(); 77 78 CallerSessionHome home = null; 80 CallerSession callee = null; 81 82 try 83 { 84 home = lookupHome("ejbcts2/CalleeSessionHome"); 85 callee = home.create(); 86 } 87 catch(NamingException e) 88 { 89 throw new ServerException ("Failed to lookup CalleeHome", e); 90 } 91 catch(CreateException e) 92 { 93 throw new ServerException ("Failed to create Callee", e); 94 } 95 96 CalleeData data = callee.simpleCall(false); 97 return data; 98 } 99 100 public CalleeData simpleCall(boolean isCaller) throws RemoteException 101 { 102 StringBuffer info = new StringBuffer ("simpleCall, isCaller: "+isCaller); 103 info.append(" CalleeData, "); 104 try 105 { 106 Classes.displayClassInfo(CalleeData.class, info); 107 log.info(info.toString()); 108 } 109 catch(Exception e) 110 { 111 log.debug("displayClassInfo failure", e); 113 } 114 if( isCaller == false ) 116 return new CalleeData(); 117 118 CallerSession callee = null; 120 try 121 { 122 cachedHome = lookupHome("ejbcts2/CalleeSessionHome"); 123 callee = cachedHome.create(); 124 } 125 catch(NamingException e) 126 { 127 throw new ServerException ("Failed to lookup CalleeHome", e); 128 } 129 catch(CreateException e) 130 { 131 throw new ServerException ("Failed to create Callee", e); 132 } 133 catch(Throwable e) 134 { 135 log.error("Unexpected error", e); 136 throw new ServerException ("Unexpected error"+e.getMessage()); 137 } 138 139 CalleeData data = callee.simpleCall2(false); 140 return data; 141 } 142 143 147 public void callByValueInSameJar() throws RemoteException 148 { 149 CallerSession callee = null; 151 try 152 { 153 cachedHome = lookupHome("ejbcts/CalleeSessionHome"); 154 callee = cachedHome.create(); 155 } 156 catch(NamingException e) 157 { 158 throw new ServerException ("Failed to lookup CalleeHome", e); 159 } 160 catch(CreateException e) 161 { 162 throw new ServerException ("Failed to create Callee", e); 163 } 164 catch(Throwable e) 165 { 166 log.error("Unexpected error", e); 167 throw new ServerException ("Unexpected error"+e.getMessage()); 168 } 169 170 ReferenceTest test = new ReferenceTest(); 171 callee.validateValueMarshalling(test); 172 } 173 174 public void callAppEx() throws CalleeException, RemoteException 175 { 176 StringBuffer info = new StringBuffer ("appEx, CalleeException, "); 177 try 178 { 179 Classes.displayClassInfo(CalleeException.class, info); 180 log.info(info.toString()); 181 } 182 catch(Exception e) 183 { 184 log.debug("displayClassInfo failure", e); 186 } 187 CallerSessionHome home = null; 189 CallerSession callee = null; 190 191 try 192 { 193 home = lookupHome("ejbcts2/CalleeSessionHome"); 194 callee = home.create(); 195 callee.appEx(); 196 } 197 catch(NamingException e) 198 { 199 throw new ServerException ("Failed to lookup CalleeHome", e); 200 } 201 catch(CreateException e) 202 { 203 throw new ServerException ("Failed to create Callee", e); 204 } 205 catch(CalleeException e) 206 { 207 throw e; 208 } 209 } 210 211 public void appEx() throws CalleeException 212 { 213 StringBuffer info = new StringBuffer ("appEx, CalleeException, "); 214 try 215 { 216 Classes.displayClassInfo(CalleeException.class, info); 217 log.info(info.toString()); 218 } 219 catch(Exception e) 220 { 221 log.debug("displayClassInfo failure", e); 223 } 224 throw new CalleeException(); 225 } 226 227 public void validateValueMarshalling(ReferenceTest test) 228 { 229 boolean wasSerialized = test.getWasSerialized(); 230 log.info("validateValueMarshalling, testWasSerialized: "+wasSerialized); 231 if( wasSerialized == false ) 232 throw new EJBException ("ReferenceTest was not serialized"); 233 } 234 235 private CallerSessionHome lookupHome(String ejbName) throws NamingException 236 { 237 CallerSessionHome home = null; 238 Properties env = new Properties (); 239 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 240 env.setProperty(Context.OBJECT_FACTORIES, "org.jboss.naming:org.jnp.interfaces"); 241 env.setProperty(Context.PROVIDER_URL, "localhost:1099"); 242 243 InitialContext ctx = new InitialContext (env); 244 log.info("looking up: "+ejbName); 245 Object ref = ctx.lookup(ejbName); 246 StringBuffer buffer = new StringBuffer ("JNDI CallerSessionHome.class: "); 247 try 248 { 249 Classes.displayClassInfo(ref.getClass(), buffer); 250 log.info(buffer.toString()); 251 } 252 catch(Exception e) 253 { 254 log.debug("displayClassInfo failure", e); 256 } 257 buffer.setLength(0); 258 buffer.append("Session CallerSessionHome.class: "); 259 try 260 { 261 Classes.displayClassInfo(CallerSessionHome.class, buffer); 262 log.info(buffer.toString()); 263 } 264 catch(Exception e) 265 { 266 log.debug("displayClassInfo failure", e); 268 } 269 270 home = (CallerSessionHome) ref; 271 return home; 272 } 273 } 274 | Popular Tags |