基于以下问题:
Connecting to a Websphere MQ in Java with SSL/Keystore
我设置了一个Domino代理来访问IBM MQ。但是我收到了消息:
javax.jms.JMSException:MQJMS2005:无法为' ibmmq.mycorp.se创建MQQueueManager:QMANAGER'
我使用以下代码:
import lotus.domino.*;
import javax.jms.*;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
import com.ibm.mq.jms.JMSC;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import java.io.InputStream;
import java.security.KeyStore;
public class JavaAgent extends AgentBase {
/*
* not working. factory incorrect set?
*/
private static final boolean debug = true;
private static final boolean debugDefault = true;
String msg;
public void NotesMain() {
lotus.domino.Session s = getSession();
OpenLogItem oli = new OpenLogItem(s);
try {
msg = "Agent started";
toLogDebug(msg);
Environment env = setEnvVariables();
InputStream res = this.getClass().getResourceAsStream("key.jks");
char[] pw = {'p','a','s','s','w','o','r','d'};
KeyStore ks;
ks = KeyStore.getInstance("JKS");
ks.load(res, pw);
msg = "after keystore loaded";
toLogDebug(msg);
// Create a keystore object for the truststore
KeyStore trustStore = KeyStore.getInstance("JKS");
InputStream res2 = this.getClass().getResourceAsStream("key.jks");
// Open our file and read the truststore (no password)
trustStore.load(res2, null);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(ks, pw);
trustManagerFactory.init(trustStore);
msg = "After Managers .init.";
toLogDebug(msg);
SSLContext sslContext = SSLContext.getInstance("SSL_TLS");
msg = "SSLContext provider: " + sslContext.getProvider().toString();
toLogDebug(msg);
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
msg = "After sslContext.init.";
toLogDebug(msg);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
msg = "After getSocketFactory()";
toLogDebug(msg);
// Create default MQ connection factory
MQQueueConnectionFactory factory = new MQQueueConnectionFactory();
msg = "After MQQueueConnectionFactory()";
toLogDebug(msg);
// Customize the factory
factory.setSSLSocketFactory(sslSocketFactory);
// Use javac SSLTest.java -Xlint:deprecation
factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
factory.setQueueManager(env.getQueManager());
factory.setHostName(env.getHost());
factory.setChannel(env.getChannel());
factory.setPort(env.getPort());
factory.setSSLFipsRequired(false);
factory.setSSLCipherSuite("TLS_RSA_WITH_AES_256_CBC_SHA256");
msg = "After factory set";
toLogDebug(msg);
QueueConnection connection = null;
connection = factory.createQueueConnection("",""); //empty user, pass to avoid MQJMS2013 messages
msg = "after createQueueConnection(\"\",\"\")";
toLogDebug(msg);
connection.start();
msg = "JMS SSL client connection started!";
toLogDebug(msg);
connection.close();
msg = "Agent done!";
toLogDebug(msg);
} catch (JMSException ex) {
oli.logError(ex);
} catch (Exception ex){
oli.logError(ex);
}
}
public Environment setEnvVariables(){
Environment env = null;
lotus.domino.Session s = getSession();
try{
Database adminDb = s.getCurrentDatabase();
if (adminDb.isOpen()){
View adminVw = adminDb.getView("settings");
if (null != adminVw){
adminVw.setAutoUpdate(false);
Document adminDoc = adminVw.getFirstDocument();
if (null != adminDoc){
env = new Environment();
if (adminDoc.hasItem("mqhost")){
env.setHost(adminDoc.getItemValueString("mqhost"));
}
if (adminDoc.hasItem("mqport")){
env.setPort(Integer.parseInt(adminDoc.getItemValueString("mqport")));
}
if (adminDoc.hasItem("mqchannel")){
env.setChannel(adminDoc.getItemValueString("mqchannel"));
}
if (adminDoc.hasItem("mqquemanager")){
env.setQueManager(adminDoc.getItemValueString("mqquemanager"));
}
}
}
}
}catch(Exception e){
//
}
return env;
}
public void toLogDebug(String msg){
if (debug){
lotus.domino.Session session = getSession();
OpenLogItem oli = new OpenLogItem(session);
oli.logEvent(msg, OpenLogItem.SEVERITY_LOW, null);
}
}
public void toLogDefault(String msg){
if (debugDefault){
lotus.domino.Session session = getSession();
OpenLogItem oli = new OpenLogItem(session);
oli.logEvent(msg, OpenLogItem.SEVERITY_HIGH, null);
}
}
public class Environment{
String host;
int port;
String channel;
String queManager;
lotus.domino.Session s = getSession();
OpenLogItem oli = new OpenLogItem(s);
public Environment(){
oli.logEvent("Environment constructor", OpenLogItem.SEVERITY_LOW, null);
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getChannel() {
return channel;
}
public void setChannel(String channel) {
this.channel = channel;
}
public String getQueManager() {
return queManager;
}
public void setQueManager(String queManager) {
this.queManager = queManager;
}
}
}
我将环境变量存储在Notes关键字文档中。有没有人知道为什么这个代码会破坏:
connection = factory.createQueueConnection("","");
密钥文件作为资源包含在代理中,并提供给我。
答案 0 :(得分:0)
有没有人知道为什么这段代码会破坏:
connection = factory.createQueueConnection("","");
这是实际导致客户端连接到队列管理器的代码行。您使用的是IBM JRE还是Oracle JRE?队列管理器错误日志中的错误消息是什么?
您正在提供空白的UserId和密码。非常糟糕的主意。此外,队列管理器的CHLAUTH规则应该阻止空白的UserId。