• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Servlet as an rmi client

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to set up a servlet as an rmi client. My rmi server runs on a remote machine. I have the rmi server up and running. Now I am trying to write a servler client to talk to this server which exists on a remote machine. I am developing servlet in my desktop using eclipse and tomcat.

When I try to do a lookup, I get AccessControlException.

How do I solve it ?

Servlet in localhost and RMI server in remote machine.
Please help
Thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like the user, under which your container is running doesn't have sufficient permissions to access the the network resource in question.

Personally, I wouldn't do this directly in a servlet.
I would make the RMI client a plain old Java object that can be instanciated by any interface (command line, servlet, etc...) to have it's methods called.
This will make debugging things like this much easier.
 
Diya Shankar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response Ben. But based on our requirement, I have to have a servlet for accessing RMI server. I managed to get thru that problem by changing java.policy file in my local machine.

Now, I get another exception, "java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: TestServer_Stub

I believe for this I have to set up a codebase.
My server runs in an UNIX machine. I read in an article that place the rmi classes[or jar file with rmi stub etc classes] in a directory which can be accessed via http.

and then use -Djava.rmi.server.codebase property from client side.
Has anyone tried this ?

Again client is in Eclipse/tomcat

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But based on our requirement, I have to have a servlet for accessing RMI server.


Strange that someone would require such a poor design.

In any case....
At this point, it sounds like your issue has more to do with RMI than with anything particular to servlets.

I'm going to move this to Distributed Java
[ January 05, 2007: Message edited by: Ben Souther ]
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, its a CLASSPATH problem.

Codebase does work, but I've never used it with servlets.
 
Diya Shankar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you accessed a rmi server in a remote machine from a local application ?

If yes, how did you set the code base then ?
where did you out the classes and which protocol did you use ?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, that second error message looks to be a classpath problem.

Make sure the library containing the stubs is included in the classpath when starting up RMIRegistry. I would recommend just doing a simple set and export of the CLASSPATH before starting up RMIRegistry.
 
Diya Shankar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chad,

Hi This is what I do for starting up rmi registry.
CLASSPATH=$CLASSPATH:$HOME/classes:
export CLASSPATH

and then I start rmiregistry like this:
nohup rmiregistry -J-mx128m -J-ms16m -J-oss1m -J-ss1m \
-J-Djava.rmi.dgc.leaseValue=123400000 \
-J-Djava.rmi.server.logCalls=true 3444> \
RmiRegistry3444.log 2>&1 &
sleep 10

I dont specify any codebase when I start rmiregistry. Again this is on a remote machine.

Any suggestions ?
 
Diya Shankar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any experts help me please ?

I have displayed the way my registry gets started. This rmi server is in a remote machine.

I have my servlet which runs in my tomcat.

I tried putting the server's stub files etc as jar file in Unix server's public_html directory and setting-Djava.rmi.server.codebase=http://test.xx.com/username/public_html/test.jar in my tomcat's configuration.

Still I get lots of exceptions, Unmarshalling exception etc.

Please help
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A few things about it..

I am having the same problem but my servlet runs well if I don't run the rmiregistry programatically.

1. run the rmiregistry manually.
In the server code,

bind the object as :
YourServerImplClass implObj=new YourServerImplClass ();
Naming.rebind("refname",implObj);

In the servlet get the object as :
YourServerInterface infObj=(YourServerInterface)Naming.lookup("rmi://IP address wheree your rmi server runs/implObj");

Now with the help of the infObj you can access any method.

Note : Copy the servlet in webapps/ROOT/WEB-INF/classes folder.
You have to copy the stub class as well as your interface class in the classes folder.

That's all.I think it should work.As its working fine with me..

best wishes....
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic