users@glassfish.java.net

Session Bean & JMS

From: <glassfish_at_javadesktop.org>
Date: Tue, 30 Oct 2007 14:24:48 PST

Guys,
      Inside my Session Bean, i need to lookup a JMS Topic and post message.

[1] Here is my session bean:
@Stateless
public class JMSSessionBean implements JMSSessionLocal{
        @Resource(mappedName = "jms/OutboundTopicConnectionFactory")
        private ConnectionFactory topicCF;
        @Resource(mappedName = "jms/OutboundTopic")
        private Topic topic;
        
    public void postResults(String status) {
        try{
            System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@Printing inside the Session Bean!" + status);
            Context jndiContext = null;
            TopicConnectionFactory topicCF = null;
            TopicConnection topicConnection = null;
            TopicSession topicSession = null;
            Topic topic = null;
            TopicPublisher topicPublisher = null;
            TextMessage message = null;
            
            jndiContext = new InitialContext();
            topicConnection = topicCF.createTopicConnection();
            topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            topicPublisher = topicSession.createPublisher(topic);
            message = topicSession.createTextMessage();
            message.setText(status);
            
            topicPublisher.publish(message);
            
            if (topicConnection != null) {
                try {
                    topicConnection.close();
                } catch (JMSException e) {}
            }
            
            
        }catch(Exception ex){
            ex.printStackTrace();
        }

    }
}

[2] When i execute this one, getting a null pointer exception on,
topicConnection = topicCF.createTopicConnection()

may be, i am missing something here. any idea?

thanks,
uday.
java.lang.NullPointerException
        at com.sun.uc.mels.connector.util.JMSSessionBean.postResults(JMSSessionBean.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
        at $Proxy67.postResults(Unknown Source)
        at com.sun.uc.mels.connector.ConnectorMDB.onMessage(ConnectorMDB.java:55)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
        at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
        at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
        at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:179)
        at $Proxy68.onMessage(Unknown Source)
        at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
        at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]
[Message sent by forum member 'udaysubbarayan' (udaysubbarayan)]

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