diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index 95f8c4234c7..02ef08585d0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -761,6 +761,10 @@ private MethodInvocationGateway doCreateMethodInvocationGateway(Method method, MethodInvocationGateway gateway = new MethodInvocationGateway(messageMapper); gateway.setupReturnType(this.serviceInterface, method); + if (method.getParameterTypes().length == 0 && !findPayloadExpression(method)) { + gateway.setPollable(); + } + JavaUtils.INSTANCE .acceptIfNotNull(payloadExpression, messageMapper::setPayloadExpression) .acceptIfNotNull(getTaskScheduler(), gateway::setTaskScheduler); @@ -941,15 +945,18 @@ private static final class MethodInvocationGateway extends MessagingGatewaySuppo private boolean isVoidReturn; + private boolean pollable; + MethodInvocationGateway(GatewayMethodInboundMessageMapper messageMapper) { setRequestMapper(messageMapper); } @Override public IntegrationPatternType getIntegrationPatternType() { - return this.isVoidReturn - ? IntegrationPatternType.inbound_channel_adapter - : IntegrationPatternType.inbound_gateway; + return this.pollable ? IntegrationPatternType.outbound_channel_adapter + : this.isVoidReturn + ? IntegrationPatternType.inbound_channel_adapter + : IntegrationPatternType.inbound_gateway; } @Nullable @@ -992,6 +999,11 @@ private boolean isVoidReturnType(ResolvableType resolvableType) { } return Void.class.isAssignableFrom(returnTypeToCheck); } + + private void setPollable() { + this.pollable = true; + } + } private final class Invoker implements Supplier { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java index e21ce82121c..3911646023a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java @@ -31,7 +31,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.BeanFactory; @@ -43,6 +43,7 @@ import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.GenericConversionService; import org.springframework.expression.common.LiteralExpression; +import org.springframework.integration.IntegrationPatternType; import org.springframework.integration.annotation.Gateway; import org.springframework.integration.annotation.GatewayHeader; import org.springframework.integration.channel.DirectChannel; @@ -56,6 +57,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.support.GenericMessage; +import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; /** @@ -156,6 +158,11 @@ public void testReceiveMessage() { Message message = service.getMessage(); assertThat(message).isNotNull(); assertThat(message.getPayload()).isEqualTo("foo"); + + MessagingGatewaySupport messagingGatewaySupport = + proxyFactory.getGateways().get(ClassUtils.getMethod(TestService.class, "getMessage")); + assertThat(messagingGatewaySupport.getIntegrationPatternType()) + .isEqualTo(IntegrationPatternType.outbound_channel_adapter); } @Test @@ -259,6 +266,12 @@ public void testNoArgMethodWithPayloadAnnotation() { TestService service = (TestService) proxyFactory.getObject(); String result = service.requestReplyWithPayloadAnnotation(); assertThat(result).isEqualTo("requestReplyWithPayloadAnnotation0bar"); + + MessagingGatewaySupport messagingGatewaySupport = + proxyFactory.getGateways() + .get(ClassUtils.getMethod(TestService.class, "requestReplyWithPayloadAnnotation")); + assertThat(messagingGatewaySupport.getIntegrationPatternType()) + .isEqualTo(IntegrationPatternType.inbound_gateway); } @Test