Skip to content

Commit cab16c4

Browse files
garyrussellartembilan
authored andcommitted
GH-3395: Fix XML expression default for ARFOGateway
Resolves #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`**
1 parent e649480 commit cab16c4

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileOutboundGatewayParser.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,9 +58,7 @@ protected BeanDefinitionBuilder parseHandler(Element element, ParserContext pars
5858
}
5959
else {
6060
builder.addConstructorArgValue(element.getAttribute("command"));
61-
if (element.hasAttribute(EXPRESSION_ATTRIBUTE)) {
62-
builder.addConstructorArgValue(element.getAttribute(EXPRESSION_ATTRIBUTE));
63-
}
61+
builder.addConstructorArgValue(element.getAttribute(EXPRESSION_ATTRIBUTE));
6462
}
6563
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "command-options", "options");
6664
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout", "sendTimeout");

spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,23 @@ public AbstractRemoteFileOutboundGateway(RemoteFileTemplate<F> remoteFileTemplat
187187
* 'get' etc), and an expression to determine the filename.
188188
* @param remoteFileTemplate the remote file template.
189189
* @param command the command.
190-
* @param expression the filename expression.
190+
* @param expressionArg the filename expression.
191191
*/
192192
public AbstractRemoteFileOutboundGateway(RemoteFileTemplate<F> remoteFileTemplate, Command command,
193-
@Nullable String expression) {
193+
@Nullable String expressionArg) {
194194

195195
Assert.notNull(remoteFileTemplate, "'remoteFileTemplate' cannot be null");
196196
this.remoteFileTemplate = remoteFileTemplate;
197197
this.command = command;
198-
if (expression == null) {
199-
Assert.state(Command.LS.equals(this.command)
200-
|| Command.NLST.equals(this.command)
201-
|| Command.PUT.equals(this.command)
202-
|| Command.MPUT.equals(this.command),
203-
"Only LS, NLST, PUT and MPUT commands can rely on the working directory.\n" +
204-
"All other commands must be supplied with the filename expression");
198+
String expression = expressionArg;
199+
boolean expressionNeeded = !(Command.LS.equals(this.command)
200+
|| Command.NLST.equals(this.command)
201+
|| Command.PUT.equals(this.command)
202+
|| Command.MPUT.equals(this.command));
203+
if (!StringUtils.hasText(expression) && expressionNeeded) {
204+
expression = "payload";
205+
}
206+
if (!StringUtils.hasText(expression)) {
205207
this.fileNameProcessor = null;
206208
}
207209
else {

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/SftpOutboundGatewayParserTests-context.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,26 @@
113113

114114
<int:channel id="outbound"/>
115115

116+
<int-sftp:outbound-gateway id="noExpressionLS"
117+
request-channel="nullChannel"
118+
reply-channel="nullChannel"
119+
session-factory="sf"
120+
remote-directory="."
121+
command="ls" />
122+
123+
<int-sftp:outbound-gateway id="noExpressionPUT"
124+
request-channel="nullChannel"
125+
reply-channel="nullChannel"
126+
session-factory="sf"
127+
remote-directory="."
128+
command="put" />
129+
130+
<int-sftp:outbound-gateway id="noExpressionGET"
131+
request-channel="nullChannel"
132+
reply-channel="nullChannel"
133+
session-factory="sf"
134+
remote-directory="."
135+
local-directory="."
136+
command="get" />
137+
116138
</beans>

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/SftpOutboundGatewayParserTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ public class SftpOutboundGatewayParserTests {
6969
@Autowired
7070
AbstractEndpoint advised;
7171

72+
@Autowired
73+
AbstractEndpoint noExpressionLS;
74+
75+
@Autowired
76+
AbstractEndpoint noExpressionPUT;
77+
78+
@Autowired
79+
AbstractEndpoint noExpressionGET;
80+
7281
@Autowired
7382
FileNameGenerator generator;
7483

@@ -165,6 +174,14 @@ public void advised() {
165174
assertThat(adviceCalled).isEqualTo(1);
166175
}
167176

177+
@Test
178+
void noExpression() {
179+
assertThat(TestUtils.getPropertyValue(this.noExpressionLS, "handler.fileNameProcessor")).isNull();
180+
assertThat(TestUtils.getPropertyValue(this.noExpressionPUT, "handler.fileNameProcessor")).isNull();
181+
assertThat(TestUtils.getPropertyValue(this.noExpressionGET,
182+
"handler.fileNameProcessor.expression.expression")).isEqualTo("payload");
183+
}
184+
168185
public static class FooAdvice extends AbstractRequestHandlerAdvice {
169186

170187
@Override

0 commit comments

Comments
 (0)