1 Reply Latest reply on Oct 8, 2011 5:15 PM by everson .

    QueueBrowser - JBossQueueBrowser$BrowserEnumeration cannot be cast to javax.jms.ObjectMessage

    everson . Newbie

      I'm trying scanning a queue and pick up a specific object there, but I'm getting the error below ....

       

      QueueBrowser queueBrowser = session.createBrowser(queue);

                  Enumeration<ObjectMessage> messages = queueBrowser.getEnumeration();

                  while (messages.hasMoreElements()) {

                      ObjectMessage objectMessage = (ObjectMessage) messages;// error here

                      Jms jms = new Jms();

                      People p = jms.new People();

                      p = (People) objectMessage.getObject();

                      System.err.println(p.getName());

                  }

       

       

      java.lang.ClassCastException: org.jboss.jms.client.JBossQueueBrowser$BrowserEnumeration cannot be cast to javax.jms.ObjectMessage

       

       

      to send the message

       

      session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

                  ObjectMessage om = session.createObjectMessage();

                  Jms jms = new Jms();

                  People p = jms.new People();

                  p.setNome("Testttttt");

                  om.setObject(p);

                  QueueSender sender = session.createSender(queue);

                  sender.send(om);

        • 1. Re: QueueBrowser - JBossQueueBrowser$BrowserEnumeration cannot be cast to javax.jms.ObjectMessage
          everson . Newbie

          I fixed as below

           

          ObjectMessage objectMessage = (ObjectMessage) messages.nextElement();

           

           

          QueueBrowser queueBrowser = session.createBrowser(queue);

                      Enumeration<ObjectMessage> messages = queueBrowser.getEnumeration();

                      while (messages.hasMoreElements()) {

                          ObjectMessage objectMessage = (ObjectMessage) messages;// error here

                          Jms jms = new Jms();

                          People p = jms.new People();

                          p = (People) objectMessage.getObject();

                          System.err.println(p.getName());

                      }