Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ClassCastException: com.ibm.mq.jms.MQQueueConnectionFactory

843830Sep 28 2007 — edited Sep 29 2007
I 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
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2007
Added on Sep 28 2007
1 comment
574 views