从远程客户端使用 Glassfish JMS

Posted

技术标签:

【中文标题】从远程客户端使用 Glassfish JMS【英文标题】:Use Glassfish JMS from remote client 【发布时间】:2011-01-29 13:18:14 【问题描述】:

我在服务器上安装了 glassfish,并使用 JMS ConnectionFactory 设置了 jms/MyConnectionFactory 和资源类型或 javax.jms.ConnectionFactory。

我现在想从本地计算机上的客户端应用程序访问它,为此我有以下内容:

public static void main(String[] args) 
        try
            Properties env = new Properties();
            env.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
            env.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
            env.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
            env.setProperty("org.omg.CORBA.ORBInitialHost", "10.97.3.74");
            env.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
            InitialContext initialContext = new InitialContext(env);
            ConnectionFactory connectionFactory = null;
            try 
                connectionFactory = (ConnectionFactory)
                initialContext.lookup("jms/MyConnectionFactory");
             catch (Exception e) 
              System.out.println("JNDI API lookup failed: " + e.toString());
              e.printStackTrace();
              System.exit(1);
            
        catch(Exception e) e.printStackTrace(System.err);
        
    

当我运行我的客户端时,我得到以下输出:

INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=10.97.3.74, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming
19-Mar-2010 16:09:13 org.hibernate.validator.util.Version <clinit>
INFO: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
19-Mar-2010 16:09:13 org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
19-Mar-2010 16:09:13 com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: SJSMQ JMS Resource Adapter starting: REMOTE
19-Mar-2010 16:09:13 com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: SJSMQ JMSRA Started:REMOTE
19-Mar-2010 16:09:13 com.sun.enterprise.naming.impl.SerialContext lookup
SEVERE: enterprise_naming.serialctx_communication_exception
19-Mar-2010 16:09:13 com.sun.enterprise.naming.impl.SerialContext lookup
SEVERE: 
java.lang.RuntimeException: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: This pool is not bound in JNDI : jms/MyConnectionFactory
        at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance(ConnectorObjectFactory.java:159)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:472)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:437)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at simpleproducerclient.Main.main(Main.java:89)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:424)
        at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:134)
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: This pool is not bound in JNDI : jms/MyConnectionFactory
        at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.obtainManagedConnectionFactory(ConnectorConnectionPoolAdminServiceImpl.java:1017)
        at com.sun.enterprise.connectors.ConnectorRuntime.obtainManagedConnectionFactory(ConnectorRuntime.java:375)
        at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance(ConnectorObjectFactory.java:124)
        ... 11 more
Caused by: javax.naming.NamingException: Lookup failed for '__SYSTEM/pools/jms/MyConnectionFactory' in SerialContext targetHost=localhost,targetPort=3700,orb'sInitialHost=ithfdv01,orb'sInitialPort=3700 [Root exception is javax.naming.NameNotFoundException: pools]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.getConnectorConnectionPool(ConnectorConnectionPoolAdminServiceImpl.java:804)
        at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.obtainManagedConnectionFactory(ConnectorConnectionPoolAdminServiceImpl.java:932)
        ... 13 more
Caused by: javax.naming.NameNotFoundException: pools
        at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:252)
        at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:171)
        at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:172)
        at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:58)
        at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:89)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:146)
        at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:176)
        at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:682)
        at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:216)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1841)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1695)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1078)
        at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:221)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:797)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:561)
JNDI API lookup failed: javax.naming.CommunicationException: Communication exception for SerialContext targetHost=10.97.3.74,targetPort=3700,orb'sInitialHost=ithfdv01,orb'sInitialPort=3700 [Root exception is java.lang.RuntimeException: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: This pool is not bound in JNDI : jms/MyConnectionFactory]
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2558)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
javax.naming.CommunicationException: Communication exception for SerialContext targetHost=10.97.3.74,targetPort=3700,orb'sInitialHost=ithfdv01,orb'sInitialPort=3700 [Root exception is java.lang.RuntimeException: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: This pool is not bound in JNDI : jms/MyConnectionFactory]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:461)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at simpleproducerclient.Main.main(Main.java:89)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:424)
        at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:134)
