users@glassfish.java.net

RMI Connection refused to localhost

From: <glassfish_at_javadesktop.org>
Date: Wed, 25 Mar 2009 06:58:51 PDT

Hi,
I have a GlassFish V2 app-server installed on my WIndows PC as part of a local J CAPS 6 installation, for testing and learning purposes.

And it works fine as long as I'm not connected to the company network at work, where I get java.rmi.ConnectException: Connection refused to host: Ynnnnnnn (the hostname of my PC) at startup.
(at home, connected via VPN through an ADSL router, evertything is fine)

The reason seems to be that RMI uses the hostname of the machine when accessing the registry, which is not always accessible, assumably because of some firewall or proxy issue.
In other words, the name as returned by dos command [i]hostname [/i]may not be accessible as an RMI host, even from the same host (i.e. localhost).

This can be circumvented by defining java.rmi.server.hostname=localhost when starting the RMI server JVM (I have verified this, by reproducing the failure in a simple RMI app, and then make it work by defining the mentioned RMI property).

But how can I apply the same solution for GlassFish?
I have tried to replace all occurrences of <myComputerName> in domain.xml and sun-acc.xml by localhost with no effect.
Also, I tried to include -Djava.rmi.server.hostname=localhost both in the startup script and in domain.xml, without any success.
Even fiddling with /etc/host has been attempted, among other things.

Whatever I try, RMI insists on using <myComputerName> when connecting. Here's excerpts from server.log:


[#|2009-03-25T14:26:33.793+0100|SEVERE|sun-appserver9.1|javax.enterprise.system.core|_ThreadID=10;_ThreadName=main;_RequestID=e4d2eb34-6861-42c8-ac29-e324bef2f4c4;|CORE5071: An error occured during initialization
com.sun.appserv.server.ServerLifecycleException: Cannot bind to URL [rmi://Ynnnnnnn:8686/management/rmi-jmx-connector]: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: Ynnnnnnn; nested exception is:
        java.net.ConnectException: Connection timed out: connect]
        at com.sun.enterprise.admin.server.core.JmxConnectorLifecycle.onStartup(JmxConnectorLifecycle.java:153)
        at com.sun.enterprise.server.ApplicationServer.onStartup(ApplicationServer.java:442)
        at com.sun.enterprise.server.ondemand.OnDemandServer.onStartup(OnDemandServer.java:120)
        at com.sun.enterprise.server.PEMain.run(PEMain.java:409)
        at com.sun.enterprise.server.PEMain.main(PEMain.java:336)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.server.PELaunch.main(PELaunch.java:412)
Caused by: java.io.IOException: Cannot bind to URL [rmi://Ynnnnnnn:8686/management/rmi-jmx-connector]: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: Ynnnnnnn; nested exception is:
        java.net.ConnectException: Connection timed out: connect]
        at javax.management.remote.rmi.RMIConnectorServer.newIOException(RMIConnectorServer.java:804)
        at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:417)
        at com.sun.enterprise.admin.jmx.remote.server.rmi.JmxConnectorServerDriver.startConnectorServer(JmxConnectorServerDriver.java:239)
        at com.sun.enterprise.admin.server.core.JmxConnectorLifecycle.onStartup(JmxConnectorLifecycle.java:134)


Regards,
Erik
[Message sent by forum member 'erik56gd' (erik56gd)]

http://forums.java.net/jive/thread.jspa?messageID=338959