users@glassfish.java.net

JMS destination queue lookup problem via the SessionContext

From: <glassfish_at_javadesktop.org>
Date: Mon, 15 Oct 2007 12:41:44 PDT

Hi,

I have Stateless session bean, that exposes a method, that takes two parameters, with one parameter specifying the destination name and the other parameter being the actual value to be posted on the queue.

My problem is that when I inject the destination via the @Resource annotation everything works fine. When I try and look it up using the session context, I get an error:

 javax.naming.NameNotFoundException: No object bound to name java:comp/env/SyncProcessQ

The code is as follows:
@Stateless(name= "MessengerImplEJB")
@Remote(MessengerRemote.class)
public class MessengerImpl implements Messenger {

    @Resource(name="Sample")
    private ConnectionFactory connectionFactory;

    @Resource(mappedName="SyncProcessQ")
    private Destination syncProcessQ;

    @Resource
    private SessionContext ctx;

    public void sendMessage(String queue, MetaNode message) {
        try {
            Connection connection = connectionFactory.createConnection();
            Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer((Destination) ctx.lookup(queue));
            producer.send(session.createObjectMessage(message));

        } catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}


Can anybody tell m why the above code fails? If I use the injected destination, it works fine. If I try to look it up using the same name 'SyncProcessQ', it cannot be found

Am I missing something?
[Message sent by forum member 'maniecoetzee' (maniecoetzee)]

http://forums.java.net/jive/thread.jspa?messageID=240212