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

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3866665#3866665

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3866665


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to