java - JMS can not connect to websphere mq -


this code of class java


package com.ibm.point_a_point;  import javax.jms.connection; import javax.jms.destination; import javax.jms.jmsexception; import javax.jms.message; import javax.jms.messageconsumer; import javax.jms.messageproducer; import javax.jms.session; import javax.jms.textmessage;  import com.ibm.msg.client.jms.jmsconnectionfactory; import com.ibm.msg.client.jms.jmsfactoryfactory; import com.ibm.msg.client.wmq.wmqconstants;  /**  * minimal , simple application point-to-point messaging.  *   * application makes use of fixed literals, customisations require re-compilation of  * source file. application assumes named queue empty prior run.  *   * notes:  *   * api type: jms api (v1.1, unified domain)  *   * messaging domain: point-to-point  *   * provider type: websphere mq  *   * connection mode: client connection  *   * jndi in use: no  *   */ public class simpleptp {    // system exit status value (assume unset value 1)   private static int status = 1;    /**    * main method    *     * @param args    */   public static void main(string[] args) {      // variables     connection connection = null;     session session = null;     destination destination = null;     messageproducer producer = null;     messageconsumer consumer = null;      try {       // create connection factory       jmsfactoryfactory ff = jmsfactoryfactory.getinstance(wmqconstants.wmq_provider);       jmsconnectionfactory cf = ff.createconnectionfactory();        // set properties       cf.setstringproperty(wmqconstants.wmq_host_name, "localhost");       cf.setintproperty(wmqconstants.wmq_port, 1414);       cf.setstringproperty(wmqconstants.wmq_channel, "system.def.svrconn");       cf.setintproperty(wmqconstants.wmq_connection_mode, wmqconstants.wmq_cm_client);       cf.setstringproperty(wmqconstants.wmq_queue_manager, "qm1");       cf.setstringproperty(wmqconstants.wmq_applicationname, "simpleptp (jms)");        // create jms objects       connection = cf.createconnection();       session = connection.createsession(false, session.auto_acknowledge);       destination = session.createqueue("queue:///q1");       producer = session.createproducer(destination);       consumer = session.createconsumer(destination);        long uniquenumber = system.currenttimemillis() % 1000;       textmessage message = session.createtextmessage("simpleptp: lucky number today "                                                       + uniquenumber);        // start connection       connection.start();        // and, send message       producer.send(message);       system.out.println("sent message:\n" + message);        message receivedmessage = consumer.receive(15000); // in ms or 15 seconds       system.out.println("\nreceived message:\n" + receivedmessage);        recordsuccess();     }     catch (jmsexception jmsex) {       recordfailure(jmsex);     }     {       if (producer != null) {         try {           producer.close();         }         catch (jmsexception jmsex) {           system.out.println("producer not closed.");           recordfailure(jmsex);         }       }       if (consumer != null) {         try {           consumer.close();         }         catch (jmsexception jmsex) {           system.out.println("consumer not closed.");           recordfailure(jmsex);         }       }        if (session != null) {         try {           session.close();         }         catch (jmsexception jmsex) {           system.out.println("session not closed.");           recordfailure(jmsex);         }       }        if (connection != null) {         try {           connection.close();         }         catch (jmsexception jmsex) {           system.out.println("connection not closed.");           recordfailure(jmsex);         }       }     }     system.exit(status);     return;   } // end main()    /**    * process jmsexception , associated inner exceptions.    *     * @param jmsex    */   private static void processjmsexception(jmsexception jmsex) {     system.out.println(jmsex);     throwable innerexception = jmsex.getlinkedexception();     if (innerexception != null) {       system.out.println("inner exception(s):");     }     while (innerexception != null) {       system.out.println(innerexception);       innerexception = innerexception.getcause();     }     return;   }    /**    * record run successful.    */   private static void recordsuccess() {     system.out.println("success");     status = 0;     return;   }    /**    * record run failure.    *     * @param ex    */   private static void recordfailure(exception ex) {     if (ex != null) {       if (ex instanceof jmsexception) {         processjmsexception((jmsexception) ex);       }       else {         system.out.println(ex);       }     }     system.out.println("failure");     status = -1;     return;   }  } 

i have error(exception) com.ibm.msg.client.jms.detailedjmssecurityexception: jmswmq2013: authentication security provided queue manager 'qm1' connection mode 'client' , hostname 'localhost (1414) 'was invalid. check if user name , password provided correct in waiting queue manager connect. websphere mq call failed completion code '2' ('mqcc_failed'); pattern '2035' ('mqrc_not_authorized').

cf.setstringproperty(wmqconstants.wmq_channel, "system.def.svrconn"); 

you should not using system channel. ask mqadmin create 1 application.

connection = cf.createconnection(); 

change to:

connection = cf.createconnection("myuser","mypswd"); 

ask mqadmin if authentication targeted either local os or ldap , use appropriate userid , password.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -