gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:09:51 53 4
gpt4 key购买 nike

我尝试使用以下代码连接 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/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com