Skip to content

Commit da5d2ca

Browse files
artembilangaryrussell
authored andcommitted
GH-3788 Support byte[] for JMS properties mapping
Fixes #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`**
1 parent 78142fc commit da5d2ca

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

spring-integration-jms/src/main/java/org/springframework/integration/jms/DefaultJmsHeaderMapper.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,8 +57,9 @@
5757
*/
5858
public class DefaultJmsHeaderMapper extends JmsHeaderMapper {
5959

60-
private static final List<Class<?>> SUPPORTED_PROPERTY_TYPES = Arrays.asList(new Class<?>[]{
61-
Boolean.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class, String.class });
60+
private static final List<Class<?>> SUPPORTED_PROPERTY_TYPES =
61+
Arrays.asList(Boolean.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class,
62+
String.class, byte[].class);
6263

6364

6465
private static final Log LOGGER = LogFactory.getLog(DefaultJmsHeaderMapper.class);

spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundChannelAdapterTests.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,10 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020

21+
import jakarta.jms.JMSException;
22+
import jakarta.jms.Message;
23+
import jakarta.jms.TextMessage;
24+
2125
import org.junit.jupiter.api.Test;
2226

2327
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,11 +47,19 @@ public class JmsOutboundChannelAdapterTests extends ActiveMQMultiContextTests {
4347
private JmsMessageDrivenEndpoint endpoint;
4448

4549
@Test
46-
public void testTransactionalSend() {
50+
public void testTransactionalSend() throws JMSException {
4751
JmsTemplate template = new JmsTemplate(connectionFactory);
48-
template.convertAndSend("outcatQ1", "Hello, world!");
52+
template.send("outcatQ1",
53+
session -> {
54+
TextMessage textMessage =
55+
session.createTextMessage("Hello, world!");
56+
textMessage.setObjectProperty("bytesProperty", "testValue".getBytes());
57+
return textMessage;
58+
});
4959
template.setReceiveTimeout(20000);
50-
assertThat(template.receive("outcatQ2")).isNotNull();
60+
Message receive = template.receive("outcatQ2");
61+
assertThat(receive).isNotNull();
62+
assertThat(receive.getObjectProperty("bytesProperty")).isEqualTo("testValue".getBytes());
5163

5264
this.aborter.abort = true;
5365
template.convertAndSend("outcatQ1", "Hello, world!");

0 commit comments

Comments
 (0)