GH-3395: Fix XML expression default for ARFOGateway
Resolves https://github.com/spring-projects/spring-integration/issues/3395 Outbound remote file gateway parser requires `expression` even though some commands don't need or use it. * Propagate the empty string for `expression` attribute * Fix default (`payload`) expression logic in the `AbstractRemoteFileOutboundGateway` **Cherry-pick to `5.3.x`**
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -58,9 +58,7 @@ public abstract class AbstractRemoteFileOutboundGatewayParser extends AbstractCo
|
||||
}
|
||||
else {
|
||||
builder.addConstructorArgValue(element.getAttribute("command"));
|
||||
if (element.hasAttribute(EXPRESSION_ATTRIBUTE)) {
|
||||
builder.addConstructorArgValue(element.getAttribute(EXPRESSION_ATTRIBUTE));
|
||||
}
|
||||
builder.addConstructorArgValue(element.getAttribute(EXPRESSION_ATTRIBUTE));
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "command-options", "options");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout", "sendTimeout");
|
||||
|
||||
@@ -187,21 +187,23 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
* 'get' etc), and an expression to determine the filename.
|
||||
* @param remoteFileTemplate the remote file template.
|
||||
* @param command the command.
|
||||
* @param expression the filename expression.
|
||||
* @param expressionArg the filename expression.
|
||||
*/
|
||||
public AbstractRemoteFileOutboundGateway(RemoteFileTemplate<F> remoteFileTemplate, Command command,
|
||||
@Nullable String expression) {
|
||||
@Nullable String expressionArg) {
|
||||
|
||||
Assert.notNull(remoteFileTemplate, "'remoteFileTemplate' cannot be null");
|
||||
this.remoteFileTemplate = remoteFileTemplate;
|
||||
this.command = command;
|
||||
if (expression == null) {
|
||||
Assert.state(Command.LS.equals(this.command)
|
||||
|| Command.NLST.equals(this.command)
|
||||
|| Command.PUT.equals(this.command)
|
||||
|| Command.MPUT.equals(this.command),
|
||||
"Only LS, NLST, PUT and MPUT commands can rely on the working directory.\n" +
|
||||
"All other commands must be supplied with the filename expression");
|
||||
String expression = expressionArg;
|
||||
boolean expressionNeeded = !(Command.LS.equals(this.command)
|
||||
|| Command.NLST.equals(this.command)
|
||||
|| Command.PUT.equals(this.command)
|
||||
|| Command.MPUT.equals(this.command));
|
||||
if (!StringUtils.hasText(expression) && expressionNeeded) {
|
||||
expression = "payload";
|
||||
}
|
||||
if (!StringUtils.hasText(expression)) {
|
||||
this.fileNameProcessor = null;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -113,4 +113,26 @@
|
||||
|
||||
<int:channel id="outbound"/>
|
||||
|
||||
<int-sftp:outbound-gateway id="noExpressionLS"
|
||||
request-channel="nullChannel"
|
||||
reply-channel="nullChannel"
|
||||
session-factory="sf"
|
||||
remote-directory="."
|
||||
command="ls" />
|
||||
|
||||
<int-sftp:outbound-gateway id="noExpressionPUT"
|
||||
request-channel="nullChannel"
|
||||
reply-channel="nullChannel"
|
||||
session-factory="sf"
|
||||
remote-directory="."
|
||||
command="put" />
|
||||
|
||||
<int-sftp:outbound-gateway id="noExpressionGET"
|
||||
request-channel="nullChannel"
|
||||
reply-channel="nullChannel"
|
||||
session-factory="sf"
|
||||
remote-directory="."
|
||||
local-directory="."
|
||||
command="get" />
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -69,6 +69,15 @@ public class SftpOutboundGatewayParserTests {
|
||||
@Autowired
|
||||
AbstractEndpoint advised;
|
||||
|
||||
@Autowired
|
||||
AbstractEndpoint noExpressionLS;
|
||||
|
||||
@Autowired
|
||||
AbstractEndpoint noExpressionPUT;
|
||||
|
||||
@Autowired
|
||||
AbstractEndpoint noExpressionGET;
|
||||
|
||||
@Autowired
|
||||
FileNameGenerator generator;
|
||||
|
||||
@@ -165,6 +174,14 @@ public class SftpOutboundGatewayParserTests {
|
||||
assertThat(adviceCalled).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noExpression() {
|
||||
assertThat(TestUtils.getPropertyValue(this.noExpressionLS, "handler.fileNameProcessor")).isNull();
|
||||
assertThat(TestUtils.getPropertyValue(this.noExpressionPUT, "handler.fileNameProcessor")).isNull();
|
||||
assertThat(TestUtils.getPropertyValue(this.noExpressionGET,
|
||||
"handler.fileNameProcessor.expression.expression")).isEqualTo("payload");
|
||||
}
|
||||
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user