• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RMI Naming.rebind() Problem

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I Ritchie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 just had the craziest dream. This tiny ad was in it.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic