我正在尝试使用独立的Java代码连接到Websphere Application Server 8上配置的JMS队列。但我收到一个例外。我检查了http://www-01.ibm.com/support/docview.wss?uid=swg1PK78897这个链接,但没有得到任何解决方案。 远程服务器上禁用SSL。 PFB我的代码和堆栈跟踪。
package com.jms.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Demo {
public static void main(String[] args) throws NamingException {
System.out.println("Start.....");
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
environment.put(Context.PROVIDER_URL, "iiop://10.10.222.197:2810");
//String pUrl = System.getProperty(Context.PROVIDER_URL);
//System.out.println("*******"+pUrl+"********");
InitialContext initContext = new InitialContext(environment);
System.out.println("Init Done");
QueueConnectionFactory qConFac = (QueueConnectionFactory)initContext.lookup("jms/FOREIGN.DIRECT.QCF");
System.out.println("Connection Factory is - "+qConFac.toString());
Queue queue = (Queue) initContext.lookup("jms/FOREIGN.DIRECT.Q");
System.out.println("Queue is - "+queue.toString());
initContext.close();
//System.setProperty("com.ibm.ssl.performURLHostNameVerification", "true");
Connection connection = null;
Session session = null;
MessageProducer producer = null;
MessageConsumer consumer = null;
TextMessage txtMessage = null;
Message message = null;
try {
connection = qConFac.createConnection();
System.out.println("CONNECTION OBTAINED");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println("SESSION CREATED");
System.out.println("Please enter your message:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String msg = br.readLine();
System.out.println("Creating producer to send message...");
producer = session.createProducer(queue);
System.out.println("Creating a TextMessage...");
txtMessage = session.createTextMessage(msg);
producer.send(txtMessage);
System.out.println("Text Message sent to queue.");
consumer = session.createConsumer(queue);
System.out.println("CONSUMER CREATED");
connection.start();
txtMessage = (TextMessage) consumer.receive();
String receivedMsg = txtMessage.getText();
System.out.println("Message received is "+receivedMsg);
if(receivedMsg.equalsIgnoreCase("1"))
System.out.println("Ticket Number is 1");
else if(receivedMsg.equalsIgnoreCase("2"))
System.out.println("Ticket Number is 2");
else
System.out.println("Some other message was received");
} catch (JMSException e) {
// TODO Auto-generated catch block
//System.out.println("JMS Exception while creating connection");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
堆栈追踪:
Start.....
Init Done
JSAS1480I: Security is not enabled because the ConfigURL property file is not set.
Connection Factory is - com.ibm.ws.sib.api.jms.impl.JmsQueueConnectionFactoryImpl@a26cf1a1
Queue is - queue://FOREIGN.DIRECT.Q?busName=FOREIGN.DIRECT.TEST
Exception in thread "P=92841:O=0:CT" com.ibm.websphere.sib.exception.SIErrorException: CWSIT0008E: A successful connection was made to the bootstrap server at localhost:7276:BootstrapBasicMessaging but the server returned an error condition: CWSIT0086E: Bus FOREIGN.DIRECT.TEST not found
at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.generateException(TrmSICoreConnectionFactoryImpl.java:982)
at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.remoteBootstrap(TrmSICoreConnectionFactoryImpl.java:638)
at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.createConnection(TrmSICoreConnectionFactoryImpl.java:307)
at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.createConnection(TrmSICoreConnectionFactoryImpl.java:222)
at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createCoreConnection(JmsJcaConnectionFactoryImpl.java:711)
at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createCoreConnection(JmsJcaConnectionFactoryImpl.java:647)
at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createConnection(JmsJcaConnectionFactoryImpl.java:376)
at com.ibm.ws.sib.api.jms.impl.JmsManagedConnectionFactoryImpl.createConnection(JmsManagedConnectionFactoryImpl.java:162)
at com.ibm.ws.sib.api.jms.impl.JmsManagedConnectionFactoryImpl.createConnection(JmsManagedConnectionFactoryImpl.java:135)
at com.jms.test.Demo.main(Demo.java:50)
Caused by: com.ibm.websphere.sib.exception.SIErrorException: CWSIT0009W: A client connect to bus FOREIGN.DIRECT.TEST failed in the bootstrap server with endpoint localhost:7276:BootstrapBasicMessaging with reason: CWSIT0086E: Bus FOREIGN.DIRECT.TEST not found.
at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.generateException(TrmSICoreConnectionFactoryImpl.java:1035)
at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.contactBootstrapService(TrmSICoreConnectionFactoryImpl.java:745)
at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.remoteBootstrap(TrmSICoreConnectionFactoryImpl.java:589)
... 8 more