7. JNDI ConfigurationAs of version 0.0.5 SwitchRMI includes a minimal JNDI Context implementation. Published objects are stored as JNDI References in a JNDI Context. A JNDI lookup at runtime will return the object used to satisfy the request. SwitchRMI client applications can also be configured via JNDI so that a client can lookup a JNDI name to obtain a proxy to a remote object. Service Configuration
The JNDI Context is built from the XML deployment descriptor file passed as the value of the system property:
The SwitchRMI servlet class in the SwitchRMI distribution needs only the provider URL passed as the value
of the switchrmi.configuration init-parameter in the Alternatively, the JNDI context can be configured via a Hashtable containing these values: import javax.naming.*; Hashtable env = new Hashtable(); env.put(Context.PROVIDER_URL, "http://localhost:8080/test/jndi/TestSuiteConfiguration.xml"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.mjh.switchrmi.jndi.JndiContextImplFactory"); jndiCtx = new InitialContext(env); jndiCtx = new InitialContext(); echo = (IEcho)jndiCtx.lookup("/switchrmi/service/object/echo"); Client Configuration
A client can be configured to declare the remote objects in a XML description file such that application code
is not aware of the actual network location of the remote object. The client configuration file declares a
The RmiClient class provides an alternative to JNDI client configuration. SwitchRMI client code uses a minimal JNDI Context internally but RMIClient constructs the proxy to a remote object directly without using JNDI Reference objects. The following listing obtains a proxy to the same remote object as the preceding JNDI client example RmiClient rmi = new RmiClient(); echo = (IEcho)rmi.connect("http://localhost:8080/rmi/echo.xmlrpc", IEcho.class); The JUnit test suite shipped with SwitchRMI uses both JNDI and RmiClient client configuration methods. |