-
1. Re: Class Cast Exception -- By HelloDr
genman Jul 5, 2006 6:22 PM (in response to hellodr)
What's the type of the object? E.g.
Object o = ...
System.out.println("class is " + o.getClass()); -
2. Re: Class Cast Exception -- By HelloDr
hellodr Jul 5, 2006 11:57 PM (in response to hellodr)Thanks genman..
The type of the Object is org.jboss.mq.SpyQueue. But I dont need to use SpyQueue or SpyConnectionFactory. I prefer to use QueueConnectionFactory and Queue Connection in my program. But When do a JNDI lookup like
SpyConnectionFactory factory = (SpyConnectionFactory) ctx.lookup("ConnectionFactory");
It returs Object of SpyConnectionFactory. What should I do in my Application Server Settings to return QueueConnectionFactory. Also please let me know the JNDI name for it.
My full Program Code is (Which Throws Exception)
package com.echain.contacts.web.action;
import java.io.PrintWriter;
import javax.jms.QueueConnection;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jboss.mq.SpyConnectionFactory;
import org.jboss.mq.SpyQueue;
public class ServerAction extends Action {
QueueConnection qCon;
QueueSession qSess;
SpyQueue queue;
QueueSender qSender;
PrintWriter pw;
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception {
try {
pw = res.getWriter();
System.out.println("\n\n*********** Creating Queue ***********\n\n");
pw.println("*********** Creating Queue ***********");
createQueue();
System.out.println("\n\n*********** Created Queue ***********\n\n");
pw.println("*********** Created Queue ***********");
System.out.println("\n\n*********** Sending Message to Queue ***********\n\n");
pw.println("*********** Sending Message to Queue ***********");
sendMessageToQueue("THis is the Message");
System.out.println("\n\n*********** Message Sent to Queue ***********\n\n");
pw.println("*********** Message Sent to Queue ***********");
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("forward.success");
}
public void createQueue() throws Exception{
InitialContext ctx = new InitialContext();
System.out.println("\n\nFactory is : " + ctx.lookup("ConnectionFactory") + "\n\n");
SpyConnectionFactory factory = (SpyConnectionFactory) ctx.lookup("ConnectionFactory");
qCon = factory.createQueueConnection();
ctx = new InitialContext();
Object o = ctx.lookup("queue/echnQueue");
System.out.println("\n\nQueue is : " + o.getClass() + "\n\n");
queue = (SpyQueue) ctx.lookup("queue/echnQueue");
qSess = qCon.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
qCon.start();
}
public void sendMessageToQueue(String message) throws Exception{
qSender = qSess.createSender(queue);
TextMessage tm = qSess.createTextMessage(message);
qSender.send(tm);
qSender.close();
System.out.println("\n\n\n\n*****************\n\nMessage Send to Queue And QSender is Closed\n\n************\n\n\n");
pw.println("***************** Message Send to Queue And QSender is Closed ************");
}
}
In the above marked redline I am getting an exception
java.lang.LinkageError: Class javax/jms/QueueConnection violates loader constraints
Please help me out
Regards,
Dharma -
3. Re: Class Cast Exception -- By HelloDr
thameema May 9, 2008 1:41 PM (in response to hellodr)I am using jboss 4.2.2 and facing the same issue. When I try to typecast the SpyConnectionFactory to TopicConnectionFacotry, I am getting ClassCastException.. Anyhelp on this?
Thanks. -
4. Re: Class Cast Exception -- By HelloDr
adrian.brock May 16, 2008 1:15 PM (in response to hellodr)This is a basic java question.
System.out.println(TopicConnectionFactory.class.getClassLoader()); Class[] interfaces = SpyConnectionFactory.class.getInterfaces(); for (int i = 0; i < interfaces.length; ++i) { Class intf = interfaces System.out.println(intf.getName() + " " + intf.getClassLoader(); }
Printing the code source will tell you where it is loading the duplicate classes from.