From da5d2ca4ebb7c00b3fc7fafed547f45d53c1accd Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 5 May 2022 12:40:10 -0400 Subject: [PATCH] GH-3788 Support byte[] for JMS properties mapping Fixes https://github.com/spring-projects/spring-integration/issues/3788 Some JMS vendors carry some important information in their JMS messages. That information can be stored in the specific properties as `byte[]`. * Add `byte[]` as a supported property type into a `DefaultJmsHeaderMapper` * Verify `byte[]` property mapping and propagation via embedded ActiveMQ broker. **Cherry-pick to `5.5.x`** --- .../jms/DefaultJmsHeaderMapper.java | 7 ++++--- .../jms/JmsOutboundChannelAdapterTests.java | 20 +++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/DefaultJmsHeaderMapper.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/DefaultJmsHeaderMapper.java index 1e0b054bef..f2cf657ce2 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/DefaultJmsHeaderMapper.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/DefaultJmsHeaderMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,8 +57,9 @@ import org.springframework.util.StringUtils; */ public class DefaultJmsHeaderMapper extends JmsHeaderMapper { - private static final List> SUPPORTED_PROPERTY_TYPES = Arrays.asList(new Class[]{ - Boolean.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class, String.class }); + private static final List> SUPPORTED_PROPERTY_TYPES = + Arrays.asList(Boolean.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class, + String.class, byte[].class); private static final Log LOGGER = LogFactory.getLog(DefaultJmsHeaderMapper.class); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundChannelAdapterTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundChannelAdapterTests.java index acec3c7fdb..a2c115f4ae 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundChannelAdapterTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundChannelAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,10 @@ package org.springframework.integration.jms; import static org.assertj.core.api.Assertions.assertThat; +import jakarta.jms.JMSException; +import jakarta.jms.Message; +import jakarta.jms.TextMessage; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -43,11 +47,19 @@ public class JmsOutboundChannelAdapterTests extends ActiveMQMultiContextTests { private JmsMessageDrivenEndpoint endpoint; @Test - public void testTransactionalSend() { + public void testTransactionalSend() throws JMSException { JmsTemplate template = new JmsTemplate(connectionFactory); - template.convertAndSend("outcatQ1", "Hello, world!"); + template.send("outcatQ1", + session -> { + TextMessage textMessage = + session.createTextMessage("Hello, world!"); + textMessage.setObjectProperty("bytesProperty", "testValue".getBytes()); + return textMessage; + }); template.setReceiveTimeout(20000); - assertThat(template.receive("outcatQ2")).isNotNull(); + Message receive = template.receive("outcatQ2"); + assertThat(receive).isNotNull(); + assertThat(receive.getObjectProperty("bytesProperty")).isEqualTo("testValue".getBytes()); this.aborter.abort = true; template.convertAndSend("outcatQ1", "Hello, world!");