Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug JMS when Body is not assignable to class?

I am using Java EE JMS Queue. I am sending objects into the queue and then receive them with a MDB. When reading the message body (with getBody()) into an object I get the following exception:

javax.jms.MessageFormatException: Body not assignable to class ...

Is there any way to get a more descriptive error out of this that would tell why exactly it is not assignable? I also tried to go into debug mode and see what kind of Message object arrives into the MDB but it is serialized as far as I can see so it's not really useful.

Object type is properly recognised in debugger before it is sent to the queue.

Additiona info: if I create an empty object manually and send it, it is properly recognised. The production object comes from a REST endpoint and contains a lot of properties and gets transformed a bunch of times in the process. Some piece of data must be preventing the assignment but debugging each property step by step would be a pain and only as a last resort.

Object is confirmed serializable per answer in how to test in Java that a class implements Serializable correctly (not just is an instance of Serializable)

Object is sent as: jmsContext.createProducer().send(queue, object);

I managed to narrow it down by setting all properties to null and then commenting that out one by one until it worked. It turns out a Duration type property was improperly? initialized which caused the problem. And in another case it was XMLGregorianCalendar property that caused it. Still, this is a very hacky way of debugging and I still don't actually know why exactly the assignment fails, I just know which property causes it.

For the time being I ended up passing entity IDs into the queue instead of full objects and I retreive them from database by the ID instead.

Pastebin of full stacktrace: http://pastebin.com/vWvhDTcr

like image 686
cen Avatar asked Sep 17 '15 07:09

cen


1 Answers

A good design(if you have control over it now, meaning its a new app not already in production) may be to use json payloads, that way you can see the payload as text at any time, the json deserializers like jackson spit out better exceptions.

Gregorian Calendars are painful for xml serialization atleast from my experience, you are better off using something like joda time.

like image 87
Mahesh Avatar answered Nov 02 '22 15:11

Mahesh