Announcement Announcement Module
Collapse
No announcement yet.
JmsOutboundGateway getting a javax.jms.IllegalStateException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JmsOutboundGateway getting a javax.jms.IllegalStateException

    I am hooking JmsOutboundGateway to WebSphere MQ 7 and I hit a problem when I try to send through the gateway. First off... here is my configuration:

    Code:
    <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory">
          <bean class="com.ibm.mq.jms.MQConnectionFactory">
            <property name="queueManager" value="XXX" />
            <property name="hostName" value="XXX" />
            <property name="port" value="XXX" />
            <property name="channel" value="XXX" />
            <property name="SSLCipherSuite" value="XXX" />
            <property name="transportType" value="1" />
          </bean>
        </property>
        <property name="sessionCacheSize" value="10" />
        <property name="cacheProducers" value="false" />
    </bean>
    
    <si:channel id="requestChannel" />
    <si:channel id="replyChannel" />
    <si:gateway id="myGateway" service-interface="xxx.MyInterface" default-request-channel="requestChannel"
        default-reply-channel="replyChannel" />
    <si-jms:outbound-gateway request-destination="myQueue" request-channel="requestChannel" reply-channel="replyChannel" />
    When I try to send to myGateway, I get the following exception:
    Code:
    2011-03-31 07:12:03,843 [http-8080-1] WARN  org.springframework.integration.gateway.GatewayProxyFactoryBean$MethodInvocationGateway org.springframework.integration.gateway.MessagingGatewaySupport doSendAndReceive - failure occurred in gateway sendAndReceive
    org.springframework.integration.MessageHandlingException: javax.jms.IllegalStateException: This SingleConnectionFactory does not hold a QueueConnection but rather: Shared JMS Connection: com.ibm.mq.jms.MQConnection@1508f31
    	at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:348)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:98)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:110)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:44)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
    	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
    	at org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318)
    	at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239)
    	at org.springframework.integration.core.MessagingTemplate.convertSendAndReceive(MessagingTemplate.java:274)
    	at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:224)
    	at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:203)
    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:300)
    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:269)
    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:260)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy10.ping(Unknown Source)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    	at java.lang.Thread.run(Thread.java:595)
    Caused by: javax.jms.IllegalStateException: This SingleConnectionFactory does not hold a QueueConnection but rather: Shared JMS Connection: com.ibm.mq.jms.MQConnection@1508f31
    	at org.springframework.jms.connection.SingleConnectionFactory.createQueueConnection(SingleConnectionFactory.java:243)
    	at org.springframework.integration.jms.JmsOutboundGateway.createConnection(JmsOutboundGateway.java:515)
    	at org.springframework.integration.jms.JmsOutboundGateway.sendAndReceive(JmsOutboundGateway.java:353)
    	at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:333)
    	... 36 more
    Looking at the code for JmsOutboundGateway I see:
    Code:
    protected Connection createConnection() throws JMSException {
    	ConnectionFactory cf = this.connectionFactory;
    	if (!this.pubSubDomain && cf instanceof QueueConnectionFactory) {
    		return ((QueueConnectionFactory) cf).createQueueConnection();
    	}
    	return cf.createConnection();
    }
    As you can see in my config, I am hooking up a CachingConnectionFactory which extends from SingleConnectionFactory which of course implements QueueConnectionFactory. The underlying MQConnectionFactory is not a QueueConnectionFactory and therefore doesn't return QueueConnections... which is ultimately what seems to be causing the exception.

    So the questions are:
    • Am I being stupid?
    • Do I really need to hook up a separate connectionFactory for Queues vs Topics?
    • Anybody else using WebSphere MQ with CachingConnectionFactory?

    I should probably add: I am using spring-framework 3.0.5.RELEASE and spring-integration 2.0.3.RELEASE.

  • #2
    I ended up working around this issue by writing a class that wraps CachingConnectionFactory and omits the QueueConnection and TopicConnection interfaces.

    Code:
    public class WebSphereMqCachingConnectionFactory implements ConnectionFactory, ExceptionListener, InitializingBean,
            DisposableBean {
        private final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
    
        public void setTargetConnectionFactory(final ConnectionFactory targetConnectionFactory) {
            cachingConnectionFactory.setTargetConnectionFactory(targetConnectionFactory);
        }
    
        public ConnectionFactory getTargetConnectionFactory() {
            return cachingConnectionFactory.getTargetConnectionFactory();
        }
    
        public void setClientId(final String clientId) {
            cachingConnectionFactory.setClientId(clientId);
        }
    
        public void setExceptionListener(final ExceptionListener exceptionListener) {
            cachingConnectionFactory.setExceptionListener(exceptionListener);
        }
    
        public void setReconnectOnException(final boolean reconnectOnException) {
            cachingConnectionFactory.setReconnectOnException(reconnectOnException);
        }
    
        public void setSessionCacheSize(final int sessionCacheSize) {
            cachingConnectionFactory.setSessionCacheSize(sessionCacheSize);
        }
    
        public int getSessionCacheSize() {
            return cachingConnectionFactory.getSessionCacheSize();
        }
    
        public void setCacheProducers(final boolean cacheProducers) {
            cachingConnectionFactory.setCacheProducers(cacheProducers);
        }
    
        public boolean isCacheProducers() {
            return cachingConnectionFactory.isCacheProducers();
        }
    
        public void setCacheConsumers(final boolean cacheConsumers) {
            cachingConnectionFactory.setCacheConsumers(cacheConsumers);
        }
    
        public boolean isCacheConsumers() {
            return cachingConnectionFactory.isCacheConsumers();
        }
    
        public void onException(final JMSException ex) {
            cachingConnectionFactory.onException(ex);
        }
    
        public void afterPropertiesSet() throws Exception {
            cachingConnectionFactory.afterPropertiesSet();
        }
    
        public void destroy() throws Exception {
            cachingConnectionFactory.destroy();
        }
    
        public Connection createConnection() throws JMSException {
            return cachingConnectionFactory.createConnection();
        }
    
        public Connection createConnection(final String username, final String password) throws JMSException {
            return cachingConnectionFactory.createConnection(username, password);
        }
    
    }
    This works though I would still like to hear from someone from the Spring Integration team about the approach... doesn't seem like this should be necessary.

    Comment


    • #3
      Hi!

      I found the same problem accept for another EMS implementation (Tibco EMS).
      But the problem is the same.
      Tried the same wrapper-implementation and that works fine.

      No reply from the Spring Integration team? Looked at the new Spring Integration samles (http://git.springsource.org/spring-integration/samples/) but didn't found any matching configuration.

      I'm using Spring 3.1.0.M1 and Spring Integration 2.0.4.RELEASE.

      Comment


      • #4
        Sorry about earlier no-replies, got overlooked somehow

        Could you please post a stack trace and sample configuration. The stack trace from before is a bit outdated.
        Also, although you seem to have no issues running 2.0.4 with Spring 3.1, i just wanted to point out that 2.0.4 and 2.0.5 branches depend on Spring 3.0.5 and SI 2.1 will depend on Spring 3.1

        Comment


        • #5
          Hi!

          Below is my configuration that didn't work. Sends it to multiple posts because of character limitation.

          1) connectionFactory:
          <bean id="connectionFactory" class="org.springframework.jms.connection.CachingC onnectionFactory">
          <property name="targetConnectionFactory">
          <bean class="com.tibco.tibjms.TibjmsConnectionFactory">
          <property name="serverUrl" value="${ems.serverUrl}" />
          <property name="userName" value="${ems.userId}"/>
          <property name="userPassword" value="${ems.password}"/>
          </bean>
          </property>
          </bean>

          Comment


          • #6
            2) Chains:
            <int:chain input-channel="buildingQueryRequestChannel">
            ...
            <int:gateway request-channel="origoBuildingQueryRequestChannel" />
            ...
            </int:chain>

            <int:chain input-channel="origoBuildingQueryRequestChannel">
            ...
            <jms:outbound-gateway request-destination="jmsOrigoService" />
            ...
            </int:chain>

            Comment


            • #7
              Stack trace if possible?

              Comment


              • #8
                3) To deploy and start the application works just fine (jboss 6)

                4) But when running a test i crashes with the following output/trace:
                15:39:12,709 INFO [org.jboss.bootstrap.impl.base.server.AbstractServe r] JBossAS [6.0.0.Final "Neo"] Started in 16s:906ms
                15:40:30,551 WARN [org.springframework.context.support.SimpleThreadSc ope] SimpleThreadScope does not support descruction callbacks. Consider using a RequestScope in a Web environment.
                15:40:30,899 WARN [org.springframework.integration.gateway.GatewayPro xyFactoryBean$MethodInvocationGateway] failure occurred in gateway sendAndReceive: org.springframework.integration.MessageHandlingExc eption: javax.jms.IllegalStateException: This SingleConnectionFactory does not hold a QueueConnection but rather: Shared JMS Connection: Connection[ClientId=null Connected=<url>:7222, URL=<url>:7222,<url>:7224]
                at org.springframework.integration.jms.JmsOutboundGat eway.handleRequestMessage(JmsOutboundGateway.java: 358) [:]
                at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:98) [:]
                at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:78) [:]
                at org.springframework.integration.handler.MessageHan dlerChain$1.send(MessageHandlerChain.java:154) [:]
                at org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288) [:]
                at org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149) [:]
                ...
                ...
                at org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288) [:]
                at org.springframework.integration.core.MessagingTemp late.doSendAndReceive(MessagingTemplate.java:318) [:]
                at org.springframework.integration.core.MessagingTemp late.sendAndReceive(MessagingTemplate.java:239) [:]
                at org.springframework.integration.gateway.MessagingG atewaySupport.doSendAndReceive(MessagingGatewaySup port.java:233) [:]
                at org.springframework.integration.gateway.MessagingG atewaySupport.sendAndReceiveMessage(MessagingGatew aySupport.java:207) [:]
                at org.springframework.integration.jms.ChannelPublish ingJmsMessageListener$GatewayDelegate.sendAndRecei veMessage(ChannelPublishingJmsMessageListener.java :420) [:]
                at org.springframework.integration.jms.ChannelPublish ingJmsMessageListener.onMessage(ChannelPublishingJ msMessageListener.java:281) [:]
                at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doInvokeListener(AbstractMessageLi stenerContainer.java:535) [:3.1.0.M1]
                at org.springframework.jms.listener.AbstractMessageLi stenerContainer.invokeListener(AbstractMessageList enerContainer.java:495) [:3.1.0.M1]
                at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doExecuteListener(AbstractMessageL istenerContainer.java:467) [:3.1.0.M1]
                at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.doReceiveAndExecute(Abstrac tPollingMessageListenerContainer.java:325) [:3.1.0.M1]
                at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.receiveAndExecute(AbstractP ollingMessageListenerContainer.java:263) [:3.1.0.M1]
                at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.invokeL istener(DefaultMessageListenerContainer.java:1058) [:3.1.0.M1]
                at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.execute OngoingLoop(DefaultMessageListenerContainer.java:1 050) [:3.1.0.M1]
                at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.run(Def aultMessageListenerContainer.java:947) [:3.1.0.M1]
                at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
                Caused by: javax.jms.IllegalStateException: This SingleConnectionFactory does not hold a QueueConnection but rather: Shared JMS Connection: Connection[ClientId=null Connected=<url>:7222, URL=<url>:7222,<url>:7224]
                at org.springframework.jms.connection.SingleConnectio nFactory.createQueueConnection(SingleConnectionFac tory.java:243) [:3.1.0.M1]
                at org.springframework.integration.jms.JmsOutboundGat eway.createConnection(JmsOutboundGateway.java:525) [:]
                at org.springframework.integration.jms.JmsOutboundGat eway.sendAndReceive(JmsOutboundGateway.java:363) [:]
                at org.springframework.integration.jms.JmsOutboundGat eway.handleRequestMessage(JmsOutboundGateway.java: 335) [:]
                ... 90 more

                Comment


                • #9
                  5) The problem seem to appear when the 'connection' should be casted to a QueueConnection?!?!

                  6) And the temporary solution is to wrap 'org.springframework.jms.connection.CachingConnect ionFactory' to avoid the cast (as described earlier), but that doesn't seem right...

                  Come back to me if you want some more information.

                  /Daniel.

                  Comment

                  Working...
                  X