3
votes

I'm working on a JMS program in java working with Glassfish v3. Now the thing is that I've added a ConnectionFactory of type QueueConnectionFactory and it's named: "jms/KwetterFactory". And a Destination Resource of type Queue and it's named "jms/KwetterQueue".

Now when I run the following code:

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();
    }

I get this error:

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)

Anyone knows what causes this problem?

2
Uhm ... why is there AWT/Swing code in your Glassfish? - Joachim Sauer
I've created a swing application with one button. When I click on it it initializes this Sender class, which will send the message (atleast it is supposed to do so). Thanks for the edit though, how did you manage to put the scrollbars on? - Julian
I changed your quote text (> foo) to use <pre> instead (<pre>foo</pre>). - Joachim Sauer
Your Swing class runs outside of your Application Container (Glassfish). Therefore it can't do lookups, because the environment is not correctly initialized. - Joachim Sauer
@Joachim, I've looked into that but it seems to be posible to just use a lookup without being inside the Application Contrainer of glassfish. - Julian

2 Answers

2
votes

Try looking at http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB "How do I access a Remote EJB component from a stand-alone java client?"

There are multiple items in there you need to review. Good luck.

1
votes

For accessing remote ConnectionFactory you need to specify Context properties, including the host and the port. For example something like this:

    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);
    }