Skip to content

Commit bc8e775

Browse files
committed
GH-3120: Identify polling MG as outbound-CA
Fixes #3120 The messaging gateway method without arguments works as a polling channel adapter. In this case a Messaging Gateway component is present in the end of flow. Therefore we treat it as an `outbound_channel_adapter`
1 parent 948f5a3 commit bc8e775

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,10 @@ private MethodInvocationGateway doCreateMethodInvocationGateway(Method method,
761761
MethodInvocationGateway gateway = new MethodInvocationGateway(messageMapper);
762762
gateway.setupReturnType(this.serviceInterface, method);
763763

764+
if (method.getParameterTypes().length == 0 && !findPayloadExpression(method)) {
765+
gateway.setPollable();
766+
}
767+
764768
JavaUtils.INSTANCE
765769
.acceptIfNotNull(payloadExpression, messageMapper::setPayloadExpression)
766770
.acceptIfNotNull(getTaskScheduler(), gateway::setTaskScheduler);
@@ -941,15 +945,18 @@ private static final class MethodInvocationGateway extends MessagingGatewaySuppo
941945

942946
private boolean isVoidReturn;
943947

948+
private boolean pollable;
949+
944950
MethodInvocationGateway(GatewayMethodInboundMessageMapper messageMapper) {
945951
setRequestMapper(messageMapper);
946952
}
947953

948954
@Override
949955
public IntegrationPatternType getIntegrationPatternType() {
950-
return this.isVoidReturn
951-
? IntegrationPatternType.inbound_channel_adapter
952-
: IntegrationPatternType.inbound_gateway;
956+
return this.pollable ? IntegrationPatternType.outbound_channel_adapter
957+
: this.isVoidReturn
958+
? IntegrationPatternType.inbound_channel_adapter
959+
: IntegrationPatternType.inbound_gateway;
953960
}
954961

955962
@Nullable
@@ -992,6 +999,11 @@ private boolean isVoidReturnType(ResolvableType resolvableType) {
992999
}
9931000
return Void.class.isAssignableFrom(returnTypeToCheck);
9941001
}
1002+
1003+
private void setPollable() {
1004+
this.pollable = true;
1005+
}
1006+
9951007
}
9961008

9971009
private final class Invoker implements Supplier<Object> {

spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.concurrent.Executors;
3232
import java.util.concurrent.TimeUnit;
3333

34-
import org.junit.Test;
34+
import org.junit.jupiter.api.Test;
3535
import org.mockito.Mockito;
3636

3737
import org.springframework.beans.factory.BeanFactory;
@@ -43,6 +43,7 @@
4343
import org.springframework.core.convert.support.DefaultConversionService;
4444
import org.springframework.core.convert.support.GenericConversionService;
4545
import org.springframework.expression.common.LiteralExpression;
46+
import org.springframework.integration.IntegrationPatternType;
4647
import org.springframework.integration.annotation.Gateway;
4748
import org.springframework.integration.annotation.GatewayHeader;
4849
import org.springframework.integration.channel.DirectChannel;
@@ -56,6 +57,7 @@
5657
import org.springframework.messaging.PollableChannel;
5758
import org.springframework.messaging.handler.annotation.Header;
5859
import org.springframework.messaging.support.GenericMessage;
60+
import org.springframework.util.ClassUtils;
5961
import org.springframework.util.ReflectionUtils;
6062

6163
/**
@@ -156,6 +158,11 @@ public void testReceiveMessage() {
156158
Message<String> message = service.getMessage();
157159
assertThat(message).isNotNull();
158160
assertThat(message.getPayload()).isEqualTo("foo");
161+
162+
MessagingGatewaySupport messagingGatewaySupport =
163+
proxyFactory.getGateways().get(ClassUtils.getMethod(TestService.class, "getMessage"));
164+
assertThat(messagingGatewaySupport.getIntegrationPatternType())
165+
.isEqualTo(IntegrationPatternType.outbound_channel_adapter);
159166
}
160167

161168
@Test
@@ -259,6 +266,12 @@ public void testNoArgMethodWithPayloadAnnotation() {
259266
TestService service = (TestService) proxyFactory.getObject();
260267
String result = service.requestReplyWithPayloadAnnotation();
261268
assertThat(result).isEqualTo("requestReplyWithPayloadAnnotation0bar");
269+
270+
MessagingGatewaySupport messagingGatewaySupport =
271+
proxyFactory.getGateways()
272+
.get(ClassUtils.getMethod(TestService.class, "requestReplyWithPayloadAnnotation"));
273+
assertThat(messagingGatewaySupport.getIntegrationPatternType())
274+
.isEqualTo(IntegrationPatternType.inbound_gateway);
262275
}
263276

264277
@Test

0 commit comments

Comments
 (0)