Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send Map Object using JMS Citrus #1205

Open
npapageorgopoulos12 opened this issue Aug 21, 2024 · 4 comments
Open

Send Map Object using JMS Citrus #1205

npapageorgopoulos12 opened this issue Aug 21, 2024 · 4 comments
Labels
Prio: Medium State: To discuss In case there are open questions concerning the issue Type: Bug Type: Question

Comments

@npapageorgopoulos12
Copy link

npapageorgopoulos12 commented Aug 21, 2024

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

@bbortt bbortt added State: To discuss In case there are open questions concerning the issue Type: Bug Type: Question Prio: Medium labels Aug 31, 2024
@bbortt
Copy link
Collaborator

bbortt commented Aug 31, 2024

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... 😉

@npapageorgopoulos12
Copy link
Author

npapageorgopoulos12 commented Sep 2, 2024

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 ?

@christophd
Copy link
Member

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.

@npapageorgopoulos12
Copy link
Author

How do I implement the MessageConverter inside the MessagePayloadBuilder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prio: Medium State: To discuss In case there are open questions concerning the issue Type: Bug Type: Question
Projects
None yet
Development

No branches or pull requests

3 participants