views:

554

answers:

1

I am writing a small utility to send JMS messages to a remote server, but I am failing to configure correctly the InitialContext (or so it seems)

code to init the Context:

      Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, 
            "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      p.put(Context.PROVIDER_URL, "jnp://10.10.10.10:1099/");
      Context context = new InitialContext(p);

But when I run it I get an exception:

javax.naming.CommunicationException 
[Root exception is java.rmi.ConnectException: 
Connection refused to host: 127.0.0.1; 
nested exception is: 
java.net.ConnectException: Connection refused: connect]

So what is baffling me is that is complaining about 127.0.0.1 event though I am configuring it for 10.10.10.10, which is alive, running jboss, no firewall, I can get a telnet session to port 1099, so it seems to be ok

Any pointers ? or helpers ?

+1  A: 

This is because JNDI, and dependent protocols, are connect-back in nature, and subsequent requests will go to the IP that the server 'believes' it should be listening on. If you telnet to 10.10.10.10:1099, and look at the output, you'll see something like this:

telnet 10.10.10.10 1099
[Connection message]
[Garbage]
127.0.0.1....

The reason is that your server is 'serving' on 127.0.0.1, and will reply with that address as the JNDI location. Because you are (most likely) on a remote machine, when your remote machine tries to connect to the IP that the Jboss server informed it to connect to (127.0.0.1), it tries to connect to itself, not to the JBoss server.

You need to either start jboss with: ./run.sh -b 0.0.0.0 (all IP bind), or change your localhost entry on the machine to 10.10.10.10

(Incidentally, I remember struggling with this one for ages, and know how frustrating it is)

Chaos
This looks promising :) definitely will try tomorrow morning and report back
webclimber
Yeah - I remember spending days on this a few years back. The smoking gun is in the telnet session - if it says 127.0.0.1 at the end of it, that's the IP that your remote client will try to connect to. You can also use this to check your fix - the correct IP will be listed there once it works.
Chaos
worked like a charm, I had to choose a single ip, for the -b param, didn't seem to work for the multi-homed machine.
webclimber
I had the same problem with Jboss, and I am just wondering if there was a better user-friendly way of configuring it. I remember wasting couple of days as I wanted to use Jboss for the first time on a remote machine. I found my answer in a group like this. Anybody has any idea if they have a help doc for this config?
paradisonoir