2 Replies Latest reply on Sep 10, 2007 12:58 AM by phansaaj

    Unable to get Connection to send a message on the testQueue

    phansaaj

      Hi,

      I am using JBOSS AS 4.2 GA and JBoss Messaging 1.3 GA.I have created an CRUD application with Seam and database is MySQL.From the entity bean created I am trying to send a message to testQueue on the server.The code from the Stateless session bean messaging example is moved to a utility java class.

      So I am getting teh following exception when i try to send te message to teh queue looks like its able to create a connection but fails on connection.start
      :08,042 INFO [STDOUT] Hibernate: insert into dummy.ticket_master (faultid, faulttype, faultdesc, faultpriority, faultlocation, deviceid, engineer, ticketpriority, ticketstatus, ticketresolution, approvalcomments, ticketid) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
      20:22:08,042 INFO [STDOUT] The Quename is /queue/testQueue
      20:22:08,042 INFO [STDOUT] Inside Message Utility:send QueueName :/queue/testQueue
      20:22:08,042 INFO [STDOUT] Inside Message Utility:send
      20:22:08,042 INFO [STDOUT] Inside Message Utility:send: Before getting connection
      20:22:08,042 INFO [STDOUT] Inside Message Utility:send.getConnection:cfJBossConnectionFactory->ConnectionFactoryDelegate[1, SID=0]
      20:22:08,042 INFO [STDOUT] Inside Message Utility:send.getConnection:icjavax.naming.InitialContext@e6728c
      20:22:08,042 INFO [STDOUT] Inside Message Utility:send.getConnection:create connection
      20:22:08,058 INFO [STDOUT] Inside Message Utility:send.getConnection:before connection start:conn isJBossConnection->ConnectionDelegate[20254712, ID=4, SID=0]
      20:22:08,074 ERROR [STDERR] java.lang.NullPointerException
      20:22:08,074 ERROR [STDERR] at org.jboss.jms.client.container.FailoverValveInterceptor.invoke(FailoverValveInterceptor.java:86)
      20:22:08,074 ERROR [STDERR] at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
      20:22:08,074 ERROR [STDERR] at org.jboss.jms.client.delegate.ClientConnectionDelegate$start_N8025343665958530775.invokeNext(ClientConnectionDelegate$start_N8025343665958530775.java)
      20:22:08,074 ERROR [STDERR] at org.jboss.jms.client.container.ClosedInterceptor.invoke(ClosedInterceptor.java:170)
      20:22:08,074 ERROR [STDERR] at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:105)
      20:22:08,074 ERROR [STDERR] at org.jboss.jms.client.delegate.ClientConnectionDelegate$start_N8025343665958530775.invokeNext(ClientConnectionDelegate$start_N8025343665958530775.java)
      20:22:08,074 ERROR [STDERR] at org.jboss.jms.client.delegate.ClientConnectionDelegate.start(ClientConnectionDelegate.java)
      20:22:08,074 ERROR [STDERR] at org.jboss.jms.client.JBossConnection.start(JBossConnection.java:121)
      20:22:08,074 ERROR [STDERR] at com.dummy.util.MessageUtility.getConnection(MessageUtility.java:178)
      20:22:08,074 ERROR [STDERR] at com.dummy.util.MessageUtility.send(MessageUtility.java:73)
      20:22:08,074 ERROR [STDERR] at com.dummy.entity.TicketMasterHome.sendMessage(TicketMasterHome.java:69)
      20:22:08,074 ERROR [STDERR] at com.dummy.entity.TicketMasterHome.persist(TicketMasterHome.java:47)
      20:22:08,074 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      20:22:08,074 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      20:22:08,074 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      20:22:08,074 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:43)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.util.Work.workInTransaction(Work.java:39)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:151)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:87)
      20:22:08,074 ERROR [STDERR] at com.dummy.entity.TicketMasterHome_$$_javassist_30.persist(TicketMasterHome_$$_javassist_30.java)
      20:22:08,074 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      20:22:08,074 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      20:22:08,074 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      20:22:08,074 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      20:22:08,074 ERROR [STDERR] at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:325)
      20:22:08,074 ERROR [STDERR] at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:338)
      20:22:08,074 ERROR [STDERR] at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
      20:22:08,074 ERROR [STDERR] at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
      20:22:08,074 ERROR [STDERR] at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
      20:22:08,074 ERROR [STDERR] at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
      20:22:08,074 ERROR [STDERR] at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
      20:22:08,074 ERROR [STDERR] at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
      20:22:08,074 ERROR [STDERR] at javax.faces.component.UICommand.broadcast(UICommand.java:383)
      20:22:08,074 ERROR [STDERR] at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
      20:22:08,074 ERROR [STDERR] at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:158)
      20:22:08,074 ERROR [STDERR] at org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:346)
      20:22:08,074 ERROR [STDERR] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
      20:22:08,074 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      20:22:08,074 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
      20:22:08,074 ERROR [STDERR] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:63)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:87)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:63)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      20:22:08,074 ERROR [STDERR] at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
      20:22:08,074 ERROR [STDERR] at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:40)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      20:22:08,074 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:140)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      20:22:08,074 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      20:22:08,074 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
      20:22:08,074 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      20:22:08,074 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      20:22:08,074 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      20:22:08,074 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      20:22:08,074 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      20:22:08,074 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      20:22:08,074 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
      20:22:08,074 INFO [STDOUT] Exception in persisting and send message java.lang.NullPointerException
      20:22:10,932 INFO [STDOUT] Hibernate: select ticketmast0_.ticketid as ticketid19_, ticketmast0_.faultid as faultid19_, ticketmast0_.faulttype as faulttype19_, ticketmast0_.faultdesc as faultdesc19_, ticketmast0_.faultpriority as faultpri5_19_, ticketmast0_.faultlocation as faultloc6_19_, ticketmast0_.deviceid as deviceid19_, ticketmast0_.engineer as engineer19_, ticketmast0_.ticketpriority as ticketpr9_19_, ticketmast0_.ticketstatus as tickets10_19_, ticketmast0_.ticketresolution as ticketr11_19_, ticketmast0_.approvalcomments as approva12_19_ from dummy.ticket_master ticketmast0_ limit ?
      20:22:11,338 INFO [STDOUT] Hibernate: select count(*) as col_0_0_ from dummy.ticket_master ticketmast0_



      The Code for the entity bean and teh helper class are as follows

      package com.dummy.entity;

      import javax.naming.InitialContext;

      import org.jboss.example.jms.common.ExampleSupport;
      import org.jboss.example.jms.queue.QueueExample;

      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityHome;

      import com.dummy.util.MessageUtility;

      @Name("ticketMasterHome")
      public class TicketMasterHome extends EntityHome {

      public void setTicketMasterTicketid(Integer id) {
      setId(id);
      }

      public Integer getTicketMasterTicketid() {
      return (Integer) getId();
      }

      @Override
      protected TicketMaster createInstance() {
      TicketMaster ticketMaster = new TicketMaster();
      return ticketMaster;
      }

      public void wire() {
      }

      public boolean isWired() {
      return true;
      }

      public TicketMaster getDefinedInstance() {
      return isIdDefined() ? getInstance() : null;
      }
      @Override
      public String persist(){
      String retValue="";
      try
      {
      retValue = super.persist();
      //QueueExample.main(null);
      sendMessage();
      }
      catch(Exception ex)
      {
      System.out.println("Exception in persisting and send message "+ex);
      }
      return retValue;
      }
      public void sendMessage() throws Exception{

      InitialContext ic = new InitialContext();
      MessageUtility bean = new MessageUtility();
      // StatelessSessionExampleHome home =
      // (StatelessSessionExampleHome)ic.lookup("ejb/StatelessSessionExample");
      //
      // StatelessSessionExample bean = home.create();
      //
      String queueName = "/queue/"+ ExampleSupport.DEFAULT_QUEUE_NAME;
      String text = "Hello!";
      System.out.println("The Quename is " + queueName);
      //bean.drain(queueName);
      bean.initiate();
      bean.send("Helloooo", queueName);
      System.out.println("The " + text + " message was successfully sent to the " + queueName + " queue");

      int num = bean.browse(queueName);

      System.out.println("Queue browse result: " + num);

      String result = bean.receive(queueName);
      System.out.println("Received " + result);

      }
      }




        • 1. Re: Unable to get Connection to send a message on the testQu
          phansaaj

          Also attached is the helper class

          package com.dummy.util;

          import java.util.ArrayList;
          import java.util.Enumeration;
          import javax.jms.Connection;
          import javax.jms.ConnectionFactory;
          import javax.jms.JMSException;
          import javax.jms.Message;
          import javax.jms.MessageConsumer;
          import javax.jms.MessageProducer;
          import javax.jms.Queue;
          import javax.jms.QueueBrowser;
          import javax.jms.Session;
          import javax.jms.TextMessage;
          import javax.naming.InitialContext;

          import org.jboss.example.jms.common.Util;

          public class MessageUtility {
          private ConnectionFactory cf = null;
          public void drain(String queueName) throws Exception
          {
          System.out.println("Inside Message Utility:drain");
          InitialContext ic = new InitialContext();
          Queue queue = (Queue)ic.lookup(queueName);
          ic.close();
          System.out.println("Message Utility: Found teh queue");
          Session session = null;
          Connection conn = null;

          try
          {
          conn = getConnection();
          session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageConsumer consumer = session.createConsumer(queue);
          System.out.println("Inside Message Utility:Created Consumer");
          Message m = null;
          do
          {
          m = consumer.receive(1L);
          }
          while(m != null);
          }
          finally
          {
          if (conn != null)
          {
          closeConnection(conn);
          }
          }
          }

          public void send(String txt, String queueName) throws Exception
          {
          InitialContext ic = new InitialContext();
          System.out.println("Inside Message Utility:send QueueName :"+ queueName);
          if (!Util.doesDestinationExist(queueName,ic))
          {
          System.out.println("Destination " + queueName + " does not exist, deploying it");
          Util.deployQueue(queueName,ic);

          }
          Queue queue = (Queue)ic.lookup(queueName);
          System.out.println("Inside Message Utility:send");
          ic.close();

          Session session = null;
          Connection conn = null;

          try
          {
          System.out.println("Inside Message Utility:send: Before getting connection");
          conn = getConnection();
          System.out.println("Inside Message Utility:send:After getting connection");
          session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
          System.out.println("Inside Message Utility:send:session" + session);
          MessageProducer producer = session.createProducer(queue);

          TextMessage tm = session.createTextMessage(txt);
          System.out.println("Inside Message Utility:send:producer is "+ producer);
          producer.send(tm);

          System.out.println("message " + txt + " sent to " + queueName);
          }
          finally
          {
          if (conn != null)
          {
          closeConnection(conn);
          }
          }
          }

          public int browse(String queueName) throws Exception
          {
          InitialContext ic = new InitialContext();
          Queue queue = (Queue)ic.lookup(queueName);
          ic.close();
          System.out.println("Inside Message Utility:browse");
          Session session = null;
          Connection conn = null;

          try
          {
          conn = getConnection();
          session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
          QueueBrowser browser = session.createBrowser(queue);

          ArrayList list = new ArrayList();
          for(Enumeration e = browser.getEnumeration(); e.hasMoreElements(); )
          {
          list.add(e.nextElement());
          }

          return list.size();
          }
          finally
          {
          if (conn != null)
          {
          closeConnection(conn);
          }
          }
          }

          public String receive(String queueName) throws Exception
          {
          InitialContext ic = new InitialContext();
          Queue queue = (Queue)ic.lookup(queueName);
          ic.close();
          System.out.println("Inside Message Utility:receive");
          Session session = null;
          Connection conn = null;

          try
          {
          conn = getConnection();
          session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

          MessageConsumer consumer = session.createConsumer(queue);

          System.out.println("blocking to receive message from queue " + queueName + " ...");
          TextMessage tm = (TextMessage)consumer.receive(5000);

          if (tm == null)
          {
          throw new Exception("No message!");
          }

          System.out.println("Message " + tm.getText() + " received");

          return tm.getText();
          }
          finally
          {
          if (conn != null)
          {
          closeConnection(conn);
          }
          }
          }

          public Connection getConnection() throws Exception
          {

          Connection connection = null;
          System.out.println("Inside Message Utility:send.getConnection:cf"+cf);
          try
          {
          InitialContext ic = new InitialContext();
          System.out.println("Inside Message Utility:send.getConnection:ic"+ic);
          //cf = (ConnectionFactory)ic.lookup("java:JmsXA");
          //cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
          cf = (ConnectionFactory)ic.lookup("java:/ConnectionFactory");
          System.out.println("Inside Message Utility:send.getConnection:create connection");
          connection = cf.createConnection();
          System.out.println("Inside Message Utility:send.getConnection:before connection start:conn is"+ connection);
          connection.start();
          ic.close();
          }
          catch(Exception e )
          {
          e.printStackTrace();
          if(connection != null)
          {
          closeConnection(connection);
          }
          System.out.println("Failed to get connection...exception is " + e);
          throw e;
          }

          return connection;
          }

          public void closeConnection(Connection con) throws Exception
          {
          try
          {
          con.close();
          }
          catch(JMSException jmse)
          {
          System.out.println("Could not close connection " + con +" exception was " + jmse);
          throw jmse;
          }
          }


          public void initiate()
          {
          try
          {
          InitialContext ic = new InitialContext();

          //cf = (ConnectionFactory)ic.lookup("java:/JmsXA");
          cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");

          ic.close();
          }
          catch(Exception e)
          {
          e.printStackTrace();

          }
          }


          }


          Please help in fixing this issue

          • 2. Re: Unable to get Connection to send a message on the testQu
            phansaaj

            Request help in figuring this out.I am unable to connect to a Messaging Queue a stateless session bean example.

            Thanks & Regards,
            Ajeet Phansalkar