Search code examples
activemq-artemis

getObjectProperty not working the same in Artemis as Classic?


I'm aware that this method was unsafe in ActiveMQ Classic from a security perspective. However, using ActiveMQ Artemis v2.32.0 with ActiveMQ Classic 5.16.0 client results in an ClassCastException when trying to:

Map<String, String> map = genericCast(message.getObjectProperty(key))

It cannot cast String to a Map.

The existing client code works completely fine when interacting with a Classic broker.

I'm not sure if this is expected behavior, but I could not find it explicitly documented. If not expected behavior, I can look further to see if I can write a test case for it.


Solution

  • You're seeing the expected behavior. As noted in the JavaDoc for Message:

    The getObjectProperty method only returns values of class Boolean, Byte, Short, Integer, Long, Float, Double, and String.

    Notice that this doesn't include Map.

    The ability of ActiveMQ Classic to support this kind of behavior is an extension that was not carried into ActiveMQ Artemis.

    Generally speaking extensions like this aren't a great idea because they entice developers to break application portability. In many cases this is a short-term gain for a long-term loss.

    In this specific case the message itself can act as a kind of Map since you can set key/value pairs of various types so there's likely no real need to set a Map as a property in the first place.