1

我安装了两台服务器。两者都在运行自己的 Glassfish 4.0 域。

在一台服务器上,我安装了一个 Singleton Remote EJB。此 Glassfish 具有指定的 IIOP 侦听器(名称=启用 UF=true 网络地址=192.168.10.95 侦听器端口=1072)。

第二个 Glassfish 实例正在运行一个简单的 JSF-2.2 应用程序。现在我正在尝试在一个 JSF-Managed-Bean 构造函数中连接到远程 ejb。

        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
        props.put(Context.PROVIDER_URL, "iiop://192.168.10.95:1072");
        props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.10.95");
        props.setProperty("org.omg.CORBA.ORBInitialPort", "1072");
        InitialContext ctx = new InitialContext(props);
        return (IUF) ctx.lookup("java:global/UFRemote/UFRemote!com.uf.IUF");

查找大约需要一分钟,最终出现以下异常:

SEVERE:   javax.naming.NamingException: Lookup failed for 'java:global/UFRemote/UFRemote!uf.IUserFramework' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=1072, java.naming.provider.url=iiop://192.168.10.95:1072, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=192.168.10.95, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=1072, java.naming.provider.url=iiop://192.168.10.95:1072, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=192.168.10.95, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 192.168.10.95; port: 1072  vmcid: OMG  minor code: 1  completed: No]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at uf.UF.lookupIUserFramework(UF.java:47)
at uf.UF.<clinit>(UF.java:17)
at beans.TestBean.<init>(TestBean.java:22)
at beans.TestBean$Proxy$_$$_WeldClientProxy.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:374)
at java.lang.Class.newInstance(Class.java:327)
at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.weld.bean.proxy.ProxyFactory.create(ProxyFactory.java:262)
at org.jboss.weld.bean.proxy.ClientProxyFactory.create(ClientProxyFactory.java:103)
at org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:157)
at org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:147)
at org.jboss.weld.bean.proxy.ClientProxyProvider.access$000(ClientProxyProvider.java:49)
at org.jboss.weld.bean.proxy.ClientProxyProvider$1.apply(ClientProxyProvider.java:57)
at org.jboss.weld.bean.proxy.ClientProxyProvider$1.apply(ClientProxyProvider.java:53)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:358)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153)
at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69)
at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:396)
at org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientProxyProvider.java:163)
at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:115)
at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:96)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
at com.sun.el.parser.AstValue.getBase(AstValue.java:151)
at com.sun.el.parser.AstValue.getValue(AstValue.java:200)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=1072, java.naming.provider.url=iiop://192.168.10.95:1072, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=192.168.10.95, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 192.168.10.95; port: 1072  vmcid: OMG  minor code: 1  completed: No]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:334)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477)
... 86 more
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 192.168.10.95; port: 1072  vmcid: OMG  minor code: 1  completed: No
at com.sun.proxy.$Proxy214.connectFailure(Unknown Source)
at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:253)
at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:276)
at com.sun.corba.ee.impl.transport.ContactInfoImpl.createConnection(ContactInfoImpl.java:129)
at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.beginRequest(ClientRequestDispatcherImpl.java:243)
at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.request(ClientDelegateImpl.java:227)
at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.is_a(ClientDelegateImpl.java:392)
at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1205)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:393)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:329)
... 87 more
Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:344)
at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:250)
... 97 more
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:364)

我认为,连接有问题,因为如果我将两者都部署在同一个 Glassfish 实例上,一切正常。

如何从不同的 Glassfish 域正确调用远程 EJB?

4

1 回答 1

2

1) IP 寻址

尝试将 org.omg.CORBA.ORBInitialHost 设置为网络主机名而不是 IP 地址。确保客户端可以通过主机名(ping 主机名)访问服务器,如有必要,编辑主机表(linux:etc/hosts windows:c:\windows\system32\drivers\hosts)并添加一行:

“ip”“主机名”(例如 192.168.1.1 server1)

(即使您解决了命名问题,也会因为直接 IP 寻址而出现问题)

2) 访问远程 GlassFish 服务器中的 EJB 组件

除了 ip 问题,请确保服务器声明了 JDNI 资源。请参阅 Glassfish 应用程序开发指南手册中的以下文本:

从作为 servlet 或 EJB 组件的客户端查找远程 GlassFish Server 中的 EJB 组件的推荐方法是使用互操作命名服务语法。主机和端口信息被添加到任何全局 JNDI 名称之前,并在查找期间自动解析。可互操作的全局名称的语法如下:

corbaname:iiop:host:port#a/b/name

这使得在另一个 GlassFish Server 中访问 EJB 组件的编程模型与在同一服务器中访问它们完全相同。部署者可以更改 EJB 组件的物理分布方式,而无需更改代码。

对于 Java EE 组件,代码仍然在 EJB 引用上执行java:comp/env查找。唯一的区别是部署程序将 ejb-ref 元素映射到 GlassFish Server 部署描述符文件中的可互操作名称,而不是简单的全局 JNDI 名称。

例如,假设 servlet 使用 查找 EJB 引用 java:comp/env/ejb/Foo,并且目标 EJB 组件的全局 JNDI 名称为 a/b/Foo

glassfish-web.xml中的 ejb-ref 元素如下所示:

<ejb-ref>
    <ejb-ref-name>ejb/Foo</ejb-ref-name>
    <jndi-name>corbaname:iiop:host:port#a/b/Foo</jndi-name>
</ejb-ref>

代码如下所示:

Context ic = new InitialContext();
Object o = ic.lookup("java:comp/env/ejb/Foo");

对于不在 Java EE 容器中运行的客户端,代码只使用可互操作的全局名称而不是简单的全局 JNDI 名称。例如:

Context ic = new InitialContext();
Object o = ic.lookup("corbaname:iiop:host:port#a/b/Foo");

存储在可互操作命名上下文和组件特定 (java:comp/env) 命名上下文中的对象是临时的。在每次服务器启动或应用程序重新加载时,所有相关对象都会重新绑定到命名空间。

(GlassFish Server 开源版 4.0 应用开发指南)

于 2013-11-23T18:11:12.087 回答