[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 708
  • Last Modified:

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

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
Muhammad Khan
Asked:
Muhammad Khan
  • 16
  • 15
1 Solution
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Muhammad KhanManager, ITAuthor Commented:
Thanx Again..that's so nice of u.. well.. i will check the code and then again come back...
0
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 Is there a firewall/proxy in the middle?
0
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
> 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
> 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
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
It's my Home computer... and this IP is not static.....it is assigned dynamically whenever i dial-in to my ISP...
0
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
Yup!!!
This is the actual case....

0
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
Yes... you are right... this is the exact communication flow...
0
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
Muhammad KhanManager, ITAuthor Commented:
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
 
girionisCommented:
 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
 
Muhammad KhanManager, ITAuthor Commented:
Yup!! You were always right.. and your suggestions cleared my way to solution very well...
Thanx a lot pal..
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 16
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now