Solved

Can a servlet connect with the RMI Registry running on an HTTP Client?

Posted on 2003-11-17
31
683 Views
Last Modified: 2013-11-24
I have developed a Web Application, I want to perform some task on the Client PCS from the Web Server.. I have created the Servlets.. everything is running on local machine.. I want to ask.. is it possible that a servlet can be connected with the Client through RMI? and thus make method calls on the Client's Object?
Plz.. Urgent help is needed...
0
Comment
Question by:aiklamha
  • 16
  • 15
31 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 9769613
 You can't connect to the client but you can connect to the RMI Registry. If you are running a registry on the same physical computer you are running your client you can connect to the registry. Just provide your Servlet (or a value object if you want to make it clearer) with the IP and the port fo the RMI Registry.
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9770011
Thankyou very much for your quick reply..
OK! That's fine... do u know any freeserver which allows this connection.. so that i can host my servlets there and connect to my client....
Just another Question: Is it possible to connect to the rmiregistry which is behind a proxy?
0
 
LVL 35

Expert Comment

by:girionis
ID: 9770067
 Thanks for the points glad I helped :)

> do u know any freeserver which allows this connection..

  For java hosting companies take a look here:
http://www.javahosts.net/links.php?op=viewlink&cid=3

  not sure if they are free though...

> Is it possible to connect to the rmiregistry which is behind a proxy?

  You will probably have problems. If you do then try and set the proxy properties manually and it should be fine:

Properties systemproperties = System.getProperties();

systemproperties.put("proxyHost",
                             "<proxy name>");
        systemproperties.put("proxyPort",
                             "<proxy port>");
        systemproperties.put("proxySet","true");

  For other proxies (FTP or firewall) yuo can also use:

systemproperties.put("firewallHost",
                             "<firewall name>");
        systemproperties.put("firewallPort",
                             "<firewall port>");
        systemproperties.put("firewallSet","true");

  and

systemproperties.put("ftpProxyHost",
                             "<ftp proxy host>");
        systemproperties.put("ftpProxyPort",
                             "<ftp proxy port>");
        systemproperties.put("ftpProxySet","true");

System.setProperties(systemproperties);
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 17

Author Comment

by:aiklamha
ID: 9771366
Thanx Again..that's so nice of u.. well.. i will check the code and then again come back...
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9806368
Hi Again....!!!!!
Your code worked like a charm.. thanx a lot..
Now need another help.... i am trying to connect to the RMI.. my servlet is running on the third party webserver... i am getting the following Error.....


Connection refused to host: 203.130.4.3; nested exception is:
java.net.ConnectException: Connection refused
java.rmi.ConnectException: Connection refused to host: 203.130.4.3; nested exception is:
java.net.ConnectException: Connection refused
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.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at aiklamha.ChangeStatusServ.doGet(ChangeStatusServ.java:41)
at aiklamha.ChangeStatusServ.service(ChangeStatusServ.java:12)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:95)
at com.caucho.server.http.Invocation.service(Invocation.java:291)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:341)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:268)
at com.caucho.server.TcpConnection.run(TcpConnection.java:136)
at java.lang.Thread.run(Thread.java:543)
Caused by: java.net.ConnectException: Connection refused
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:434)
at java.net.Socket.connect(Socket.java:384)
at java.net.Socket.(Socket.java:291)
at java.net.Socket.(Socket.java:119)
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


