INT-2586 FTP Session Factory: Expose Timeout Props

JIRA: https://jira.spring.io/browse/INT-2586

Add timeout properties to the `DefaultFtpSessionFactory`
avoiding the need to subclass it just to set these
common properties.
This commit is contained in:
Gary Russell
2014-04-16 17:48:18 -04:00
committed by Artem Bilan
parent 42130246e1
commit 7dc9c6b983
4 changed files with 91 additions and 12 deletions

View File

@@ -104,15 +104,19 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/ftp
</para>
<para>
<emphasis>Advanced Configuration</emphasis>
<emphasis role="bold">Advanced Configuration</emphasis>
</para>
<para>
<classname>DefaultFtpSessionFactory</classname> provides an abstraction over the underlying client API which,
since <emphasis>Spring Integration 2.0</emphasis>, is <ulink url="http://commons.apache.org/net/">Apache Commons Net</ulink>.
This spares you from the low level configuration details
of the <classname>org.apache.commons.net.ftp.FTPClient</classname>. However there are times when access to lower level <classname>FTPClient</classname> details is
necessary to achieve more advanced configuration (e.g., setting data timeout, default timeout etc.). For that purpose, <classname>AbstractFtpSessionFactory</classname>
of the <classname>org.apache.commons.net.ftp.FTPClient</classname>. Several common properties are exposed on the
session factory (since <emphasis>version 4.0</emphasis>, this now includes <code>connectTimeout</code>,
<code>defaultTimeout</code> and <code>dataTimeout</code>).
However there are times when access to lower level <classname>FTPClient</classname> configuration is
necessary to achieve more advanced configuration (e.g., setting the port range for active mode etc.).
For that purpose, <classname>AbstractFtpSessionFactory</classname>
(the base class for all FTP Session Factories) exposes hooks, in the form of the two post-processing methods below.
<programlisting language="java"><![CDATA[/**
* Will handle additional initialization after client.connect() method was invoked,
@@ -132,8 +136,7 @@ protected void postProcessClientBeforeConnect(T client) throws IOException {
<programlisting language="java"><![CDATA[public class AdvancedFtpSessionFactory extends DefaultFtpSessionFactory {
protected void postProcessClientBeforeConnect(FTPClient ftpClient) throws IOException {
ftpClient.setDataTimeout(5000);
ftpClient.setDefaultTimeout(5000);
ftpClient.setActivePortRange(4000, 5000);
}
}]]></programlisting>
</para>

View File

@@ -312,5 +312,15 @@
<xref linkend="amqp-outbound-gateway"/>.
</para>
</section>
<section id="4.0-ftp">
<title>FTP Timeouts</title>
<para>
The <classname>DefaultFtpSessionFactory</classname> now exposes the
<code>connectTimeout</code>, <code>defaultTimeout</code> and <code>dataTimeout</code>
properties, avoiding the need to subclass the factory just to set these common
properties. The <code>postProcess*</code> methods are still available for more
advanced configuration. See <xref linkend="ftp-session-factory"/> for more information.
</para>
</section>
</section>
</chapter>