Servlet that implements RMI
Hi Everyone,
I m planning to implement RMI with servlet. The architecture is as follows:
--> Http request to the server(tomcat) where the servlet will accept the request. It will get the header request and the post request and on the basis of this post request it will invoke RMI to process specific functionality like fetching image from database.
--> RMI then uses JDBC to interact with the database and get required results.
--> The servlet then returns this image back to the client.
Now, I have seen some examples for servlet and RMI but I havent seen a concrete tutorial explaining this situation.
Is my architecture correct ? Is there anything that I m missing ?
Please guide me.
Thank you.
Your description doesn't say that you have an RMI server running elsewhere, and that your servlet will be an RMI client that connects to that server. That would be a decent architecture. But if your architecture is something else, then I don't know.
And if you expect to find a tutorial for how to make a servlet be an RMI client, you need to fix up your development skills. There are two concepts there that are basically independent: (1) Servlets (2) RMI. I am sure you have found tutorials for both of them. You should be able to combine the two concepts for yourself.
First of all thanks for your reply.
And I apologise for vaguely describing my requirement. I did some search on it and realised that I was acting silly when it came to overall end to end java application.
Now my architecture is as follows:
--> Servlet accepts request from user and gets the header information.
--> Look up for specific methods on a RMI registry/server located elsewhere.
--> Request is processed and data is fetched from database.
--> Returned to Servlet which in turn sends it back to the user.
I 'm still actually looking for tutorials as to how to invoke RMI from servlet. Although, I have independently implemented both of them its just about "integrating" them.
If you can give me more information about it, that would be great !
Thanks.
Message was edited by:
siddhsdesai
There should not be mich differance in doing a RMI call from a servelet. As long as the Security Manager does not block you
LRMKa at 2007-7-13 23:17:57 >

Hi there,Thanks for your reply. But for me, I m new to servlet to its just a bit of problem figuring out however I m searching :-).But, please feel free to guide me as to how I should go about doing it.
Figure out how to make a client call any RMI server. Leave out the complication of the servlet. Once you have that working, you'll realize that the servlet will just be another client of your RMI server.%
Hi duffymo,
Thanks for your reply.
I already have got my RMI client and server working as a part of the system prototype. All I dont know is how I should go about doing it in servlet :p. I know might sound strange but for someone who isnt into servlets, it is a bit hard !
But, I m still searching. Any input in regards to servlet as a RMI client would be very much appreciated :-).
I just had a look at O reilly's book on Servlet Programming. Let me try implementing it. In the mean time if anyone has any advice for me please feel free to point it out to me.
Message was edited by:
siddhsdesai
You have some working code that acts as an RMI client? Then take that code and put it into the doGet(), or doPost(), method of your servlet. Problem solved. I can't understand what the difficulty is.
Hi DrClap,
Thanks for your reply.
Well, I did that ! I pasted RMI Client code to Servlets doGet method but it wont compile and gives me 2 errors.
symbol : class HelloInterface
location: class HelloWorld
HelloInterface hello = (HelloInterface) Naming.lookup ("//xxx.xxx.xxx/Hello"
);
^
HelloWorld.java:14: cannot find symbol
symbol : class HelloInterface
location: class HelloWorld
HelloInterface hello = (HelloInterface) Naming.lookup ("//xxx.xxx.xxx/Hello"
);
^
2 errors
I have the Stub and Interface in web-inf/classes folder but I dont know whats happening over here. I have checked the interface and everything but it wont work.
And my servlet :
try
{
HelloInterface hello = (HelloInterface) Naming.lookup ("//xxx.xxx.xxx/Hello");
System.out.println("IP Address: "+hello.showIPAddress());
System.out.println("User Name: "+hello.getUsernames());
}catch(Exception e)
{
System.out.println("Error from hello world: "+e);
}
Message was edited by:
siddhsdesai
I also wanted to mention that the RMI server is running independently off the servlet. Still the same problem
well, I found the problem. All I had to do is specify the location of the stub file which was in current directory therefore -classpath "path for servlet";. filename.java
But now, I m getting java.rmi.NotBoundException: //examples//servlet//Hello
I started the server and rmiregistry from current directory but I dont know why it would show that error. I also tried changing it to //ip//hello....may be my fundamentals are wrong..
Any advise would be greatly appreciated
Finally, it has been solved :-). It should have been //ip/Name Of InterfaceThanks everyone for your help :-)
Are your stub & skel in a package? If not, Tomcat won't deal with them.%
oops, glad it worked. (reading too fast again)%