3
votes

Using JBoss AS 6.1.0 Final with "default" deployment profile.

I like to send a JMS message from a Session Bean. I set the following:

/server/default/deploy/my-hornetq-jms:

<configuration xmlns="urn:hornetq"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">

    <queue name="queue/DummyMDBean">
        <entry name="jms/DummyMDBean"/>
    </queue>
</configuration>

In the bean I have:

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class Demo implements DemoRemote, DemoLocal {
    ...
    @Resource(mappedName = "java:/ConnectionFactory")
    private static QueueConnectionFactory queueConnectionFactory;

    @Resource(mappedName = "/jms/DummyMDBean")
    private static Queue queue;

    public void example() {
        QueueConnection queueConnection = null;
        try {
            queueConnection = queueConnectionFactory.createQueueConnection();
        } catch (JMSException e) {
            System.out.println("Exception occurred: " + e.toString());
            e.printStackTrace();
        }

        try {
            QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            QueueSender queueSender = queueSession.createSender(queue);

            // Send a text message:
            TextMessage textMessage = queueSession.createTextMessage();
            textMessage.setText("Hello World");

            queueSender.send(textMessage);
        } catch (JMSException e) {
            System.out.println("Exception occurred: " + e.toString());
            e.printStackTrace();
        } finally {
            closeConnection(queueConnection);
        }
    }

I get the following error:

15:46:05,011 INFO  [STDOUT] Exception occurred: javax.jms.JMSException: Failed to create session factory
15:46:05,661 ERROR [STDERR] javax.jms.JMSException: Failed to create session factory
15:46:05,666 ERROR [STDERR]     at    org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:605)
15:46:05,667 ERROR [STDERR]     at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:131)
15:46:05,668 ERROR [STDERR]     at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:126)
15:46:05,669 ERROR [STDERR]     at com.demo.Demo.example(Demo.java:109)

...

15:46:05,782 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:722)
15:46:05,783 ERROR [STDERR] Caused by: java.lang.NullPointerException
15:46:05,784 ERROR [STDERR]     at org.hornetq.core.client.impl.ServerLocatorImpl.removeFromConnecting(ServerLocatorImpl.java:682)
15:46:05,784 ERROR [STDERR]     at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:751)
15:46:05,785 ERROR [STDERR]     at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:601)
15:46:05,785 ERROR [STDERR]     ... 180 more

line 109 is the "queueConnection = queueConnectionFactory.createQueueConnection();".

I didn't change anything from the default except of the xml above. Any ideas about the problem, and how to fix it?

1
Unrelated to the question, but your first try/catch doesn't seem to make much sense. If it throws you just continue (with an invalid connection). The second try catch does exactly the same logging. You can remove the first catch and the second try.Arjan Tijms
@Arjan i know but this is just a test to try findout why its fail.roterl

1 Answers

2
votes

Is line 109 in Demo.java corresponding to the following line?

QueueSender queueSender = queueSession.createSender(queue);

I guess that queue might be null. You could try to declare your queue as follows:

<queue name="queue/DummyMDBean">
    <entry name="/jms/DummyMDBean"/>
</queue>

Update:

The used connection factory can also be problematic in an EJB environment. In AS 6.10 /ConnectionFactory is a kind of unmanaged factory that works in Servlets and JSF managed beans to create direct destination listeners (which is otherwise forbidden in the container).

For usage in EJB it seems you now actually should use java:/jmsXA instead (this was different in 6.0 and 5.x). E.g.

@Resource(mappedName = "java:/JmsXA")
private ConnectionFactory queueConnectionFactory;