Announcement Announcement Module
Collapse
No announcement yet.
JmsTemplate connection closed error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JmsTemplate connection closed error

    Hi..

    I am new to spring technology. I am using jmstemplate to send a message to IBM MQ queue in my web application deployed on WAS 6

    When i send the first message it is working fine. But when i send a second message.. i am getting the following "connection closed" exception. I have copied the stack trace below. seems like a basic error. but not able to find where i messed it up.

    Appreciate your help on this.

    -------------------------------------------------
    Caused by: javax.jms.IllegalStateException: Connection closed
    at com.ibm.ejs.jms.JMSConnectionHandle.checkOpen(JMSC onnectionHandle.java:788)
    at com.ibm.ejs.jms.JMSQueueConnectionHandle.createQue ueSession(JMSQueueConnectionHandle.java:201)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.jms.connection.SingleConnectio nFactory$SharedConnectionInvocationHandler.invoke( SingleConnectionFactory.java:549)
    at $Proxy0.createQueueSession(Unknown Source)
    at org.springframework.jms.core.JmsTemplate102.create Session(JmsTemplate102.java:182)
    at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:462)
    ... 25 more

  • #2
    copied the code snippet:

    --------------------------------------

    Spring config:

    <bean id="sender" class="com.statestr.spring.simple.MessageSender">
    <property name="jmsTemplate" ref="TestJMSTemplate2"/>
    </bean>

    <bean id="TestJMSTemplate2" class="org.springframework.jms.core.JmsTemplate102 ">
    <property name="connectionFactory" ref="jmsQueueConnectionFactory2" />
    <property name="defaultDestinationName" value="jms/TEST/mqQueue"/>
    <property name="destinationResolver" ref="jmsDestinationResolver2"/>
    <property name="pubSubDomain">
    <value>false</value>
    </property>
    </bean>

    <bean id="jmsQueueConnectionFactory2"
    class="org.springframework.jms.connection.SingleCo nnectionFactory102">
    <property name="targetConnectionFactory">
    <ref bean="internalJmsQueueConnectionFactory2"/>
    </property>
    <property name="pubSubDomain">
    <value>false</value>
    </property>
    </bean>

    <bean id="internalJmsQueueConnectionFactory2"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiTemplate">
    <ref bean="MQJndiTemplate"/>
    </property>
    <property name="jndiName">
    <value>jms/mqPrototypeQCF</value>
    </property>
    </bean>

    <bean id="jmsDestinationResolver2"
    class="org.springframework.jms.support.destination .JndiDestinationResolver">
    <property name="jndiTemplate">
    <ref bean="MQJndiTemplate"/>
    </property>
    <property name="cache">
    <value>true</value>
    </property>
    </bean>

    <bean id="MQJndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
    <props>
    <prop key="java.naming.factory.initial">com.ibm.webspher e.naming.WsnInitialContextFactory</prop>
    <prop key="java.naming.provider.url"><URL></prop>
    </props>
    </property>
    </bean>

    --------------------------------------
    MessageSender Code :

    try{
    this.jmsTemplate.send(new MessageCreator() {
    public Message createMessage(Session arg0) throws JMSException {
    return arg0.createTextMessage("hello " + System.currentTimeMillis());
    }
    });
    }catch (JmsException je){
    je.printStackTrace();
    }

    --------------------------------------
    web.xml
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    <servlet>
    <servlet-name>SendMessageServlet</servlet-name>
    <servlet-class>com.statestr.spring.simple.servlet.SendMessa geServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>SendMessageServlet</servlet-name>
    <url-pattern>/sendmsg</url-pattern>
    </servlet-mapping>

    --------------------------------------
    SenderMessageServlet service method:

    org.springframework.context.ApplicationContext context =
    (org.springframework.context.ApplicationContext)We bApplicationContextUtils.
    getWebApplicationContext(arg0.getSession(true).get ServletContext());
    MessageSender sender = (MessageSender)context.getBean("sender");
    sender.handle("hello");

    ------------------------------------

    Comment


    • #3
      You probably need to set the reconnect mode on your connection factory...

      Code:
      <property name="reconnectOnException"  value="true"></property>

      Comment


      • #4
        No luck.. getting the following error on inserting the suggested property.
        ---------------------------------------------------------
        Caused by: javax.jms.IllegalStateException: Method setExceptionListener not permitted
        at com.ibm.ejs.jms.JMSCMUtils.methodNotPermittedExcep tion(JMSCMUtils.java:253)
        at com.ibm.ejs.jms.JMSConnectionHandle.checkRestricte dMethod(JMSConnectionHandle.java:805)
        at com.ibm.ejs.jms.JMSConnectionHandle.setExceptionLi stener(JMSConnectionHandle.java:323)
        at org.springframework.jms.connection.SingleConnectio nFactory.prepareConnection(SingleConnectionFactory .java:365)
        at org.springframework.jms.connection.SingleConnectio nFactory.initConnection(SingleConnectionFactory.ja va:291)
        at org.springframework.jms.connection.SingleConnectio nFactory.createConnection(SingleConnectionFactory. java:227)
        at org.springframework.jms.connection.SingleConnectio nFactory.createQueueConnection(SingleConnectionFac tory.java:242)
        at org.springframework.jms.core.JmsTemplate102.create Connection(JmsTemplate102.java:170)
        at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:461)
        ... 29 more

        Comment

        Working...
        X