You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Dan Retzlaff <dr...@gmail.com> on 2010/08/25 01:42:23 UTC

ClassCastException with ObjectMessages and MessageListeners between Web Apps

When ActiveMQ deserializes an ObjectMessage, it uses the current thread's
context ClassLoader. This strategy does not work for my combination of
Tomcat and JMS MessageListeners, and I'm wondering if I'm missing something.

I have multiple web applications deployed in Tomcat, with a shared VM broker
ConnectionFactory configured in Tomcat's context.xml. Let's call the
applications AppA and AppB. If AppA opens a JMS connection first, the
connection's threads' ClassLoader is AppA's. If AppB receives an
ObjectMessage from AppA using a MessageListener, a ClassCastException is
thrown when downcasting.

As a workaround, I have created a thread pool in AppB dedicated to pulling
messages with MessageConsumer.receive(). This way AppB's context ClassLoader
is used during deserialization and the downcast succeeds. However, this
feels inelegant, and I'm surprised at my inability to find any other
discussion of this subtle gotcha.

Any suggestions? Maybe I shouldn't be sharing a my ConnectionFactory among
web applications?

Regards,
Dan