File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet - RMI Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet - RMI Error" Watch "Servlet - RMI Error" New topic
Author

Servlet - RMI Error

Varun Rupela
Greenhorn

Joined: Feb 17, 2002
Posts: 12
Hi:
I wrote a simple application that uses RMI and got it to work. The application involves a client that invokes a remote method (on the server) for adding 2 numbers and returns the sum to the client.
When I tried to use a Servlet as a client of the remote method I get the following exception:
"error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: impl_Stub ""
impl_Stub is the name of the Stub that "rmic" generated from the interface implementation.
It would be great if someone could help me correct the error.
In order to use RMI along with Servlets do I need to things in a different manner?
Question 2:
Just for kicks: In a Servlet, I tried to (use the response Writer to) print the value of a static varible from another class. There were no compilation errors. But when accessing the servlet from the internet, the web page showed an "Internal Server Error"?
Do I need to use the RequestDispatcher?
Thank you.
Varun.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
1. Sure sounds like the servlet client is unable to find the stub code. You did put the class in a package didn't you? And put the class file under WEB-INF/classes where the servlet will look. There is nothing magic about using RMI with servlets, you just have to obey the rules for classes that servlets use.
2. There is no reason that should not work. You did put a try/catch in your doGet or doPost, right? If not, look at the servlet engine logs.
Bill
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
Varun - you sent me a private message but I cant reply due to your private message settings. Therefore I will repeat the basic msg.

Could you direct me to a resource that lists the rules to be followed while using RMI in Servlets? My Servlet is still not working and I am guessing I might have missed some things out.

I actually have an example in my Servlets and JSP book. My suggestion is that you do what I did and experiment with RMI outside the servlet environment until you are sure that part is working.
In the servlet environment you mainly have to ensure that:
1. all your code is in a package
2. your compiled client class files are in WEB-INF where the servlet engine can find them.
Bill
Varun Rupela
Greenhorn

Joined: Feb 17, 2002
Posts: 12
Thank you again Mr. Brogden:
I will try and follow your instructions and let you know what happens.
Thank you.
Varun.
Varun Rupela
Greenhorn

Joined: Feb 17, 2002
Posts: 12
Dear Mr. Brogden:
I have been able to use RMI such that all my code is in packages and it works correctly.
Now, when I am going to be using a servlet as a client:
1. Should the Servlet be in a package as well?
2. Is WEB-INF a file or a directory? I guess it is a file that the Servlet engine checks to know which class files to load?
3. Which "compiled class files" do I place in WEB-INF? - (Do I place the class file of the interface and the stub in it)?
I appreciate your being patient with me.
Thank you.
Varun.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet - RMI Error