0 Replies Latest reply on Feb 15, 2005 11:27 AM by fmarchioni fmarchioni

    Error closing connection from a JSP. Why ?

    fmarchioni fmarchioni Newbie

      Hi all,
      I'm trying to send a JMS message from a JSP page.
      I have taken a basic TopicSendClient example and compiled
      it under WEB-INF/classes directory so that I can access it
      from a JSP


      package test;
      
      import javax.jms.*;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class TopicSendClient
      {
       TopicConnection conn = null;
       TopicSession session = null;
       Topic topic = null;
      
       public void setupPubSub(String queue)
       throws JMSException, NamingException
       {
       InitialContext iniCtx = new InitialContext();
       Object tmp = iniCtx.lookup("java:/JmsXA");
       TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
       conn = tcf.createTopicConnection();
       topic = (Topic) iniCtx.lookup(queue);
       session = conn.createTopicSession(false,
       TopicSession.AUTO_ACKNOWLEDGE);
       conn.start();
       }
      
       public void sendAsync(String text, String queue)
       throws JMSException, NamingException
       {
       System.out.println("Begin sendAsync");
       // Setup the pub/sub connection, session
       setupPubSub(queue);
       // Send a text msg
       TopicPublisher send = session.createPublisher(topic);
       TextMessage tm = session.createTextMessage(text);
       send.publish(tm);
       System.out.println("sendAsync, sent text=" + tm.getText());
       send.close();
       System.out.println("End sendAsync");
      
       stop();
       }
      
       public void stop()
       throws JMSException
       {
      
       conn.stop();
       session.close();
       conn.close();
      
       }
      
      
      }



      The code is quite simple:

      <%
      
      
       test.TopicSendClient client = new test.TopicSendClient();
      
       client.sendAsync("A text msg","topic/testTopic");
      
      
      %>


      Unfortunately when the method conn.stop() is invoked JBoss issues this error:

      17:18:08,921 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
      javax.jms.IllegalStateException: This method is not applicatable in JMS resource adapter at org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.stop(JmsSessionF
      actoryImpl.java:238)
      at test.TopicSendClient.stop(Unknown Source)
      at test.TopicSendClient.sendAsync(Unknown Source)
      at org.apache.jsp.test_jsp._jspService(test_jsp.java:47)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper

      Why JBoss raises this error ? Shouldn't I close the connection from a JSP or what ???
      Thanks a lot in advance
      Francesco