ClassCastException: com.ibm.mq.jms.MQQueueConnectionFactory
843830Sep 28 2007 — edited Sep 29 2007I have the below program, trying to send a message to Q, we use WAS 4.0.3 and MQ, 5.3. Trying to lookup JNDI in WAS. Error is on the line " javax.naming.Context env =(javax.naming.Context) ctx.lookup("QCF");"
Any help greatly appreciated !.
package com.jms;
import javax.naming.Context;
import javax.naming.InitialContext;
public class JMSPTP {
public JMSPTP(){
}
public static void main() {
try {
// get JNDI context
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
// get local JNDI environment
javax.naming.Context env =(javax.naming.Context) ctx.lookup("QCF");
// get queue connection factory
javax.jms.QueueConnectionFactory qcf =(javax.jms.QueueConnectionFactory) env.lookup("QCF");
// create a connection
javax.jms.QueueConnection qc = qcf.createQueueConnection();
// create a session
javax.jms.QueueSession qSession =qc.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
// get queue
javax.jms.Queue q = (javax.jms.Queue) env.lookup("Q1");
// create a queue sender for the queue and send a text message
javax.jms.QueueSender sender = qSession.createSender(q);
sender.send(qSession.createTextMessage("Hello world!"));
sender.close();
System.out.println("close");
} catch (Exception ex) {
System.err.println("JMSPTP.init(): Exception:" + ex.toString() + ", " + ex.getMessage());
ex.printStackTrace(System.err);
}// EOF catch
}
}