Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RMI callback in WLS 6.1 SP3 -- just how?

0 views
Skip to first unread message

Alan Tang

unread,
Aug 16, 2002, 10:00:02 AM8/16/02
to
Hi:

I modified the hello example that comes with the installation to test rmi
callback. The code is below. The server can be loaded upon startup fine. But
when running the client, after exported itself, I'm getting this error:

javax.naming.ServiceUnavailableException. Root exception is
java.net.UnknownHostException: null
at java.net.InetAddress.getAllByName0(InetAddress.java:566)
at java.net.InetAddress.getAllByName0(InetAddress.java:535)
at java.net.InetAddress.getAllByName(InetAddress.java:528)
at weblogic.rjvm.RJVMFinder.getDnsEntries(RJVMFinder.java:292)
at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:142)
at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:207)
at
weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialCon
textFactoryDelegate.java:307)
at
weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialCon
textFactoryDelegate.java:211)
at
weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFact
ory.java:149)
at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:660)
at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:241)
at javax.naming.InitialContext.init(InitialContext.java:217)
at javax.naming.InitialContext.<init>(InitialContext.java:193)
at rmitest.HelloClient.getInitialContext(HelloClient.java:84)
at rmitest.HelloClient.doit(HelloClient.java:38)
at rmitest.HelloClient.main(HelloClient.java:75)

What am I missing here? I'm using the jdk131 that comes with the
installation, running on windows 2000.

====== server interface =========
package rmitest;
public interface Hello extends java.rmi.Remote {
String sayHello() throws java.rmi.RemoteException;
void Register(HelloClientIntf hc) throws java.rmi.RemoteException;
}
======== server impl =========
package rmitest;

import javax.naming.*;
import weblogic.rmi.RMISecurityManager;
import java.rmi.RemoteException;

public class HelloImpl implements Hello
{
private String name;

public HelloImpl(String s) throws RemoteException {
super();
name = s;
}

public String sayHello() throws java.rmi.RemoteException {
return "Hello World!";
}

public void Register(HelloClientIntf hc){
System.out.println("client registered...");
try{
hc.HelloBack(); // callback
}catch(RemoteException e){
e.printStackTrace();
}

}
public static void main(String args[]) {
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());

try {
HelloImpl obj = new HelloImpl("HelloServer");
Context ctx = new InitialContext();
ctx.bind("HelloServer", obj);
System.out.println("HelloImpl created and bound in the registry " +
"to the name HelloServer");

}
catch (Exception e) {
System.out.println("HelloImpl.main: an exception occurred:");
e.printStackTrace();
}
}
}

========== client interface =============
package rmitest;

public interface HelloClientIntf extends java.rmi.Remote {
public String HelloBack() throws java.rmi.RemoteException;
}

=========== client impl ===============
package rmitest;

import java.io.PrintStream;
//import weblogic.utils.Debug;
import javax.naming.*;
import java.util.Hashtable;

import java.rmi.server.UnicastRemoteObject;

public class HelloClient implements HelloClientIntf {

private final static boolean debug = true;

public final static String
JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";

int port;
String host;

private static void usage() {
System.err.println("Usage: java examples.rmi.hello.HelloClient " +
"<hostname> <port number>");
System.exit(-1);
}

public HelloClient() {

}

public void doit(){

try {
UnicastRemoteObject.exportObject(this);
System.out.println("exported client...");

InitialContext ic = getInitialContext("t3://" + host + ":" + port);

Hello obj =
(Hello) ic.lookup("HelloServer");

obj.Register(this);

System.out.println("Successfully connected to HelloServer on " +
host + " at port " +
port + ": " + obj.sayHello() );

}
catch (Throwable t) {
t.printStackTrace();
System.exit(-1);
}

}

public String HelloBack(){
return "Hello back from the client!";
}

public static void main(String[] argv) throws Exception {
if (argv.length < 2) {
usage();
}
String host = argv[0];
int port = 0;
try {
port = Integer.parseInt(argv[1]);
}
catch (NumberFormatException nfe) {
usage();
}

HelloClient hc = new HelloClient();
hc.doit();
}

private static InitialContext getInitialContext(String url)
throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
return new InitialContext(env);
}
}


Alan Tang

unread,
Aug 16, 2002, 3:14:44 PM8/16/02
to
Never mind, it was a stupid mistake I made (the host and port are not passed
in).


"Alan Tang" <ai_...@yahoo.com> wrote in message
news:3d5d...@newsgroups.bea.com...

0 new messages