Caused by: java.lang.RuntimeException: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: This pool is not bound in JNDI : jms/MyConnectionFactory
        at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance(ConnectorObjectFactory.java:159)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:472)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:437)
        ... 8 more
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: This pool is not bound in JNDI : jms/MyConnectionFactory
        at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.obtainManagedConnectionFactory(ConnectorConnectionPoolAdminServiceImpl.java:1017)
        at com.sun.enterprise.connectors.ConnectorRuntime.obtainManagedConnectionFactory(ConnectorRuntime.java:375)
        at com.sun.enterprise.resource.naming.ConnectorObjectFactory.getObjectInstance(ConnectorObjectFactory.java:124)
        ... 11 more
Caused by: javax.naming.NamingException: Lookup failed for '__SYSTEM/pools/jms/MyConnectionFactory' in SerialContext targetHost=localhost,targetPort=3700,orb'sInitialHost=ithfdv01,orb'sInitialPort=3700 [Root exception is javax.naming.NameNotFoundException: pools]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.getConnectorConnectionPool(ConnectorConnectionPoolAdminServiceImpl.java:804)
        at com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl.obtainManagedConnectionFactory(ConnectorConnectionPoolAdminServiceImpl.java:932)
        ... 13 more
Caused by: javax.naming.NameNotFoundException: pools
        at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:252)
        at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:171)
        at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:172)
        at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:58)
        at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:89)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:146)
        at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:176)
        at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:682)
        at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:216)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1841)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1695)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1078)
        at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:221)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:797)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:561)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2558)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)

我查看了许多帖子并尝试了许多方法,但均未成功。我可以在我的服务器上运行以下命令:

./asadmin list-jndi-entries

UserTransaction: com.sun.enterprise.transaction.TransactionNamingProxy$UserTransactionProxy
java:global: com.sun.enterprise.naming.impl.TransientContext
jdbc: com.sun.enterprise.naming.impl.TransientContext
ejb: com.sun.enterprise.naming.impl.TransientContext
com.sun.enterprise.container.common.spi.util.InjectionManager: com.sun.enterprise.container.common.impl.util.InjectionManagerImpl
jms: com.sun.enterprise.naming.impl.TransientContext

Command list-jndi-entries executed successfully.

./asadmin list-jndi-entries --context jms

MyTopic: org.glassfish.javaee.services.ResourceProxy
MyConnectionFactory: org.glassfish.javaee.services.ResourceProxy
MyQueue: org.glassfish.javaee.services.ResourceProxy

Command list-jndi-entries executed successfully.

非常感谢任何帮助。

干杯,

詹姆斯

【问题讨论】:

【参考方案1】:
Caused by: javax.naming.NameNotFoundException: pools

这似乎是由最近(2010 年 2 月 15 日)修复的 bug 引起的。您需要至少升级到GF v3.0.1 build 05。试试看吧。

【讨论】:

我已经更新到 (GlassFish 3 (build 9)) 仍然看到同样的错误。 我没有更新本地版本的 glassfish,只更新了服务器版本,一旦我更新了本地版本,它就可以与 3.0.1 build 9 一起使用。知道 3.0.1 何时发布吗?跨度> 已经发布了,你还在用build 9。你不是说3.0.2左右吗?

以上是关于从远程客户端使用 Glassfish JMS的主要内容,如果未能解决你的问题,请参考以下文章

远程 JMS 队列的客户端

使用glassfish服务器的JMS客户端

Glassfish V3.x 和远程独立客户端

如何从远程机器访问 websocket

将 Glassfish 与 IIOP 结合使用时的完整协议层次结构是啥

Eclipse Oxygen 发布(4.7.0)远程调试 Glassfish NullPointerException