Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ClassCastException with ObjectMessage

138 views
Skip to first unread message

Sameera Balay

unread,
Jun 18, 2001, 9:23:49 AM6/18/01
to
Hi,

I'm using MDB's on WebLogic6.0 with sp2. I'm using Pub/Sub. I tried
using TextMessage it works fine but I try to use ObjectMessage I get the
following error.

<Jun 18, 2001 7:44:09 AM CDT> <Warning> <EJB> <The MessageDrivenBean
threw an Exception in onMessage()
java.lang.ClassCastException: weblogic.jms.common.TextMessageImpl
at
com.nextjet.enterprise.flightmonitoring.flightcancellation.FlightCancellationMDB.onMessage(FlightCancellationMDB.java:71)

at
weblogic.ejb20.internal.MDListener.execute(MDListener.java:221)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)

at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>

Here's my code on the Pub side

topicConnectionFactory =
(TopicConnectionFactory)_ctx.lookup(JMS_FACTORY);
topicConnection =
topicConnectionFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
try {
topic = (Topic) _ctx.lookup(_topic_name);
}
catch(NamingException ne) {
topic = topicSession.createTopic(_topic_name);
_ctx.bind(_topic_name, topic);
}
topicPublisher = topicSession.createPublisher(topic);

msg = topicSession.createObjectMessage();

// Start the JMS connection; allows messages to be delivered.
topicConnection.start();

FlightID flightID = new FlightID(new Date(), "AA", "", null, "DFW",
"ATL");
FlightCancellation flightCancellation = new FlightCancellation(flightID,
new Date());
msg.setObject(flightCancellation);
topicPublisher.publish(msg);
}

Can somebody tell me why I get a class cast exception and why it's
looking for weblogic.jms.common.TextMessageImpl

Thanks
Sameera

Don Martin

unread,
Jun 18, 2001, 9:39:12 AM6/18/01
to

Check your code in the onMessage method for FlightCancellation.
Looks like you may be casting it to a TextMessageImpl there
rather than an ObjectMessageImpl.

-Don

Sameera Balay

unread,
Jun 18, 2001, 9:59:45 AM6/18/01
to
No I'm not casting it to TextMessage.

Here's the code for onMessage

public void onMessage(Message message) {
try {
if(message instanceof ObjectMessage)
System.out.println("Message is ObjectMessage");
System.out.println("Inside onMessage");
ObjectMessage objectmessage = (ObjectMessage)message;
FlightCancellation flightcancellation = (FlightCancellation)objectmessage.getObject();
}
catch(Exception e) {
}
}

Thanks
Sameera

Zach

unread,
Jun 18, 2001, 1:06:38 PM6/18/01
to
When you get a class cast exception, it displays the name of the class
that you were trying to cast, not the name of the class to which you are
casting. Actually it looks like you are casting a TextMessage to an
ObjectMessage which will definitely not work. Your code checks for
instanceof ObjectMessage, but you cast it even if it is not. I would
expect to see see something like

if (message instanceof ObjectMessage) {
FlightCancellation fc = (FlightCancellation)
((ObjectMessage) message).getObject();
}

I don't see you setting the delivery mode on your producer. The default is
persistent. Perhaps you have some TextMessages still in your queue from
a previous test run?.

_sjz.


"Sameera Balay" <s...@nextjet.com> wrote in message
news:3B2E0951...@nextjet.com...

Sameera Balay

unread,
Jun 20, 2001, 6:40:02 PM6/20/01
to
I had old TextMessages still in the queue from the previous run. That's the
reason I had the error. How do I remove the old messages from the queue?

Thanks
Sameera

0 new messages