简体   繁体   English

使Java EE InitialContext查找合格的主机名? (针对JBoss EJB服务器)

[英]Make Java EE InitialContext find a qualified hostname? (against JBoss EJB server)

How do I use a fully qualified host name for the "java.naming.provider.url" property in the "env" parameter passed into (Java EE) InitialContext class. 如何在传递给(Java EE)InitialContext类的“ env”参数中的“ java.naming.provider.url”属性中使用完全限定的主机名。 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. 无论我输入IP地址还是完全限定的(host.domain ...)主机名,lookup(name)调用都将失败,表示找不到主机名,其中主机名只是主机名的“基本名”没有其域的主机。 Eg - 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: 例如,假设mypc.somedomain.net为1.2.3.4,则输入“ 1.2.3.4”或“ mypc.somedomain.net”将失败,并显示类似以下内容:

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

Do I need to pass a DNS server into InitialContext? 我是否需要将DNS服务器传递给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) (就像在“ ping mypc.somedomain.net”中一样)

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 (eg - "testbox") which does not require a fully qualified name. 为了对“ Robin”进行一些改进,我们通常在单独的JVM中运行客户端进程,该JVM通常会命中localhost上的服务器,或者有时会击中不需要相同子网/域的另一台主机(例如-“ testbox”)上的服务器全限定名称。

Also, I tried adding the "jns://" prefix and ":1099" suffix (eg - "jns://mypc.somedomain.net:1099"), not that these were required to make "testbox" work, and got the same exception. 此外,我尝试添加“ jns://”前缀和“:1099”后缀(例如,“ jns://mypc.somedomain.net:1099”),而不是使“ testbox”正常工作所必需的,并且有同样的例外。

I have googled around and found several instances of this error (InitialContext / JBoss -> UnknownHostException) or similar question, but no answers. 我四处搜寻,发现此错误的几个实例(InitialContext / JBoss-> UnknownHostException)或类似问题,但没有答案。 Ouch. 哎哟。

Upon closer inspection, this is a duplicate of: 经过仔细检查,这是以下内容的重复:

JBoss UnknownHostException when on different network 在不同网络上时,JBoss UnknownHostException

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. EJB客户端无法访问JBoss EJB服务器,除非以这样的方式启动JBoss服务器,即服务器知道其自己的(完全限定的)名称。

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. 我的Windows XP PC知道它的“短”名称,但是您必须给jboss使用参考问题中提到的-b参数(绑定)为其本身指定完全限定的名称。 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). 关于JNDI(或EJB?)协议的某些事情需要某种“双重查找”,即在找到主机之后,查询主机的名称,然后再次查找(或不查找)。 Go figure. 去搞清楚。 Anti spoofing protection??? 反欺骗保护???

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 Java EE container and you have to do the appropriate configuration for running a thin client as should be defined somewhere in your app servers documentation. 如果是这种情况,则它不在Java EE容器中运行,并且您必须执行适当的配置以运行瘦客户端,如应在应用服务器文档中定义的位置。

Simply trying to lookup the InitialContext from a fully qualified name will not work. 简单地尝试从完全限定的名称中查找InitialContext是行不通的。 I have never done this for JBoss, but I have for WAS. 我从未为JBoss做到这一点,但为WAS做过。 You will have to find out what JBoss jars and configurations are required for that to work. 您将必须找出工作所需的JBoss jar和配置。

Like WAS, they may have some means of creating a Client Container which would then allow you full access to Java EE resources in the normal way. 像WAS一样,它们可能具有一些创建客户端容器的方法,然后将允许您以常规方式完全访问Java EE资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM