java - 使用 JAVA 和 SSL 连接 MQ 版本 9

标签 java ssl-certificate ibm-mq

我尝试使用以下代码连接 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: Completion Code '2', Reason '2393'.

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

我也在 IBM 网站上阅读了密码映射的映射。找不到更多解决方案。请问有人知道这个情况请帮忙吗?

谢谢

最佳答案

您的问题可能是 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 升级到最新版本,然后重试。

关于java - 使用 JAVA 和 SSL 连接 MQ 版本 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58130318/

相关文章:

java - Spring Boot如何在服务器重启时轮换日志文件

java - Permgen 空间增量填充/调整大小。如何微调避免调整其大小

c# - .pem 文件和 .p12 文件和 URL - 天啊

python - web.py 上的 SSL 证书链不完整

docker - 在Windows Docker下运行的IBM MQ客户端

java - Spring Boot 部署失败,Weblogic 10.3.4.0 中出现 StackoverflowError

java - Android:没有 onCreate() 方法的服务类

firefox - Firefox 中的 SSL 证书异常

jms - 使用客户端模式连接到 IBM MQ 时出现 MQJMS2005 异常

c++ - IBM WebSphere MQ 在 Windows 上支持 64 位客户端吗?