citrusframework/citrus

Send Map Object using JMS Citrus

Opened this issue · 4 comments

Citrus Version
4.1.0

Question
I am trying to test integration of components and on the other end, i receive this error:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object with class 'java.lang.String' to class 'java.util.Map'
What I've tried so far
I ve tried adding the following parameters when sending the message:

  • .body(marshal(payload,objectMapper))
  • .header("_type", Map.class))
  • .type(MessageType.JSON)
  • and also tried the bellow using MessagePayloadBuilder, where i got error Caused by: jakarta.jms.MessageFormatException: Only objectified primitive objects and String types are allowed... type: class java.util.ArrayList
.body(new MessagePayloadBuilder() {
        @Override
        public Object buildPayload(TestContext testContext) {
            return payloadMap;
        }
    })

Additional Info
They payload is a Map with nested ArrayLists

sorry, I do not quit understand your issue and am trying to grasp it fully. would you mind answering me some questions?

[...] on the other end, i receive this error:

what do you mean by "the other end"? I understand that the JMS message has been sent, but cannot be received?

how are you sending the payload? are you marshalling the map in any way?

and of course, the best way would be to have a reproducer available... 😉

Thank you for your response

To clarify:

  1. What I mean by "the other end":
    I am referring to the application that is receiving the message. This application uses the Qpid protonj2
    protocol and requires messages with a Map type payload.

  2. How I am sending the payload:
    I am attempting to send a Map with nested ArrayLists as the payload. I have tried marshalling the Map object using:

.body(marshal(payload, objectMapper))
.header("_type", Map.class))
.type(MessageType.JSON)

Given that the receiving application requires a Map type payload, is there a way to properly send such a payload using Citrus? Is there a specific approach or configuration I should use to meet the requirements of the Qpid Proton-J2 ?

So the JMS message converter in Citrus creates JMS text, map or object messages based on the message payload type (see https://github.com/citrusframework/citrus/blob/main/endpoints/citrus-jms/src/main/java/org/citrusframework/jms/message/JmsMessageConverter.java#L151)

It should create a JMS MapMessage when the message payload is a Map.

I believe this is only working with simple key value pairs of type String so nested ArrayLists may be a problem. But you can also create the JMS MapMessage directly, for instance by using the MessagePayloadBuilder approach. The JMS message converter will then just use your custom JMS MapMessage and send it.

Also you could try to set the Map as an object and specify useObjectMessages=true on the JMS endpoint in Citrus. This makes the message converter use a JMS object message with the specified map.

How do I implement the MessageConverter inside the MessagePayloadBuilder