Is this the problem with the security manager or what.. i don't have any idea.. This is the last thing i have to do to complete my project...but this is the most important as well.. everything worked on local computer.. but now in real world.. it's a mess..:(
Remember i am not behind the proxy...
Thanx Again..
0
 
LVL 35

Expert Comment

by:girionis
ID: 9806444
 Is there a firewall/proxy in the middle?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9808747
No.. I have already said that i am neither behind a firewall nor i am behind a proxy.....
Is this the problem with the security manager?
0
 
LVL 35

Expert Comment

by:girionis
ID: 9809053
> Is this the problem with the security manager?

  I do not think so... Can you ping the host you are trying to connect to?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9809466
A point again....
I am on the rmiregistry side....( means i cannot physically operate the webserver where my servlets are deployed).. therefore i can't see whether i can ping it or not..
Every servlet is running beautifully other than the one which is trying to connect to RMI Registry....
0
 
LVL 35

Expert Comment

by:girionis
ID: 9809504
 Since it is working on the local computer and not on the remote one it is definetely not a Servlet problem, it's more likely a connection problem. I do not think it is a security manager isue otherwise you would have got a relevant error message.

  Can you get in touch with th epeople of the server and ask them? They might be able to give you more hints.
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9811274
Precisely NOT... I am not in touch with those ppl.. caz i am on a freeserver..U must have heard about mycgiserver.com.. i asked them a thousand time whether they have support for RMI .. but no resposne...
In some servlets i have seen the setSecurityManager thing. whish is set to RMISecurityManager.... i just cudn't get informatino what that's all about.. do u have any knowledge?
Help me plz........... this is the matter of bucks... and Job...
:(
0
 
LVL 35

Expert Comment

by:girionis
ID: 9816296
> Connection refused to host: 203.130.4.3; nested exception is:

  The above error says that the conneciton is refused but it does not give us any additional information. Usually this happens if there is a firewall in the middle but since you said you don't know then we can never be sure.

  As I said above I do not think it is a security issue otherwise you would have got an error message like:

java.security.AccessControlException: access denied
  (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

  Maybe you are indeed getting this message but it is on the server side logs, do you have access on the server side logs/console?

> whish is set to RMISecurityManager.... i just
>cudn't get informatino what that's all about..
>do u have any knowledge?

  The security manager is a java class that helps you to specify a security policy in Java. In RMI you can just change the java.policy file and grant the appropriate permissions but you first need to have access to the policy file itself.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9816304
 A few more info. I just tried to ping the host 203.130.4.3 but I got a "request timed out." response which means either

a) the server is down.
b) There is a firewall/proxy that denies access (the administrators of the site probably denied pings to avoid any possible DDOS attacks)

  I really think your solution lies to getting in touch with the server people. There is nothing wrong with your Servlet or RMI classes, it is just network problem.
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9818268
yah.. this IP is assigned to my computer dynamicaly.. i have programmed my servlets so that it takes the IP Address from the Request then tries to connect to the rmiregistry running on the computer...
A strange thing i am noticing... when i type IPconfig on command prompt it displays the current IP assigned to me...but when i access the servlet it always displays the previos IP assigned to my computer.. i just couldn't understand what the problem could be....

I have a network connection plus i have the modem connection.. so at the same time there are two different IPs assigned to my computer... when i run rmiregistry which address would it be bound to??????????

Thanx for your concern..
MOIN.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9818426
 So the RMI registry is running on your computer and the servlet is trying to connect to your computer and the "Connection refused to host: ..." is actually the error you are getting from the server.

  Can you not run the registry on the same computer you are running the Servlet?

> when i run rmiregistry which address would it be bound to??????????

  I am not sure... What happens if you only run one connection (either the modem connection or the network connection)?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9824297
You have got that right... let me tell u details of my project.. It's to control devices from mobile phone. so it includes 1) A mobile device  2) A Home Pc where device is connected  3) A WebServer which hosts the Servlets... I wanted the communication b/w the client and server thru RMI.. it worked fine in local environment.. only now it's giving error....
well. if i couldn't find any solution for this.. then i will complete the task thru HTTP Messages ( which would only be the workaround and not the solution)
But they (sun ppl) have promissed about RMI's efficiency and capabilities... they have spoken very high about it everywhere.. then why 0' Why it's not working.. :(

I read somewhere
JAVA = Just Amazing Vendor's Assurances..... Is that true???????// ;)
I hope not..
0
 
LVL 35

Expert Comment

by:girionis
ID: 9824397
 The error message is that

"java.rmi.ConnectException: Connection refused to host: 203.130.4.3"

  Now to get things clear and right. Is the host with IP 203.130.4.3 your home computer (client) or the web server?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9825074
It's my Home computer... and this IP is not static.....it is assigned dynamically whenever i dial-in to my ISP...
0
 
LVL 35

Expert Comment

by:girionis
ID: 9826785
 So the connection is actually refused to your home computer... From where? Does your web server tries to connect to your computer by any means (apart from HTTP)?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9830220
Yup!!!
This is the actual case....

0
 
LVL 35

Expert Comment

by:girionis
ID: 9830267
 So how does the web server tries to connect to your computer? I guess the Servlet is your RMI client and you have the RMI server on your computer?

  Then you do the interaction Mobile phone -> Servlet -> your home computer -> Servlet -> mobile phone?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9831778
Yes... you are right... this is the exact communication flow...
0
 
LVL 35

Expert Comment

by:girionis
ID: 9831847
 So actually the Servlet (RMI client) throws a connection error while it tries to connect to your home computer (RMI server) since there is probably a firewall before the server.

  I am afraid there is nothing you can do about it unless you use techniques like HTTP-tunelling. Being behind a firewall/proxy is a big problem in an RMI application.

  Take a look here:

http://developer.java.sun.com/developer/onlineTraining/rmi/RMI.html#FirewallIssues
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9836063
Thanx for ur quick replies...
I am looking at this article.. but one thing is very strange... i am still unable to find any reason for this... Whenever I am connecting to servlets @ mycgiserver.com.. there IP of my computer is the previous one. not the current one... i don't know what could be the reason...
Gogo
http://www.mycgiserver.com/servlet/aiklamha.CheckIP
This will tell your current IP.. but in my case it's telling the previous IP.. can u tell me whether it's client or server side error?
0
 
LVL 35

Expert Comment

by:girionis
ID: 9836096
 Maybe your system is caching your IP somehow or maybe it is getting the second IP (if you are using both the network and dial up)?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9836486
I have checked by clearing all the cache.. all cookies.. and also i have checked using Tomcat.. all working fine.. only mycgiserver is giving such a nonsense output... I have also disabled my network card therefore there is no other IP..
0
 
LVL 35

Expert Comment

by:girionis
ID: 9836562
 I tried it and it gives me back the I.P. of the proxy server we are running... Have you tried to run your Servlet on another server?
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9836740
Yahooooooooooooooo!!! I have done it.....That was the server error ( i still don't know what was that) that was getting previous IP always.. so i have sent my current IP to the server with my first request to the servlet... then servlet connected back to my pc and boooom.. turned the light on...
Well i am still wondering if there is a way in Java that i could get IP Assigned to my Dial-up adapter without giving any pc name.....


Well thankyou very much.... for all your concern... tell me what i can do for ya????
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9836742
Yahooooooooooooooo!!! I have done it.....That was the server error ( i still don't know what was that) that was getting previous IP always.. so i have sent my current IP to the server with my first request to the servlet... then servlet connected back to my pc and boooom.. turned the light on...
Well i am still wondering if there is a way in Java that i could get IP Assigned to my Dial-up adapter without giving pc name.....


Well thankyou very much.... for all your concern... tell me what i can do for ya????
0
 
LVL 35

Expert Comment

by:girionis
ID: 9837342
 Glad problem is finally solved :)

  I told there was nothign wrong with your source code, problem was on the server side... maybe wrong configuration...
0
 
LVL 17

Author Comment

by:aiklamha
ID: 9838081
Yup!! You were always right.. and your suggestions cleared my way to solution very well...
Thanx a lot pal..
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert String matching to regex in java 4 49
expectj telnet failing 5 45
JavaFX TableView not displaying correctly 3 55
Facing this issue for maven proxy setting 2 20
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question