JMS - 查找问题

时间:2011-05-23 12:10:46

标签: java glassfish jms lookup

我正在使用Glassfish v3处理java中的JMS程序。现在的问题是我添加了一个QueueConnectionFactory类型的ConnectionFactory,它的名字是:“jms / KwetterFactory”。以及Queue类型的目标资源,它的名称为“jms / KwetterQueue”。

现在我运行以下代码:

public Sender() throws JMSException, NamingException
    {
        // get the initial context
       InitialContext ctx = new InitialContext();

       // lookup the queue connection factory
       QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup("jms/KwetterFactory");

       // lookup the queue object
       Queue queue = (Queue) ctx.lookup("jms/KwetterQueue");

       // create a queue connection
       QueueConnection queueConn = connFactory.createQueueConnection();

       // create a queue session
       QueueSession queueSession = queueConn.createQueueSession(false,
           Session.DUPS_OK_ACKNOWLEDGE);

       // create a queue sender
       QueueSender queueSender = queueSession.createSender(queue);
       queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

       // create a simple message to say "Hello"
       TextMessage message = queueSession.createTextMessage("Hello");

       // send the message
       queueSender.send(message);

       // print what we did
       System.out.println("sent: " + message.getText());

       // close the queue connection
       queueConn.close();
    }

我收到此错误:

java.lang.RuntimeException: Orb initialization erorr
        at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:148)
        at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
        at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
        at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
        at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at Sender.Sender.(Sender.java:32)
        at GUI.GUI.jButton1ActionPerformed(GUI.java:73)
        at GUI.GUI.access$000(GUI.java:24)
        at GUI.GUI$1.actionPerformed(GUI.java:47)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6263)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6028)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Caused by: java.lang.NullPointerException
        at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:120)
        ... 36 more May 23, 2011 2:09:10 PM GUI.GUI jButton1ActionPerformed SEVERE: null javax.naming.NamingException: Lookup failed for 'jms/KwetterFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at Sender.Sender.(Sender.java:32)
        at GUI.GUI.jButton1ActionPerformed(GUI.java:73)
        at GUI.GUI.access$000(GUI.java:24)
        at GUI.GUI$1.actionPerformed(GUI.java:47)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6263)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6028)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
        at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
        ... 31 more Caused by: java.lang.RuntimeException: Orb initialization erorr
        at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:148)
        at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
        at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
        at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
        at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
        ... 32 more Caused by: java.lang.NullPointerException
        at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:120)
        ... 36 more BUILD SUCCESSFUL (total time: 9 seconds)

有谁知道导致这个问题的原因是什么?

2 个答案:

答案 0 :(得分:2)

试试看 http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB “如何从独立的Java客户端访问远程EJB组件?”

您需要查看多个项目。祝你好运。

答案 1 :(得分:1)

要访问远程ConnectionFactory,您需要指定Context属性,包括主机和端口。例如:

    Context context = null;
    String host = "192.168.0.101";
    String port = "3700";
    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", host);
    props.setProperty("org.omg.CORBA.ORBInitialPort", port);

    try
    {
        context = new InitialContext(props);
    }
    catch (NamingException e)
    {
        System.out.println("JMSCommon Error: Can't init JNDI Context" + "(" + e + ")");
        System.exit(0);
    }