Search code examples
javatomcatjmsibm-mqjndi

Tomcat 7 + JNDI Resource + IBM WebSphere MQ


My mission is to connect Tomcat 7 to remote IBM MQ. I try create JNDI Resource in server.xml file but it doesn't work. I used example from.

Addinatinaly i added in this example username and password. But there is error when i call JNDI resource from java code.

<Resource
      name="jms/MyQCF"
      auth="Container"
      type="com.ibm.mq.jms.MQQueueConnectionFactory"
      factory="com.ibm.mq.jms.MQQueueConnectionFactoryFactory"
      description="JMS Queue Connection Factory for sending messages"
      HOST="<mymqserver>"
      PORT="1414"
      CHAN="<mychannel>"
      TRAN="1"
      QMGR="<myqueuemanager>"/>
   <Resource
      name="jms/MyQ"
      auth="Container"
      type="com.ibm.mq.jms.MQQueue"
      factory="com.ibm.mq.jms.MQQueueFactory"
      description="JMS Queue for receiving messages from Dialog"
      QU="<myqueue>"/>

I've downloaded all required *.jars from [IBM sphere]/lib/java to Tomcat lib folder. Help me please, mb i'm doing somethink wrong. Maybe i need some IBM Client, but i don't know what is it.

Edit: The error stacktrace

javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceEnvFactory.getObjectInstan‌​ce(ResourceEnvFactor‌​y.java:117) 
at javax.naming.spi.NamingManager.getObjectInstance(NamingManag‌​er.java:321)

VERSION OF IBM MQ LIBS IS:

Implementation-Version: 7.0.1.8 - k701-108-120201

My current Resource in server.xml is:

<Resource
  name="jms/MyQCF"
  auth="Container"
  type="org.springframework.jms.connection.CachingConnectionFactory"
  factory="com.ibm.mq.jms.MQQueueConnectionFactoryFactory"
  description="JMS Queue Connection Factory for sending messages"
  HOST="192.168.204.73"
  PORT="1415"
  username="***"
  password="***"
  CHAN="JAVA.CHANNEL"
  TRAN="1"
  QMGR="U.SEND"/>

<Resource
  name="jms/MyQ"
  auth="Container"
  type="com.ibm.mq.jms.MQQueue"
  factory="com.ibm.mq.jms.MQQueueFactory"
  description="JMS Queue for receiving messages from Dialog"
  QU="U.RECEIVE"/>

My java code:

System.out.println("servlet page*****************");

    Context ctx = null;
    try {
        ctx = (Context) new InitialContext().lookup("java:comp/env");
        System.out.println("ctx: " + ctx);
    } catch (NamingException e) {
        e.printStackTrace();
    }
    QueueConnectionFactory qcf = null;
    try {
        qcf = (QueueConnectionFactory) ctx.lookup("jms/MyQCF");
        System.out.println("qcf: " + qcf);
    } catch (NamingException e) {
        e.printStackTrace();
    }

My stacktrace:

servlet page*****************

ctx: org.apache.naming.NamingContext@463b1a3e

javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    at kz.lalafa.MyServlet.doPost(MyServlet.java:45)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

My Tomcat lib folder contains:

annotations-api.jar            
fscontext.jar
catalina-ant.jar               
geronimo-j2ee-management_1.1_spec-1.0.1.jar
catalina-ha.jar                
geronimo-jms_1.1_spec-1.1.1.jar
catalina.jar                   
jasper-el.jar
catalina-tribes.jar            
jasper.jar
CL3Export.jar                  
jms.jar
CL3Nonexport.jar               
jndi.jar
com.ibm.mq.commonservices.jar  
jsp-api.jar
com.ibm.mq.defaultconfig.jar   
jta.jar
com.ibm.mqetclient.jar         
ldap.jar
com.ibm.mq.headers.jar         
providerutil.jar
com.ibm.mq.jar                 
rmm.jar
com.ibm.mq.jmqi.jar            
servlet-api.jar
com.ibm.mqjms.jar              
tomcat-api.jar
com.ibm.mq.jms.Nojndi.jar      
tomcat-coyote.jar
com.ibm.mq.pcf.jar             
tomcat-dbcp.jar
com.ibm.mq.postcard.jar        
tomcat-i18n-es.jar
com.ibm.mq.soap.jar            
tomcat-i18n-fr.jar
com.ibm.mq.tools.ras.jar       
tomcat-i18n-ja.jar
connector.jar                  
tomcat-jdbc.jar
dhbcore.jar                    
tomcat-util.jar
ecj-4.2.2.jar                  
wmq.jmsra.rar
el-api.jar

My web.xml:

<?xml version='1.0' encoding='utf-8'?>
<web-app version="2.4"
     xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<resource-env-ref>
    <resource-env-ref-name>jms/MyQCF</resource-env-ref-name>
    <resource-env-ref-type>javax.jms.QueueConnectionFactory</resource-env-ref-type>
</resource-env-ref>
<resource-env-ref>
    <resource-env-ref-name>jms/MyQ</resource-env-ref-name>
    <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
</web-app>

Solution

  • I just decided to use Spring Boot for this - https://github.com/lzp4ever/IBM_WebSphere_MQ_Spring_Boot_JMS.

    But i got new problem. My new problem at this link: multiple jms connection factory