JMS - проблема поиска - PullRequest
       25

JMS - проблема поиска

3 голосов
/ 23 мая 2011

Я работаю над JMS-программой на Java, работающей со Glassfish v3. Теперь дело в том, что я добавил ConnectionFactory типа QueueConnectionFactory и назвал его «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 ]

2 голосов
/ 23 мая 2011

Попробуйте посмотреть на http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB «Как получить доступ к компоненту Remote EJB из автономного Java-клиента?»

Там есть несколько пунктов, которые вы должны просмотреть. Удачи.

1 голос
/ 24 ноября 2011

Для доступа к удаленной 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);
    }
...