wood burning stoves*
The moose likes Distributed Java and the fly likes RMI Naming.rebind() Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI Naming.rebind() Problem" Watch "RMI Naming.rebind() Problem" New topic
Author

RMI Naming.rebind() Problem

I Ritchie
Greenhorn

Joined: Sep 14, 2003
Posts: 7
Hi,
The following simple example is making my life very difficult. It is failing on the Naming.rebind() for some reason when I try to run the app. Interface and stack trace are below. Can anyone tell me what the problem is? Thanks in advance.



Stack Trace:
Trying to bind
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.net.MalformedURLException: no protocol: and
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:217)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:350)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at HelloWorldImpl.main(HelloWorldImpl.java:25)
Caused by: java.net.MalformedURLException: no protocol: and
at java.net.URL.<init>(URL.java:537)
at java.net.URL.<init>(URL.java:434)
at java.net.URL.<init>(URL.java:383)
at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:747)
at sun.rmi.server.LoaderHandler.getDefaultCodebaseURLs(LoaderHandler.java:120)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:149)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:631)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:257)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:200)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1513)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:215)
... 4 more
Idly Vada
Ranch Hand

Joined: Sep 02, 2003
Posts: 135
Use //localhost/Hello instead of rmi://localhost/Hello in Naming.rebind
This may solve your problem.
And either disable the security manager or edit the policy file of java.
Anurag Mishra
Ranch Hand

Joined: Jun 16, 2003
Posts: 121
Hi,
if ur still in problem pls try this.
1. The command prompt from where ur trying to run
ur RMI programm set classpath for tht current directory.
2. create a .polic file say its test.policy save this in ur directry
put these code in test.policy

3. After that start rmiregistry
4. start ur rmi server from command prompt after setting proper classpaths
using
java -Djava.security.policy=C:\test.policy URServerClassfile
5. for Client also use same as above like
java -Djava.security.policy=C:\test.policy CLIENTClassfile

it should work........
still if u have problem pls tell me.
thanks
Anurag


SCJP 1.2
I Ritchie
Greenhorn

Joined: Sep 14, 2003
Posts: 7
Hi,
I have done as you suggested and am still having problems. I created a policy file just like you said, ran rmic, started the rmiregistry and executed the class. My code is now as follows:

This gives me the following exception:
Trying to bind
java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:567)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at HelloWorldImpl.main(HelloWorldImpl.java:25)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
... 6 more
Any ideas anyone?
I executed the app with -Djava.security.policy=./test.policy
Looks like it hasnt picked up the security policy?
Thanks for the advice so far!
I Ritchie
Greenhorn

Joined: Sep 14, 2003
Posts: 7
Forgot to mention, I tried to remove RMI: from the line:
Naming.rebind("RMI://localhost:1098/Hello",hw);
This did not make any difference, and I still receieve the same exceptions.
Idly Vada
Ranch Hand

Joined: Sep 02, 2003
Posts: 135
Hi Ritchie!
I don't think you are creating stubs and skeletons for implemenation classes. It is always better to seperate implementation classes from server program. Use rmic to generate stubs and skeletons.Then run your server program.It'll work
Code for HelloWorld app:
//Remote interface
import java.rmi.*;
public interface HelloWorld extends Remote
{
public String sayHello(String name) throws RemoteException;
}
//Implementation class
import java.rmi.*;
import java.rmi.server.*;
public class HelloWorldImpl extends UnicastRemoteObject implements HelloWorld
{

public HelloWorldImpl() throws RemoteException
{
super();
}

public String sayHello(String name)
{
return "Hello "+ name;
}
}
//server program
import java.rmi.*;
class HelloServer{
public static void main(String[] args)
{
try
{
HelloWorldImpl hw = new HelloWorldImpl();
System.out.println("Trying to bind");
Naming.rebind("localhost/Hello",hw);
System.out.println("Bound");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
after creating and compiling all these classes,
use rmic to create stub and skeleton classes(rmic HelloWorldImpl). Then start the server program.
[ September 20, 2003: Message edited by: Murthy Narasimha ]
Anurag Mishra
Ranch Hand

Joined: Jun 16, 2003
Posts: 121
Hi Ritchie,
pls follow the things what Murthy Narasimha has told you
and try to run ur programm even if it doesn't work send me all the three
java files to me by mail.
i will try to solve your problem and reply back.
thanks
Anurag
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Naming.rebind() Problem
 
Similar Threads
Rebind() Problem
UnmarshalException while executing the Server Application
HFJ - RMI issues.
Remote Exception Error.
very urgent->plz help:error when connecting to cmp