【问题标题】:Connecting MQ version 9 using JAVA with SSL使用带有 SSL 的 JAVA 连接 MQ 版本 9
【发布时间】:2019-09-27 08:03:14
【问题描述】:

我尝试使用以下代码连接 MQ 版本 9。

/**
 * Java class to connect to MQ. Post and Retrieve messages.
 *
 */
public class MQClientTest {

    String qMngrStr = "";
    String user = "user";
    String password = "password";
    String queueName = "qname";
    String hostName = "hostName ";
    int port = 1234;
    String channel = "channel";
    String sslCiphersuite="TLS_RSA_WITH_AES_256_CBC_SHA256";
    //message to put on MQ.
    String msg = "WelCome to MQ.";
    //Create a default local queue.
    MQQueue queue;
    MQQueueManager qManager;

    /**
     * Initialize the MQ
     *
     */
    public void init(){

        //Set MQ connection credentials to MQ Envorinment.
         MQEnvironment.hostname = hostName;
         MQEnvironment.channel = channel;
         MQEnvironment.port = port;
         MQEnvironment.userID = user;
         MQEnvironment.password = password;
         MQEnvironment.sslCipherSuite= sslCiphersuite;
       //  MQEnvironment.sslFipsRequired=true;
         //set transport properties.
         MQEnvironment.properties.put(MQConstants.TRANSPORT_PROPERTY, MQConstants.TRANSPORT_MQSERIES_CLIENT);

         try {
             //initialize MQ manager.
            qManager = new MQQueueManager(qMngrStr);
        } catch (MQException e) {
            e.printStackTrace();
            System.out.println("queue manager issue");
        }
    }

    /**
     * Method to put message to MQ.
     *
     */
    public void putAndGetMessage(){

        int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT; 
        try {
            queue = qManager.accessQueue(queueName, openOptions);

            MQMessage putMessage = new MQMessage();
            putMessage.writeUTF(msg);

            //specify the message options...
            MQPutMessageOptions pmo = new MQPutMessageOptions(); 
            // accept 
            // put the message on the queue
            queue.put(putMessage, pmo);

            System.out.println("Message is put on MQ.");

        catch (MQException e) {
            e.printStackTrace();
            System.out.println("MQexception");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("IOexception");
        }
        catch (Exception e) {
            System.out.println("exception");}
    }

    public static void main(String[] args) {

        System.out.println("Processing Main...");

        MQClientTest clientTest = new MQClientTest();
        System.setProperty("com.ibm.mq.cfg.useIBMCipherMappings", "false");
        // Enabling SSL debug to view the communication
        //System.setProperty("javax.net.debug", "ssl:handshake");

        System.setProperty("javax.net.ssl.trustStore","client.jks");
        System.setProperty("javax.net.ssl.trustStorePassword","clientpass");
        System.setProperty("javax.net.ssl.keyStore","client.jks");
        System.setProperty("javax.net.ssl.keyStorePassword","clientpass");
        //initialize MQ.
        clientTest.init();

        //put and retreive message from MQ.
        clientTest.putAndGetMessage();

        System.out.println("Done!");
    }

}

但我收到以下错误:

MQJE001:MQJE001:完成代码“2”,原因“2393”。

我已尝试将系统变量 com.ibm.mq.cfg.useIBMCipherMappings 设置为 false。并且还在 MQEnvironment.sslCipherSuite 中添加了 ssl 名称。

我也在 IBM 网站上阅读了密码映射的映射。找不到更多的解决方案。如果有人知道这件事,请帮忙?

谢谢

【问题讨论】:

  • RC 2393 是 MQRC_SSL_INITIALIZATION_ERROR,对于 MQ Java/Java 应用程序,这通常意味着 JRE 的 TLS 套接字库(Java 安全套接字扩展 (JSSE))对 TLS 配置中的某些内容不满意。从 JSSE 报告的异常应该作为生成的 MQException 的链接异常提供,并且将提供有关问题性质的更多信息 - 您是否能够修改您的应用程序以打印出链接异常?
  • 我的队列管理器名称为空,因此获取队列管理器对象时出错。我应该如何解决这个问题?
  • @user - 提供给 MQQueueManager 构造函数的队列管理器名称必须是您要连接的队列管理器的实际名称。如果上面代码中的常量值(主机名、端口、通道等)是您正在编译的实际值,那么它们都需要更改为目标队列管理器的正确值。
  • 您使用的确切 java 版本是什么?前 1.8 0-124。

标签: java ssl-certificate ibm-mq


【解决方案1】:

您的问题可能是 JRE 不允许 256 密码套件,而不是 MQ。见https://developer.ibm.com/answers/questions/189995/why-do-i-get-amq9771-2393-ssl-initialization-error/https://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html#footnote1-1

我建议将您的 Java JDK 升级到最新版本,然后重试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-22
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2016-06-23
    • 2012-09-10
    相关资源
    最近更新 更多