INT-2981 - Add Rename (mv) to (S)FTP Gateway

* (S)FTP Change Commands, Options to Enums
* INT-2981 Add Support For 'mv' To File/Remote/GW
* INT-2981 (S)FTP Namespace Support and Docs
* INT-2981 Create Remote Dirs if Needed
* INT-2981 Add 'mv' Command to What's New
* INT-2981 Polishing - PR Comments
* Add javadocs to enums.
* Polish schemas to use an enumerated type for available gateway commands
This commit is contained in:
Gary Russell
2013-04-05 14:44:48 -04:00
committed by Gunnar Hillert
parent 2e2986d354
commit c224d445ac
16 changed files with 557 additions and 158 deletions

View File

@@ -3,6 +3,7 @@
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
targetNamespace="http://www.springframework.org/schema/integration/sftp"
elementFormDefault="qualified" attributeFormDefault="unqualified">
@@ -10,7 +11,8 @@
<xsd:import namespace="http://www.springframework.org/schema/tool" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-3.0.xsd" />
<xsd:import namespace="http://www.springframework.org/schema/integration/file"
schemaLocation="http://www.springframework.org/schema/integration/file/spring-integration-file-3.0.xsd" />
<xsd:element name="outbound-channel-adapter">
<xsd:annotation>
@@ -240,12 +242,15 @@
<xsd:all>
<xsd:element name="request-handler-advice-chain" type="integration:adviceChainType" minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attribute name="command" use="required" type="xsd:string">
<xsd:attribute name="command" use="required">
<xsd:annotation>
<xsd:documentation>
sftp command - ls, get or rm
sftp command.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:union memberTypes="int-file:remoteGatewayCommand xsd:string"/>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="command-options" type="xsd:string">
<xsd:annotation>
@@ -272,6 +277,15 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="rename-expression" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
SpEL expression representing the path for the
new filename when using the 'mv' command. Defaults
to "headers.['file_renameTo']".
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="request-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>

View File

@@ -43,6 +43,16 @@
order="2"
/>
<int-sftp:outbound-gateway id="gateway3"
session-factory="sf"
request-channel="inbound1"
reply-channel="outbound"
command="mv"
expression="payload"
rename-expression="'foo'"
order="1"
/>
<int-sftp:outbound-gateway id="advised"
local-directory="local-test-dir"
session-factory="sf"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -28,6 +28,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.Message;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.Command;
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.Option;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
import org.springframework.integration.message.GenericMessage;
@@ -54,6 +56,9 @@ public class SftpOutboundGatewayParserTests {
@Autowired
AbstractEndpoint gateway2;
@Autowired
AbstractEndpoint gateway3;
@Autowired
AbstractEndpoint advised;
@@ -69,11 +74,11 @@ public class SftpOutboundGatewayParserTests {
assertEquals(new File("local-test-dir"), TestUtils.getPropertyValue(gateway, "localDirectory"));
assertFalse((Boolean) TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory"));
assertNotNull(TestUtils.getPropertyValue(gateway, "filter"));
assertEquals("ls", TestUtils.getPropertyValue(gateway, "command"));
assertEquals(Command.LS, TestUtils.getPropertyValue(gateway, "command"));
@SuppressWarnings("unchecked")
Set<String> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
assertTrue(options.contains("-1"));
assertTrue(options.contains("-f"));
assertTrue(options.contains(Option.NAME_ONLY));
assertTrue(options.contains(Option.NOSORT));
Long sendTimeout = TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout", Long.class);
assertEquals(Long.valueOf(777), sendTimeout);
@@ -89,10 +94,20 @@ public class SftpOutboundGatewayParserTests {
assertNotNull(TestUtils.getPropertyValue(gateway, "outputChannel"));
assertEquals(new File("local-test-dir"), TestUtils.getPropertyValue(gateway, "localDirectory"));
assertFalse((Boolean) TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory"));
assertEquals("get", TestUtils.getPropertyValue(gateway, "command"));
assertEquals(Command.GET, TestUtils.getPropertyValue(gateway, "command"));
@SuppressWarnings("unchecked")
Set<String> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
assertTrue(options.contains("-P"));
assertTrue(options.contains(Option.PRESERVE_TIMESTAMP));
}
@Test
public void testGatewayMv() {
SftpOutboundGateway gateway = TestUtils.getPropertyValue(gateway3,
"handler", SftpOutboundGateway.class);
assertNotNull(TestUtils.getPropertyValue(gateway, "sessionFactory"));
assertNotNull(TestUtils.getPropertyValue(gateway, "outputChannel"));
assertEquals(Command.MV, TestUtils.getPropertyValue(gateway, "command"));
assertEquals("'foo'", TestUtils.getPropertyValue(gateway, "renameProcessor.expression.expression"));
}
@Test