开发者

Object with collection containing Serializable, non-primitive objects can't be set as ActiveMQ ObjectMessage

I'd appreciate any help on this...

I have an Object I'm trying to send in a JMS ObjectMessage by calling setObject. This Object contains a HashMap content as well as some other fields. When the map contains primitive elements the message is built fine. Likewise if I add a non-primitive serializable field to the Object it also sends ok.

Here's the rub: Whenever I try to add a serializable non-primitive object to the MAP I get the following MessageFormatException:

javax.jms.MessageFormatException: Only objectified primitive objects, String, 
Map and List types are allowed but was: com.abc.ObjectInList

The javadoc for ObjectMessage specifies...

Only Serializable Java objects can be used.

... check. And ...

If a collection of Java objects must be sent, one of the Collection classes provided since JDK 1.2 can be used.

... double check. While this doesn't specifically say anything about Serializable objects in a Collection, I guess I would assume this would be supported. Am I doing something wrong here? Do I just bite the bullet and make a new field in my top level Object so I don't have to put it in the Collection?

Using ActiveMQ 5.2. A pertinent Stack Trace follows.

2011-08-01 21:06:05,767 ERROR javax.jms.MessageFormatException: Only objectified primitive objects, String, Map and List types are allowed but was: com.abc.engine.ejb.BasicSchedule@58f295b9 type: class c om.abc.engine.ejb.BasicSchedule 2011-08-01 21:06:05,767 ERROR at org.apache.activemq.command.ActiveMQMessage.checkValidObject(ActiveMQMessage.java:468) 2011-08-01 21:06:05,767 ERROR at org.apache.activemq.command.ActiveMQMapMessage.setObject(ActiveMQMapMessage.java:705) 2011-08-01 21:06:05,767 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.initMessage(ChronicleMessageBean.java:149) 2011-08-01 21:06:05,767 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.send(ChronicleMessageBean.java:125) 2011-08-01 21:06:05,767 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.onMessage(ChronicleMessageBean.java:77) 2011-08-01 21:06:05,767 ERROR at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)2011-08-01 21:06:05,768 ERROR at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 2011-08-01 21:06:05,777 ERROR [com.abc.chronicle.ejb.Chr开发者_JAVA百科onicleMessageBean] JMS Exception Sending Message to SDK.OUTGOING_NOTIFICATION : javax.jms.MessageFormatException: Only objectified primitive objects, String, Ma p and List types are allowed but was: com.abc.engine.ejb.BasicSchedule@1003b2df type: class com.abc.engine.ejb.BasicSchedule 2011-08-01 21:06:05,778 ERROR javax.jms.MessageFormatException: Only objectified primitive objects, String, Map and List types are allowed but was: com.abc.engine.ejb.BasicSchedule@1003b2df type: class c om.abc.engine.ejb.BasicSchedule 2011-08-01 21:06:05,778 ERROR at org.apache.activemq.command.ActiveMQMessage.checkValidObject(ActiveMQMessage.java:468) 2011-08-01 21:06:05,778 ERROR at org.apache.activemq.command.ActiveMQMapMessage.setObject(ActiveMQMapMessage.java:705) 2011-08-01 21:06:05,778 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.initMessage(ChronicleMessageBean.java:149) 2011-08-01 21:06:05,778 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.send(ChronicleMessageBean.java:125) 2011-08-01 21:06:05,778 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.onMessage(ChronicleMessageBean.java:77)


Although I haven't checked it, but looking at the source code it seems like you hit this exception when ActiveMQ validates message properties, not the body. The JavaDoc for ObjectMessage reads:

Only Serializable Java objects can be used.

I used all sorts of Java objects with ActiveMQ (arbitrary complex) and it always worked. However when you set message properties (Message#setObjectProperty):

Note that this method works only for the objectified primitive object types (Integer, Double, Long ...) and String objects.

Inspecting the ActiveMQ codebase quoted above it looks like you are trying to use message object properties to send complex Java objects. This abuses the concept of message properties, which should be simple metadata like ids or peer names.

Also it looks like ActiveMQ optionally supports Map and List, but it this is vendor specific.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