views:

454

answers:

2

How do I use a fully qualified host name for the "java.naming.provider.url" property in the "env" parameter passed into (J2EE) InitialContext class. Whether I pass in an IP address, or a fully qualified (host.domain...) host name, the lookup( name) call will fail, saying it cannot find the hostname, where the hostname is just the "basename" of the host without its domain. E.g. - say that mypc.somedomain.net is 1.2.3.4, putting in either "1.2.3.4" or "mypc.somedomain.net" will fail with something like:

javax.naming.CommunicationException java.rmi.UnknownHostException: mypc

Do I need to pass a DNS server into InitialContext? What isn't it smart enough to just let the underlying OS do the job? (as in "ping mypc.somedomain.net", which just works)

The client and the server are neither on the same machine, nor the same subnet, so I have to use a fully qualified hostname. To refine this a bit for "Robin", we normally run a client process in a separate JVM which typically hits a server on localhost, or sometimes on another host on the same subnet / domain (e.g. - "testbox") which does not require a fully qualified name.

Also, I tried adding the "jns://" prefix and ":1099" suffix (e.g. - "jns://mypc.somedomain.net:1099"), not that these were required to make "testbox" work, and got the same exception.

I have googled around and found several instances of this error (InitialContext / JBoss -> UnknownHostException) or similar question, but no answers. Ouch.

A: 

Your last statement implies that you are running the client as a standalone application. If this is the case, it is not running in a JEE container and you have to do the appropriate configuration for running a thin client as should be defined somewhere in your app servers documentation.

Simply trying to lookup the InitialContext from a fully qualified name will not work. I have never done this for JBoss, but I have for WAS. You will have to find out what JBoss jars and configurations are required for that to work.

Like WAS, they may have some means of creating a Client Container which would then allow you full access to JEE resources in the normal way.

Robin
+1  A: 

Upon closer inspection, this is a duplicate of:

http://stackoverflow.com/questions/840292/jboss-unknownhostexception-when-on-different-network

The EJB client fails to access the JBoss EJB server, UNLESS the JBoss server is started in such a way that the server knows its own (fully qualified) name.

My Windows XP PC knows its "short" name, but you have to give jboss the fully qualified name for itself with the -b parameter (bind) mentioned in the referenced question. Something about the JNDI (or EJB?) protocol requires some kind of "double lookup" where after the host is found, it is queried for its name, and then looked up again (or not). Go figure. Anti spoofing protection???

Roboprog