Hello,
I am experimenting with Java RMI. I know RMI is a part of J2SE and not J2EE but I have this example from "Professional Java Server Programming J2EE 1.3 Edition" and you don't have any other appropriate thread for it.
After I have bought "Professional Java
Server Programming J2EE 1.3 Edition" from WROX I try to run the first
RMI-example. But something is going wrong:
1) if I try to run rmiregistry with appropriate policy-file, I get buffer
overflow exception from RegisterIt - class (after a very long time)
while registring my server-class.
2) in some faq - lists I found a work-around with
sun.rmi.registry.RegistryImpl ("java
-Djava.security.policy=registerit.policy
sun.rmi.registry.RegistryImpl").
So I first create server class. Next I create server stub
(now they are matching). Then I create client class and registration class.
Now I start registry and register my server-class, but if
I try to connect it from my client class, I still get
"java.rmi.UnmarshalException: invalid method hash".
I know this exception appears if my stub is not matching my remote server
class. But it is not possible because I always generate my stub after
creating server class so they must be synchronized.
3) When I try out Activatable example on my system and try to registry my
activatable server class I get connection refused exception (rmid is
running). I can only register my server class if
sun.rmi.registry.RegistryImpl is running too. But then I get invalid method
hash when I was trying to run my client class.
Has anyone an idea what is going wrong?
Why rmiregistry does not work on my system?
Why rmid does not work?
I am wondering if I have to set some environmental variables because of the
fact that nothing concerned rmi is running on my system properly.
I am working with Java 1.4.1 and BlackdownJava2-1.4.1.
Lydia
Here are my files (not for activatable example):
Server-Interface
Code:
public interface HelloInterface extends java.rmi.Remote
{
// This method is called by remote clients and is implemented
// by remote object
public String hello() throws java.rmi.RemoteException;
}
Server-Class
Code:
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
public class HelloServer extends UnicastRemoteObject
implements HelloInterface
{
public HelloServer() throws RemoteException
{
super();
}
public String hello() throws RemoteException
{
return "Hello World";
}
}
Register-Class
Code:
import java.rmi.*;
public class RegisterIt
{
public static void main(String args[])
{
try
{
HelloServer obj = new HelloServer();
System.err.println("Object instantiated : " + obj);
System.err.println("rebinding HelloServer...");
Naming.rebind("/HelloServer", obj);
System.err.println("HelloServer bound in registry");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Client-Class
Code:
import java.rmi.*;
public class HelloClient
{
public static void main(String args[])
{
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
HelloInterface obj = (HelloInterface) Naming.lookup("/HelloServer");
String message = obj.hello();
System.err.println(message);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}