diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java
index ee4ff131b96..d1c1c6a42ca 100644
--- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java
+++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2022 the original author or authors.
+ * Copyright 2002-2023 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,8 +18,7 @@
import java.lang.reflect.Field;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.amqp.core.Address;
@@ -40,11 +39,11 @@
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.isNull;
/**
@@ -55,8 +54,7 @@
*
* @since 2.1
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitConfig
@DirtiesContext
public class AmqpInboundGatewayParserTests {
@@ -66,16 +64,16 @@ public class AmqpInboundGatewayParserTests {
@Test
public void customMessageConverter() {
Object gateway = context.getBean("gateway");
- MessageConverter gatewayConverter = TestUtils.getPropertyValue(gateway, "amqpMessageConverter", MessageConverter.class);
- MessageConverter templateConverter = TestUtils.getPropertyValue(gateway, "amqpTemplate.messageConverter", MessageConverter.class);
+ MessageConverter gatewayConverter =
+ TestUtils.getPropertyValue(gateway, "amqpMessageConverter", MessageConverter.class);
+ MessageConverter templateConverter =
+ TestUtils.getPropertyValue(gateway, "amqpTemplate.messageConverter", MessageConverter.class);
TestConverter testConverter = context.getBean("testConverter", TestConverter.class);
assertThat(gatewayConverter).isSameAs(testConverter);
assertThat(templateConverter).isSameAs(testConverter);
assertThat(TestUtils.getPropertyValue(gateway, "autoStartup")).isEqualTo(Boolean.TRUE);
assertThat(TestUtils.getPropertyValue(gateway, "phase")).isEqualTo(0);
- assertThat(TestUtils.getPropertyValue(gateway, "replyTimeout", Long.class)).isEqualTo(Long.valueOf(1234L));
- assertThat(TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout", Long.class))
- .isEqualTo(Long.valueOf(1234L));
+ assertThat(TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout")).isEqualTo(1234L);
assertThat(TestUtils.getPropertyValue(gateway, "messageListenerContainer.missingQueuesFatal", Boolean.class))
.isTrue();
}
@@ -145,14 +143,12 @@ public void verifyUsageWithHeaderMapper() throws Exception {
@Test
public void testInt2971HeaderMapperAndMappedHeadersExclusivity() {
- try {
- new ClassPathXmlApplicationContext("AmqpInboundGatewayParserTests-headerMapper-fail-context.xml",
- this.getClass()).close();
- }
- catch (BeanDefinitionParsingException e) {
- assertThat(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
- "is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'")).isTrue();
- }
+ assertThatExceptionOfType(BeanDefinitionParsingException.class)
+ .isThrownBy(() ->
+ new ClassPathXmlApplicationContext("AmqpInboundGatewayParserTests-headerMapper-fail-context.xml",
+ getClass()))
+ .withMessageStartingWith("Configuration problem: The 'header-mapper' attribute " +
+ "is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'");
}
private static class TestConverter extends SimpleMessageConverter {
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationProperties.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationProperties.java
index 8cf47678aa7..6af3f6de76c 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationProperties.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2022 the original author or authors.
+ * Copyright 2014-2023 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.
@@ -37,6 +37,7 @@
*
{@code spring.integration.endpoints.noAutoStartup=}
* {@code spring.integration.channels.error.requireSubscribers=true}
* {@code spring.integration.channels.error.ignoreFailures=true}
+ * {@code spring.integration.endpoints.defaultTimeout=30000}
*
*
* @author Artem Bilan
@@ -112,6 +113,12 @@ public final class IntegrationProperties {
*/
public static final String ENDPOINTS_NO_AUTO_STARTUP = INTEGRATION_PROPERTIES_PREFIX + "endpoints.noAutoStartup";
+ /**
+ * Specifies the default timeout for blocking operations like send and receive messages.
+ * @since 6.2
+ */
+ public static final String ENDPOINTS_DEFAULT_TIMEOUT = INTEGRATION_PROPERTIES_PREFIX + "endpoints.defaultTimeout";
+
private static final Properties DEFAULTS;
private boolean channelsAutoCreate = true;
@@ -132,6 +139,8 @@ public final class IntegrationProperties {
private String[] noAutoStartupEndpoints = {};
+ private long endpointsDefaultTimeout = IntegrationContextUtils.DEFAULT_TIMEOUT;
+
private volatile Properties properties;
static {
@@ -293,6 +302,23 @@ public String[] getNoAutoStartupEndpoints() {
return Arrays.copyOf(this.noAutoStartupEndpoints, this.noAutoStartupEndpoints.length);
}
+ /**
+ * Return the value of {@link #ENDPOINTS_DEFAULT_TIMEOUT} option.
+ * @return the value of {@link #ENDPOINTS_DEFAULT_TIMEOUT} option.
+ * @since 6.2
+ */
+ public long getEndpointsDefaultTimeout() {
+ return this.endpointsDefaultTimeout;
+ }
+
+ /**
+ * Configure a value for {@link #ENDPOINTS_DEFAULT_TIMEOUT} option.
+ * @param endpointsDefaultTimeout the value for {@link #ENDPOINTS_DEFAULT_TIMEOUT} option.
+ */
+ public void setEndpointsDefaultTimeout(long endpointsDefaultTimeout) {
+ this.endpointsDefaultTimeout = endpointsDefaultTimeout;
+ }
+
/**
* Represent the current instance as a {@link Properties}.
* @return the {@link Properties} representation.
@@ -312,6 +338,7 @@ public Properties toProperties() {
props.setProperty(READ_ONLY_HEADERS, StringUtils.arrayToCommaDelimitedString(this.readOnlyHeaders));
props.setProperty(ENDPOINTS_NO_AUTO_STARTUP,
StringUtils.arrayToCommaDelimitedString(this.noAutoStartupEndpoints));
+ props.setProperty(ENDPOINTS_DEFAULT_TIMEOUT, "" + this.endpointsDefaultTimeout);
this.properties = props;
}
@@ -348,7 +375,9 @@ public static IntegrationProperties parse(Properties properties) {
StringUtils.commaDelimitedListToStringArray(value)))
.acceptIfHasText(properties.getProperty(ENDPOINTS_NO_AUTO_STARTUP),
(value) -> integrationProperties.setNoAutoStartupEndpoints(
- StringUtils.commaDelimitedListToStringArray(value)));
+ StringUtils.commaDelimitedListToStringArray(value)))
+ .acceptIfHasText(properties.getProperty(ENDPOINTS_DEFAULT_TIMEOUT),
+ (value) -> integrationProperties.setEndpointsDefaultTimeout(Long.parseLong(value)));
return integrationProperties;
}
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java
index 98c4f9e86cf..dfd358fc23f 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java
@@ -35,7 +35,6 @@
import org.springframework.integration.IntegrationPatternType;
import org.springframework.integration.MessageTimeoutException;
import org.springframework.integration.channel.ReactiveStreamsSubscribableChannel;
-import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.endpoint.EventDrivenConsumer;
@@ -124,7 +123,9 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint
private String errorChannelName;
- private long replyTimeout = IntegrationContextUtils.DEFAULT_TIMEOUT;
+ private boolean requestTimeoutSet;
+
+ private boolean replyTimeoutSet;
private InboundMessageMapper