Problem creating standalone client
jaeger Jun 10, 2005 5:29 AMHi,
I am trying to create a standalone client, which accesses a JBoss server using a Session bean. In my simple example, I would basically try to use a Session bean's network-capabilities to call some method on the server and get the result back to the client.
I started with the Fibonacci tutorial found at JBossIDE. After some fiddling around, I got a working servlet example. So I tried to create a simple standalone client, which does the same as the servlet: connect to the Session bean, call a method and display the result. All this from the commandline, so I can use System.out.writeln() for output.
This standalone client works great when I start it on the same machine where also the JBoss server is running.
Starting it on a different machine, however, does not work. It seems the program always tries to connect to localhost (127.0.0.1), but of course there is no JBoss server answering.
Using tcpdump, I found that the program is in fact connecting to the remote JBoss server first, and some data is exchanged, but afterwards it tries to connect to localhost.
Maybe I have a conceptual problem here: can I lookup a Session bean on a remote server and use it, without having a JBoss server also running on the local machine?
I would be glad for any hint, as I spent more that a day now trying to find what's wrong here, and I am sure it is only a very small detail I am missing.
Thanks,
Christoph Jäger
P.S.: Just for completeness, I am using JBoss 4.0.1sp1 on a Fedora Linux machine, Java5.0, and the machine I am trying to run my client from is a Windows machine, also Java5.0.
Here is the source code of my client program:
package tutorial.text;
import java.io.IOException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import tutorial.interfaces.Fibo;
import tutorial.interfaces.FiboHome;
public class ComputeMain {
private FiboHome home;
public static void main(String[] args) throws IOException {
ComputeMain main = new ComputeMain();
main.run(50);
}
public ComputeMain() {
try {
Context context = new InitialContext();
Object ref = context.lookup("ejb/Fibo");
home = (FiboHome) PortableRemoteObject.narrow(ref, FiboHome.class);
} catch (Exception e) {
System.err.println("Lookup of java:/comp/env/ failed");
e.printStackTrace();
}
}
protected void run(int limit) {
double[] result=null;
try {
Fibo bean = home.create();
result = bean.compute(limit);
bean.remove();
} catch (Exception e) {
System.err.println("Call of bean.compute() failed");
e.printStackTrace();
return;
}
System.out.println("got result:");
for (int i=0;i<result.length;i++)
{
System.out.println(i+": "+result);
}
System.out.println();
}
}
and my jndi.properties file:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=jnp://172.24.1.202:1099 java.naming.factory.url.pkgs=org.jboss.naming.client:org.jboss.naming:org.jnp.interfaces