4-2 Programming Stand-alone Clients for Oracle WebLogic Server
4.2 Developing a WebLogic Full Client
Creating a basic WebLogic full client consists of the following steps:
1.
Generate the wlfullclient.jar file for client applications using the JarBuilder tool. See
Appendix B, Using the WebLogic JarBuilder Tool.
2.
Obtain a reference to the remote object.
a.
Get the initial context of the server that hosts the service using a T3 URL.
b.
Obtain an instance of the service object by performing a lookup using the initial context. This instance can then be used just like a local object reference.
3.
Call the remote objects methods. Sample code to for a simple WebLogic full client is provided in
Example 4–1 .
Example 4–1 Simple WebLogic Full hello Client
package examples.rmi.hello; import java.io.PrintStream;
import weblogic.utils.Debug; import javax.naming.;
import java.util.Hashtable;
This client uses the remote HelloServer methods. author Copyright c Oracle. All Rights Reserved.
public class HelloClient {
private final static boolean debug = true; Defines the JNDI context factory.
public final static String JNDI_FACTORY=weblogic.jndi.WLInitialContextFactory;
int port; String host;
private static void usage { System.err.printlnUsage: java examples.rmi.hello.HelloClient +
hostname port number; System.exit-1;
}
public HelloClient {} public static void mainString[] argv throws Exception {
if argv.length 2 {
Note: Not all functionality available with weblogic.jar is available
with the wlfullclient.jar. For example, wlfullclient.jar does not support Web services, which require the wseeclient.jar. Nor does
wlfullclient.jar support operations necessary for development purposes, such as ejbc, or support administrative operations, such as
deployment, which still require using the weblogic.jar.
Developing a WebLogic Full Client 4-3
usage; }
String host = argv[0]; int port = 0;
try { port = Integer.parseIntargv[1];
} catch NumberFormatException nfe {
usage; }
try {
InitialContext ic = getInitialContextt3: + host + : + port; Hello obj =
Hello ic.lookupHelloServer; System.out.printlnSuccessfully connected to HelloServer on +
host + at port + port + : + obj.sayHello ;
} catch Throwable t {
t.printStackTrace; System.exit-1;
}
} private static InitialContext getInitialContextString url
throws NamingException {
Hashtable env = new Hashtable; env.putContext.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY;
env.putContext.PROVIDER_URL, url; return new InitialContextenv;
} }
4.3 Distributing the WebLogic Full Client