1 25 26 package org.objectweb.easybeans.rpc.rmi.client; 27 28 import java.rmi.RemoteException ; 29 import java.util.Hashtable ; 30 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 import javax.rmi.PortableRemoteObject ; 35 36 import org.objectweb.easybeans.rpc.api.ClientRPC; 37 import org.objectweb.easybeans.rpc.api.EJBRequest; 38 import org.objectweb.easybeans.rpc.api.EJBResponse; 39 import org.objectweb.easybeans.rpc.rmi.server.RMIServerRPC; 40 41 45 public class RMIClientRPC implements ClientRPC { 46 47 50 public static final String EASYBEANS_RMI_FACTORY = "easybeans.rpc.rmi.factory"; 51 52 55 private Hashtable rmiClientEnvironment = null; 56 57 58 62 public RMIClientRPC(final Hashtable <?, ?> rmiClientEnvironment) { 63 this.rmiClientEnvironment = rmiClientEnvironment; 64 } 65 66 67 73 @SuppressWarnings ("unchecked") 74 public EJBResponse sendEJBRequest(final EJBRequest request) { 75 76 String additionalInitialFactory = System.getProperty(EASYBEANS_RMI_FACTORY); 78 if (additionalInitialFactory != null) { 79 rmiClientEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, additionalInitialFactory); 80 } 81 82 83 Context ictx = null; 84 try { 85 ictx = new InitialContext (rmiClientEnvironment); 86 } catch (NamingException ne) { 87 throw new IllegalStateException (ne); 88 } 89 90 Object serverObject = null; 92 try { 93 serverObject = ictx.lookup(RMIServerRPC.RPC_JNDI_NAME); 94 } catch (NamingException ne) { 95 throw new IllegalStateException (ne); 96 } 97 RMIServerRPC server = (RMIServerRPC) PortableRemoteObject.narrow(serverObject, RMIServerRPC.class); 99 100 try { 102 return server.getEJBResponse(request); 103 } catch (RemoteException re) { 104 throw new RuntimeException ("Error while handling answer on the remote side ", re); 105 } 106 107 } 108 109 } 110 | Popular Tags |