Skip to content

GH-3120: Identify polling MG as outbound-CA #3122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Object> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -156,6 +158,11 @@ public void testReceiveMessage() {
Message<String> 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
Expand Down Expand Up @@ -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
Expand Down