更新这个问题似乎与Ubuntu操作系统是虚拟化的事实有关,也就是说我已经使用Vmware Workstation来创build主机操作系统(Windows)和客户操作系统(Ubuntu)。
当我将EJB部署到主机上的Glassfish时(Windows); 我可以在主机(Windows)或客户机(Ubuntu)上使用servlet客户机来查找EJB。 我还可以指定主机或来宾的设置来查找EJB。 我相信这就是问题所在,即查找总是在主机上完成,无论主机设置或访客设置是否在servlet中提供。 有没有人有类似的经验,你做了什么来解决它。
原来的问题
请参阅下面的代码:
Properties props = new Properties(); props = new Properties(); props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory"); props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.163.128"); props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); try { InitialContext ctx = new InitialContext(props); RemoteInterfaceRemote r = (RemoteInterfaceRemote) ctx.lookup("java:global/Course/RemoteInterface!com.w0051977.dao.RemoteInterfaceRemote");//!com.w0051977.dao.RemoteInterfaceRemote String greeting = r.Greeting("Ian"); System.out.println("got here"); } catch (NamingException n) { System.out.println(n.toString()); }
该代码在Servlet中find并按预期工作,其中包含“Good afternoon Ian”。 该Servlet运行在Windows PC上,并连接到一个Windows服务器,这个企业bean是托pipe的。
但是,当我将这个bean移动到Linux(Ubuntu)PC时,我遇到了问题。 上面的代码将在Linux PC上的一个Servlet中运行(在这种情况下,客户端和服务器在同一台计算机上)。 但是,我无法获得上面的代码在Windows PC上的servlet中工作。
当Windows客户端(servlet)连接到Linux(Ubuntu)服务器时,有没有什么特别的事情要做? 移动服务器时,我明显改变了上面代码中的IP地址。 例外是:
Lookup failed for 'java:global/Course/RemoteInterface' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=ubuntu, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming
Glassfish控制台(在Ubuntu上)的输出是:
[2016-10-14T08:57:16.824-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460636824] [levelValue: 800] [[ visiting unvisited references]] [2016-10-14T08:57:16.890-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460636890] [levelValue: 800] [[ visiting unvisited references]] [2016-10-14T08:57:17.238-0700] [glassfish 4.1] [INFO] [AS-EJB-00054] [javax.enterprise.ejb.container] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637238] [levelValue: 800] [[ Portable JNDI names for EJB RemoteInterface: [java:global/Course/RemoteInterface, java:global/Course/RemoteInterface!com.w0051977.dao.RemoteInterfaceRemote]]] [2016-10-14T08:57:17.248-0700] [glassfish 4.1] [INFO] [AS-EJB-00055] [javax.enterprise.ejb.container] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637248] [levelValue: 800] [[ Glassfish-specific (Non-portable) JNDI names for EJB RemoteInterface: [com.w0051977.dao.RemoteInterfaceRemote#com.w0051977.dao.RemoteInterfaceRemote, com.w0051977.dao.RemoteInterfaceRemote]]] [2016-10-14T08:57:17.432-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637432] [levelValue: 900] [[ WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]] [2016-10-14T08:57:17.472-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637472] [levelValue: 900] [[ WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]] [2016-10-14T08:57:17.482-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637482] [levelValue: 900] [[ WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]] [2016-10-14T08:57:18.078-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460638078] [levelValue: 800] [[ Course was successfully deployed in 1,282 milliseconds.]]
我花了好几天的时间来看这个。 请帮忙。
输出:sudo lsof -i:3700是(请注意,我没有改变IP版本为4根据@ RC评论:
从Windows PC Pinging Ubuntu PC时有答复。
这是Linux服务器上的JNDI树:
JNDI查找名称应该在远程服务器上? 我必须在本地Glassfish PC(Windows PC)上进行任何configuration吗?
这听起来可能是一个防火墙问题。 尝试telnet你的Linux机器从端口3700的Windows机器。如果无法连接,添加防火墙规则,以允许传入端口3700流量。这应该允许EJB通信。 但是你也可能想要允许你的http / https传入请求。
希望有所帮助。