title: Two simple IBM MQ client tests write to MQ queue - why does one work, but, NOT the other?
body: <p>I'm running two(2) client tests.</p>
  
  <p>Presumably they should both work.  But, one does not, and I do not know why.</p>
  
  <p><strong><em>(1) This one works...</em></strong></p>
  
  <pre><code>package aaa.bbb.ccc;
  
  import com.ibm.mq.MQEnvironment;
  import com.ibm.mq.MQQueueManager;
  import com.ibm.mq.MQQueue;
  import com.ibm.mq.MQMessage;
  import com.ibm.mq.MQPutMessageOptions;
  import com.ibm.mq.constants.CMQC;
  import com.ibm.mq.constants.MQConstants;
  
  public class MQCheck {
      public static void main(String args[]) {
      try {
          int openOptions = CMQC.MQOO_INQUIRE | CMQC.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT;
          MQEnvironment.hostname = "localhost";
          MQEnvironment.port = 1414;
          MQEnvironment.channel = "DEV.APP.SVRCONN";
          MQEnvironment.properties.put(CMQC.USER_ID_PROPERTY, "admin");
          MQEnvironment.properties.put(CMQC.PASSWORD_PROPERTY, "passw0rd");          
          MQEnvironment.properties.put(CMQC.TRANSPORT_PROPERTY, CMQC.TRANSPORT_MQSERIES);
          MQQueueManager qMgr;
          qMgr = new MQQueueManager("QM1");
          MQQueue destQueue = qMgr.accessQueue("mylocalqueue", openOptions);
          MQMessage hello_world = new MQMessage();
          hello_world.writeUTF("Blah...blah...bleah...test message no.1...!");
          MQPutMessageOptions pmo = new MQPutMessageOptions();
          destQueue.put(hello_world, pmo);
          destQueue.close();
          qMgr.disconnect();
          System.out.println("------------------------success...");            
      } catch (Exception e) {
          System.out.println("Exception: " + e);
          e.printStackTrace();
      }
      }
  }
  </code></pre>
  
  <p><strong><em>(2) This one does NOT work...</em></strong>  </p>
  
  <pre><code>package aaa.bbb.ccc;
  
  import com.ibm.mq.jms.MQQueueConnection;
  import com.ibm.mq.jms.MQQueueConnectionFactory;
  import com.ibm.mq.jms.MQSession;
  import com.ibm.msg.client.wmq.WMQConstants;
  import javax.jms.Connection;
  import javax.jms.JMSException;
  import javax.jms.MessageProducer;
  import javax.jms.Queue;
  import javax.jms.QueueSession;
  import javax.jms.Session;
  import javax.jms.TextMessage;
  
  public class MQCheck3 {
  
      public static void main(String args[]) {
  
      Connection qconn = null;
      QueueSession qsess = null;
      MQSession mqsess;
      Queue queue = null;
  
      try {
          MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
          connectionFactory.setHostName("localhost");
          connectionFactory.setChannel("DEV.APP.SVRCONN");//communications link
          connectionFactory.setPort(1414);
          connectionFactory.setQueueManager("QM1");
          connectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
          connectionFactory.setBooleanProperty(WMQConstants.CAPABILITY_USERNAME_PASSWORD, true);
          connectionFactory.setStringProperty(WMQConstants.USERID, "admin");
          connectionFactory.setStringProperty(WMQConstants.PASSWORD, "passw0rd");            
          qconn = (MQQueueConnection) connectionFactory.createConnection();
          qconn = connectionFactory.createQueueConnection();
          qconn.start();
          mqsess = (MQSession) qconn.createSession(false, Session.AUTO_ACKNOWLEDGE); //.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
          queue = mqsess.createQueue("mylocalqueue");
          TextMessage textMessage = mqsess.createTextMessage("Bleah...bleah...blech...test message no.2...!");
          MessageProducer mc = mqsess.createProducer(queue);
          mc.send(textMessage, 0, 0, 0);
          System.out.println("------------------------success...");  
      } catch (JMSException e) {
          System.out.println("Exception: " + e);
          e.printStackTrace();
      } finally {
          try {
          qsess.close();
          qconn.close();
          } catch (JMSException e) {
          System.err.print(e);
          }
      }
      }
  }
  </code></pre>
  
  <p>NOTE: 
  Running the code in (2) gets the following exception...</p>
  
  <pre><code>Exception: com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: The security authentication was not valid that was supplied for QueueManager 'QM1' with connection mode 'Client' and host name 'localhost(1414)'.
  Please check if the supplied username and password are correct on the QueueManager to which you are connecting.
  com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: The security authentication was not valid that was supplied for QueueManager 'QM1' with connection mode 'Client' and host name 'localhost(1414)'.
  Please check if the supplied username and password are correct on the QueueManager to which you are connecting.
      at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:514)
      at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:214)
      at com.ibm.msg.client.wmq.internal.WMQConnection.&lt;init&gt;(WMQConnection.java:408)
      at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:6398)
      at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:5740)
      at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl._createConnection(JmsConnectionFactoryImpl.java:293)
      at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:234)
      at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6016)
      at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:111)
      at aaa.bbb.ccc.MQCheck3.main(MQCheck3.java:35)
  Caused by: com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2035' ('MQRC_NOT_AUTHORIZED').
      at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:202)
      ... 8 more
  Exception in thread "main" java.lang.NullPointerException
      at aaa.bbb.ccc.MQCheck3.main(MQCheck3.java:48)
  </code></pre>
  
  <p><strong>*QUESTION: can anyone explain to me why the 2nd example does not work?:  *</strong> </p>
  
  <p>-Is there something that is incorrect and/or missing from the code that would enable it to work?</p>
  
  <p><strong><em>FYI - running MQ server from Docker image:</em></strong></p>
  
  <p>C:>docker exec mq dspmqver</p>
  
  <pre><code>C:\&gt;docker exec mq dspmqver
  Name:        IBM MQ
  Version:     9.0.3.0
  Level:       p903-L170517.DE
  BuildType:   IKAP - (Production)
  Platform:    IBM MQ for Linux (x86-64 platform)
  Mode:        64-bit
  O/S:         Linux 4.9.31-moby
  InstName:    Installation1
  InstDesc:
  Primary:     Yes
  InstPath:    /opt/mqm
  DataPath:    /var/mqm
  MaxCmdLevel: 903
  LicenseType: Developer
  
  C:\&gt;
  </code></pre>
  
  <p><strong><em>pom.xml</em></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;aaa.bbb.ccc&lt;/groupId&gt;
      &lt;artifactId&gt;mqcheck&lt;/artifactId&gt;
      &lt;version&gt;1&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;name&gt;mqcheck&lt;/name&gt;
      &lt;description&gt;mqcheck&lt;/description&gt;
  
      &lt;properties&gt;
      &lt;mq.version&gt;8.0.0.2&lt;/mq.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;   
      &lt;dependency&gt;
          &lt;groupId&gt;ibm.mq&lt;/groupId&gt;
          &lt;artifactId&gt;fscontext&lt;/artifactId&gt;
          &lt;version&gt;${mq.version}&lt;/version&gt;
      &lt;/dependency&gt;          
      &lt;dependency&gt;
          &lt;groupId&gt;ibm.mq&lt;/groupId&gt;
          &lt;artifactId&gt;jms&lt;/artifactId&gt;
          &lt;version&gt;${mq.version}&lt;/version&gt;
      &lt;/dependency&gt;        
      &lt;dependency&gt;
          &lt;groupId&gt;ibm.mq&lt;/groupId&gt;
          &lt;artifactId&gt;com.ibm.mq&lt;/artifactId&gt;
          &lt;version&gt;${mq.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;ibm.mq&lt;/groupId&gt;
          &lt;artifactId&gt;com.ibm.mqjms&lt;/artifactId&gt;
          &lt;version&gt;${mq.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;ibm.mq&lt;/groupId&gt;
          &lt;artifactId&gt;com.ibm.mq.jmqi&lt;/artifactId&gt;
          &lt;version&gt;${mq.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;ibm.mq&lt;/groupId&gt;
          &lt;artifactId&gt;com.ibm.mq.headers&lt;/artifactId&gt;
          &lt;version&gt;${mq.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;ibm.mq&lt;/groupId&gt;
          &lt;artifactId&gt;com.ibm.mq.commonservices&lt;/artifactId&gt;
          &lt;version&gt;${mq.version}&lt;/version&gt;
      &lt;/dependency&gt;    
      &lt;/dependencies&gt;
  
      &lt;build&gt;
      &lt;finalName&gt;${project.artifactId}-${project.version}&lt;/finalName&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.1&lt;/version&gt;
          &lt;configuration&gt;
              &lt;source&gt;1.8&lt;/source&gt;
              &lt;target&gt;1.8&lt;/target&gt;
              &lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
          &lt;/configuration&gt;
          &lt;/plugin&gt;              
      &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong><em>as per the suggestion in the post below (thx, joshmc),  here is the AMQERR01.log</em></strong>
  it appears to provide a clue... -now, the quest to determine how to I unblock the 'admin' user   :-)</p>
  
  <pre><code>----- cmqxrmsa.c : 1347 -------------------------------------------------------
  08/11/17 17:32:09 - Process(1847.6) User(root) Program(amqrmppa)
              Host(bd069b8075db) Installation(Installation1)
              VRMF(9.0.3.0) QMgr(QM1)
              Time(2017-08-11T17:32:09.967Z)
  
  AMQ9776: Channel was blocked by userid
  
  EXPLANATION:
  The inbound channel 'DEV.APP.SVRCONN' was blocked from address '172.17.0.1'
  because the active values of the channel were mapped to a userid which should
  be blocked. The active values of the channel were 'MCAUSER(admin)
  CLNTUSER(admin)'.
  ACTION:
  Contact the systems administrator, who should examine the channel
  authentication records to ensure that the correct settings have been
  configured. The ALTER QMGR CHLAUTH switch is used to control whether channel
  authentication records are used. The command DISPLAY CHLAUTH can be used to
  query the channel authentication records.
  ----- cmqxrmsa.c : 1347 ------------------------------------------------------- 
  </code></pre>
  
  <p><strong><em>running following command (as suggested)...</em></strong></p>
  
  <pre><code>C:\&gt;docker exec --tty --interactive mq runmqsc
  5724-H72 (C) Copyright IBM Corp. 1994, 2017.
  Starting MQSC for queue manager QM1.
  </code></pre>
  
  <p><strong><em>DIS CHL(DEV.APP.SVRCONN) MCAUSER</em></strong></p>
  
  <pre><code>DIS CHL(DEV.APP.SVRCONN) MCAUSER
       1 : DIS CHL(DEV.APP.SVRCONN) MCAUSER
  AMQ8414: Display Channel details.
     CHANNEL(DEV.APP.SVRCONN)                CHLTYPE(SVRCONN)
     MCAUSER(app)
         :
  </code></pre>
  
  <p><strong><em>DISPLAY CHLAUTH(DEV.APP.SVRCONN) MATCH(RUNCHECK) ALL ADDRESS(172.17.0.1)</em></strong></p>
  
  <pre><code>DISPLAY CHLAUTH(DEV.APP.SVRCONN) MATCH(RUNCHECK) ALL ADDRESS(172.17.0.1) CLNTUSER('admin')
       5 : DISPLAY CHLAUTH(DEV.APP.SVRCONN) MATCH(RUNCHECK) ALL ADDRESS(172.17.0.1) CLNTUSER('admin')
  AMQ8878: Display channel authentication record details.
     CHLAUTH(DEV.APP.SVRCONN)                TYPE(ADDRESSMAP)
     DESCR( )                                CUSTOM( )
     ADDRESS(*)                              USERSRC(CHANNEL)
     CHCKCLNT(ASQMGR)                        ALTDATE(2017-08-11)
     ALTTIME(19.23.31)
  </code></pre>
  
  <p><strong><em>DIS QMGR CONNAUTH</em></strong></p>
  
  <pre><code>DIS QMGR CONNAUTH
       1 : DIS QMGR CONNAUTH
  AMQ8408: Display Queue Manager details.
     QMNAME(QM1)                             CONNAUTH(DEV.AUTHINFO)
  </code></pre>
  
  <p><strong><em>DIS AUTHINFO(DEV.AUTHINFO)</em></strong></p>
  
  <pre><code>DIS AUTHINFO(DEV.AUTHINFO)
       2 : DIS AUTHINFO(DEV.AUTHINFO)
  AMQ8566: Display authentication information details.
     AUTHINFO(DEV.AUTHINFO)                  AUTHTYPE(IDPWOS)
     ADOPTCTX(YES)                           DESCR( )
     CHCKCLNT(REQDADM)                       CHCKLOCL(OPTIONAL)
     FAILDLAY(1)                             AUTHENMD(OS)
     ALTDATE(2017-08-14)                     ALTTIME(13.57.29)
  </code></pre>
  
  <p><strong><em>DISPLAY CHLAUTH(DEV.APP.SVRCONN) all</em></strong></p>
  
  <pre><code>DISPLAY CHLAUTH(DEV.APP.SVRCONN) all
       1 : DISPLAY CHLAUTH(DEV.APP.SVRCONN) all
  AMQ8878: Display channel authentication record details.
     CHLAUTH(DEV.APP.SVRCONN)                TYPE(ADDRESSMAP)
     DESCR( )                                CUSTOM( )
     ADDRESS(*)                              USERSRC(CHANNEL)
     CHCKCLNT(ASQMGR)                        ALTDATE(2017-08-16)
     ALTTIME(13.43.26)
  </code></pre>
  
  <p><strong><em>DISPLAY CHLAUTH(</em>) all*</strong></p>
  
  <pre><code>DISPLAY CHLAUTH(*) all
       2 : DISPLAY CHLAUTH(*) all
  AMQ8878: Display channel authentication record details.
     CHLAUTH(DEV.ADMIN.SVRCONN)              TYPE(USERMAP)
     DESCR(Allows admin user to connect via ADMIN channel)
     CUSTOM( )                               ADDRESS( )
     CLNTUSER(admin)                         USERSRC(CHANNEL)
     CHCKCLNT(ASQMGR)                        ALTDATE(2017-08-16)
     ALTTIME(13.43.26)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(DEV.ADMIN.SVRCONN)              TYPE(BLOCKUSER)
     DESCR(Allows admins on ADMIN channel)   CUSTOM( )
     USERLIST(nobody)                        WARN(NO)
     ALTDATE(2017-08-16)                     ALTTIME(13.43.26)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(DEV.APP.SVRCONN)                TYPE(ADDRESSMAP)
     DESCR( )                                CUSTOM( )
     ADDRESS(*)                              USERSRC(CHANNEL)
     CHCKCLNT(ASQMGR)                        ALTDATE(2017-08-16)
     ALTTIME(13.43.26)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(MY.ADMIN.SVRCONN)               TYPE(ADDRESSMAP)
     DESCR( )                                CUSTOM( )
     ADDRESS(127.0.0.1)                      USERSRC(CHANNEL)
     CHCKCLNT(ASQMGR)                        ALTDATE(2017-08-11)
     ALTTIME(20.17.14)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(MY.ADMIN.SVRCONN)               TYPE(BLOCKUSER)
     DESCR( )                                CUSTOM( )
     USERLIST(*NOBODY)                       WARN(NO)
     ALTDATE(2017-08-11)                     ALTTIME(20.17.51)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(SYSTEM.ADMIN.SVRCONN)           TYPE(ADDRESSMAP)
     DESCR(Default rule to allow MQ Explorer access)
     CUSTOM( )                               ADDRESS(*)
     USERSRC(CHANNEL)                        CHCKCLNT(ASQMGR)
     ALTDATE(2017-08-03)                     ALTTIME(17.22.22)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(SYSTEM.*)                       TYPE(ADDRESSMAP)
     DESCR(Default rule to disable all SYSTEM channels)
     CUSTOM( )                               ADDRESS(*)
     USERSRC(NOACCESS)                       WARN(NO)
     ALTDATE(2017-08-03)                     ALTTIME(17.22.22)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(*)                              TYPE(ADDRESSMAP)
     DESCR(Back-stop rule - Blocks everyone)
     CUSTOM( )                               ADDRESS(*)
     USERSRC(NOACCESS)                       WARN(NO)
     ALTDATE(2017-08-16)                     ALTTIME(13.43.26)
  AMQ8878: Display channel authentication record details.
     CHLAUTH(*)                              TYPE(BLOCKUSER)
     DESCR(Default rule to disallow privileged users)
     CUSTOM( )                               USERLIST(*MQADMIN)
     WARN(NO)                                ALTDATE(2017-08-03)
     ALTTIME(17.22.22)
  </code></pre>