security - Spring JMS can not connect to WebSphere MQ - authentication fail -
i config websphere mq following command:
define qlocal(new.ql.rq) define qlocal(new.ql.rs) define listener('new.lsr') trptype(tcp) port(1420) control(qmgr) start listener('new.lsr') define channel('new.svr.conn') chltype(svrconn) set chlauth(*) type(blockuser) userlist('nobody','*mqadmin') set chlauth(system.admin.*) type(blockuser) userlist('nobody') set chlauth(new.svr.conn) type(addressmap) address(*) usersrc(channel) set chlauth(new.svr.conn) type(blockuser) userlist('nobody') refresh security
then can use mq explore connect using mqm
username , empty password.
however, when use spring jms, authentication fail. following section xml config.
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="classpath:main.properties" /> <!-- websphere mq connection factory --> <bean id="mqconnectionfactory" class="com.ibm.mq.jms.mqqueueconnectionfactory"> <property name="hostname"> <value>${queue_hostname}</value> </property> <property name="port"> <value>${queue_port}</value> </property> <property name="queuemanager"> <value>${queue_manager}</value> </property> <property name="transporttype"> <value>1</value> </property> </bean> <bean id="jmsconnectionfactory" class="org.springframework.jms.connection.usercredentialsconnectionfactoryadapter"> <property name="targetconnectionfactory" ref="mqconnectionfactory" /> <property name="username"> <value>${mq.username}</value> </property> <property name="password"> <value>${mq.password}</value> </property> </bean> <!-- jms destination resolver --> <bean id="jmsdestinationresolver" class="org.springframework.jms.support.destination.dynamicdestinationresolver"> </bean> <!-- jms queue template --> <bean id="jmsqueuetemplate" class="org.springframework.jms.core.jmstemplate102"> <property name="connectionfactory"> <ref bean="jmsconnectionfactory" /> </property> <property name="destinationresolver"> <ref bean="jmsdestinationresolver" /> </property> <property name="pubsubdomain"> <value>false</value> </property> <property name="receivetimeout"> <value>20000</value> </property> </bean> <bean id="messageservice" class="com.test.testspringjmsmq.messageservice" /> </beans>
the error messages:
caused by: com.ibm.msg.client.jms.detailedjmssecurityexception: jmswmq2013: security authentication not valid supplied queuemanager 'lorol' connection mode 'client' , host name 'xx.xx.xx.xx'. please check if supplied username , password correct on queuemanager connecting @ com.ibm.msg.client.wmq.common.internal.reason.reasontoexception(reason.java:531) @ com.ibm.msg.client.wmq.common.internal.reason.createexception(reason.java:219) @ com.ibm.msg.client.wmq.internal.wmqconnection.<init>(wmqconnection.java:410) @ com.ibm.msg.client.wmq.factories.wmqconnectionfactory.createv7providerconnection(wmqconnectionfactory.java:7855) @ com.ibm.msg.client.wmq.factories.wmqconnectionfactory.createproviderconnection(wmqconnectionfactory.java:7331) @ com.ibm.msg.client.jms.admin.jmsconnectionfactoryimpl.createconnection(jmsconnectionfactoryimpl.java:276) @ com.ibm.mq.jms.mqconnectionfactory.createcommonconnection(mqconnectionfactory.java:6055) @ com.ibm.mq.jms.mqtopicconnectionfactory.createtopicconnection(mqtopicconnectionfactory.java:114) @ com.ibm.mq.jms.mqtopicconnectionfactory.createconnection(mqtopicconnectionfactory.java:197) @ org.springframework.jms.connection.singleconnectionfactory.docreateconnection(singleconnectionfactory.java:343) @ org.springframework.jms.connection.singleconnectionfactory.initconnection(singleconnectionfactory.java:290) @ org.springframework.jms.connection.singleconnectionfactory.createconnection(singleconnectionfactory.java:227) @ org.springframework.jms.support.jmsaccessor.createconnection(jmsaccessor.java:184) @ org.springframework.jms.core.jmstemplate.execute(jmstemplate.java:461) ... 25 more caused by: com.ibm.mq.mqexception: jmscmq0001: websphere mq call failed compcode '2' ('mqcc_failed') reason '2035' ('mqrc_not_authorized'). @ com.ibm.msg.client.wmq.common.internal.reason.createexception(reason.java:206) ... 37 more
finally, not use spring jms implement connection between java , websphere mq.
i directly use simple jms implement it, , think configuration more easy spring jms.
the following section sample code simple jms.
try { mqqueueconnectionfactory cf = new mqqueueconnectionfactory(); // config cf.sethostname("localhost"); cf.setport(1414); cf.settransporttype(jmsc.mqjms_tp_client_mq_tcpip); cf.setqueuemanager("qm_thinkpad"); cf.setchannel("system.def.svrconn"); mqqueueconnection connection = (mqqueueconnection) cf.createqueueconnection(); mqqueuesession session = (mqqueuesession) connection.createqueuesession(false, session.auto_acknowledge); mqqueue queue = (mqqueue) session.createqueue("queue:///q1"); mqqueuesender sender = (mqqueuesender) session.createsender(queue); mqqueuereceiver receiver = (mqqueuereceiver) session.createreceiver(queue); long uniquenumber = system.currenttimemillis() % 1000; jmstextmessage message = (jmstextmessage) session.createtextmessage("simpleptp "+ uniquenumber); // start connection connection.start(); sender.send(message); system.out.println("sent message:\\n" + message); jmsmessage receivedmessage = (jmsmessage) receiver.receive(10000); system.out.println("\\nreceived message:\\n" + receivedmessage); sender.close(); receiver.close(); session.close(); connection.close(); system.out.println("\\nsuccess\\n"); } catch (jmsexception jmsex) { system.out.println(jmsex); system.out.println("\\nfailure\\n"); } catch (exception ex) { system.out.println(ex); system.out.println("\\nfailure\\n"); } }
Comments
Post a Comment