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`**
This commit is contained in:
Artem Bilan
2022-05-05 12:40:10 -04:00
committed by Gary Russell
parent 78142fc62e
commit da5d2ca4eb
2 changed files with 20 additions and 7 deletions

View File

@@ -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<Class<?>> 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<Class<?>> 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);

View File

@@ -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!");