0 Replies Latest reply on Jul 6, 2006 12:28 AM by Dharma Raja

    Class Cast Exception - Hellodr

    Dharma Raja Newbie

      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 ***********");
      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) {

      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);

      public void sendMessageToQueue(String message) throws Exception{
      qSender = qSess.createSender(queue);
      TextMessage tm = qSess.createTextMessage(message);
      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