Write the thin or pluggable application client
You can develop and run Java thin client applications on machines installed with either a client or a server. The client provides a setup command shell which sets up your environment for either a thin client application or a J2EE client application. The server provides a command shell which sets up your environment for J2EE application clients only. The Java invocation to run a thin application client varies between a client and a server. If your thin client application needs to run on both a client installation and a server installation, follow the steps for developing thin application clients on a server machine.
The thin or pluggable application client is a traditional Java application that contains a main() method. The WebSphere application client provides runtime support for accessing remote enterprise beans. Additionally, WAS provides the implementation services such as security, workload management (WLM), and others.
Consider the following items when writing a thin client application or a pluggable client application that accesses an enterprise bean:
- The first two lines in this code snippet illustrate what a client application uses to specify the computer name, domain, and port when initializing an instance of InitialContext.class. After the bootstrap values (<myHost>:<bootstrap-port>) are defined, the client to server communications occur within the underlying infrastructure. In this example,
prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); prop.put(Context.PROVIDER_URL, "iiop://<myHost>:<bootstrap-port>");The INITIAL_CONTEXT_FACTORY and PROVIDER_URL properties can also be passed as WebSphere-defined parameters rather than hardcoding these values in your application client code. Include the following properties when running your application client:
-Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory -Djava.naming.provider.url=iiop://<myHost>:<bootstrap-port>where <myHost> is the computer name and domain where WAS resides, and <bootstrap-port> is the configured bootstrap port number and the port on which the name service for your application server is listening.. Using this approach, you can simply create the InitialContext using the constructor which takes no arguments..
initialContext = new javax.naming.InitialContext();The INITIAL_CONTEXT_FACTORY and PROVIDER_URL properties is set automatically.
The thin application client and the pluggable application client must use fully qualified JNDI names for each resource in the client application.
java.lang.Object ejbHome = initialContext.lookup ("the/fully/qualified/path/to/actual/home/in/namespace/<MyEJBHome>"); <MyEJBHome> = (<MyEJBHome>)javax.rmi.PortableRemoteObject.narrow (ejbHome, <MyEJBHome>.class);In the example below, the increment bean, which is in the DefaultApplication, binds to "Increment":
java.lang.Object ejbHome = initialContext.lookup("Increment"); com.ibm.defaultapplication.IncrementHome home = (com.ibm.defaultapplication.IncrementHome)javax.rmi.PortableRemoteObject.narrow (ejbHome, com.ibm.defaultapplication.IncrementHome.class);To determine the fully qualified name, look at the JNDI name field on the Bindings tab in the application assembly tool.