Q:

Trouble casting JMS Message as TextMessage

I'm using a QueueBrowser to get and then loop through an enumeration of messages on a JMS queue. When I try to cast msgs.nextElement() as a TextMessage, IntelliJ IDEA tells me:
java.lang.ClassCastException: weblogic.jms.common.ObjectMessageImpl cannot be cast to javax.jms.TextMessage

I'm very new to JMS and I'm not quite sure what weblogic.jms.common.ObjectMessageImpl is. Casting msgs.nextElement() to type Message seems to work fine. My code is below.
private void readQueueMessage() throws JMSException {
    int counter = 0;
    System.out.println("Starting the subscriber");
    QueueBrowser queueBrowser = queueSession.createBrowser(queue);
    Enumeration msgs = queueBrowser.getEnumeration();
    //queueConnection.start();
    System.out.println("Queue started");
    if ( !msgs.hasMoreElements() ) { 
        System.out.println("No messages in queue");
    } else { 
        while (msgs.hasMoreElements()) { 
            System.out.println(">>> message count: " + ++counter);

            Message message = (Message)msgs.nextElement();
            System.out.println("MessageID: " + message.getJMSMessageID() + "\tPriority: " + message.getJMSPriority() + "\tDeliveryMode: " + message.getJMSDeliveryMode());
            System.out.println("Timestamp: " + message.getJMSTimestamp() + "\tJMSDestination: " + message.getJMSDestination() + "\tReplyTo: " + message.getJMSReplyTo());
            System.out.println("Data: " + ((TextMessage)message).getText());

            if (counter >= 3) break;
        }
    }

    System.out.println("stopping the queue");
    queueConnection.stop();
}

A:

There are several different types of messages in JMS. You are trying to read a TextMessage that basically contains a String, but the message you are reading is in fact an ObjectMessage which contains a Java object. You should check if the message is a text message using instanceof TextMessage and either ignore it if it is something else or throw an exception.
The class weblogic.jms.common.ObjectMessageImpl is simply WebLogic's implementation of ObjectMessage.

