INT-4092: Add errorChannel Header with Void Return
JIRA: https://jira.spring.io/browse/INT-4092 Polishing Polishing Polish of Polishing
This commit is contained in:
committed by
Artem Bilan
parent
52904c7106
commit
9f40d896a2
@@ -90,6 +90,8 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
|
||||
private final Map<String, Expression> globalHeaderExpressions;
|
||||
|
||||
private final Map<String, Object> headers;
|
||||
|
||||
private final List<MethodParameter> parameterList;
|
||||
|
||||
private final MethodArgsMessageMapper argsMapper;
|
||||
@@ -115,9 +117,17 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
GatewayMethodInboundMessageMapper(Method method, Map<String, Expression> headerExpressions,
|
||||
Map<String, Expression> globalHeaderExpressions, MethodArgsMessageMapper mapper,
|
||||
MessageBuilderFactory messageBuilderFactory) {
|
||||
this(method, headerExpressions, globalHeaderExpressions, null, mapper, messageBuilderFactory);
|
||||
}
|
||||
|
||||
GatewayMethodInboundMessageMapper(Method method, Map<String, Expression> headerExpressions,
|
||||
Map<String, Expression> globalHeaderExpressions, Map<String, Object> headers,
|
||||
MethodArgsMessageMapper mapper,
|
||||
MessageBuilderFactory messageBuilderFactory) {
|
||||
Assert.notNull(method, "method must not be null");
|
||||
this.method = method;
|
||||
this.headerExpressions = headerExpressions;
|
||||
this.headers = headers;
|
||||
this.globalHeaderExpressions = globalHeaderExpressions;
|
||||
this.parameterList = getMethodParameterList(method);
|
||||
this.payloadExpression = parsePayloadExpression(method);
|
||||
@@ -354,6 +364,9 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper<Object[]
|
||||
GatewayMethodInboundMessageMapper.this.globalHeaderExpressions);
|
||||
builder.copyHeadersIfAbsent(evaluatedHeaders);
|
||||
}
|
||||
if (GatewayMethodInboundMessageMapper.this.headers != null) {
|
||||
builder.copyHeadersIfAbsent(GatewayMethodInboundMessageMapper.this.headers);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.springframework.integration.support.management.TrackableComponent;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.core.DestinationResolver;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
@@ -549,10 +550,17 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Object> headers = null;
|
||||
// We don't want to eagerly resolve the error channel here
|
||||
Object errorChannel = this.errorChannel == null ? this.errorChannelName : this.errorChannel;
|
||||
if (errorChannel != null && method.getReturnType().equals(void.class)) {
|
||||
headers = new HashMap<>();
|
||||
headers.put(MessageHeaders.ERROR_CHANNEL, errorChannel);
|
||||
}
|
||||
GatewayMethodInboundMessageMapper messageMapper = new GatewayMethodInboundMessageMapper(method,
|
||||
headerExpressions,
|
||||
this.globalMethodMetadata != null ? this.globalMethodMetadata.getHeaderExpressions() : null,
|
||||
this.argsMapper, this.getMessageBuilderFactory());
|
||||
headers, this.argsMapper, this.getMessageBuilderFactory());
|
||||
if (StringUtils.hasText(payloadExpression)) {
|
||||
messageMapper.setPayloadExpression(payloadExpression);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -133,6 +134,7 @@ public class GatewayInterfaceTests {
|
||||
equalTo("public abstract void org.springframework.integration.gateway.GatewayInterfaceTests$Foo.foo(java.lang.String)"));
|
||||
assertThat((Method) message.getHeaders().get("object"), equalTo(fooMethod));
|
||||
assertThat((String) message.getPayload(), equalTo("hello"));
|
||||
assertThat(new MessageHeaderAccessor(message).getErrorChannel(), equalTo("errorChannel"));
|
||||
called.set(true);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user