Fix HER-1875 FetchFTP needs socket timeout

* FetchFTP.java
    setSoTimeoutMs(), getSoTimeoutMs()
    (init) - set default value of 20000 ms, same as FetchHTTP
    fetch() - set various timeouts on FTPClient - effectively sets connect
    timeout and socket timeout on control connection, and socket timeout on
    data connection (notably, does not set connect timeout on data connection
    w/ current commons-net)
This commit is contained in:
nlevitt
2011-04-04 19:50:56 +00:00
parent 1395854f9a
commit 8e7b9a5fdf
@@ -196,15 +196,33 @@ public class FetchFTP extends Processor {
* retry later).
*/
{
setTimeoutSeconds(20*60); // 20 minutes
}
public int getTimeoutSeconds() {
return (Integer) kp.get("timeoutSeconds");
}
public void setTimeoutSeconds(Integer timeout) {
kp.put("timeoutSeconds",timeout);
}
setTimeoutSeconds(20*60); // 20 minutes
}
public int getTimeoutSeconds() {
return (Integer) kp.get("timeoutSeconds");
}
public void setTimeoutSeconds(Integer timeout) {
kp.put("timeoutSeconds",timeout);
}
/**
* If the socket is unresponsive for this number of milliseconds, give up.
* Set to zero for no timeout (Not. recommended. Could hang a thread on an
* unresponsive server). This timeout is used timing out socket opens and
* for timing out each socket read. Make sure this value is <
* {@link #TIMEOUT_SECONDS} for optimal configuration: ensures at least one
* retry read.
*/
{
setSoTimeoutMs(20*1000); // 20 seconds
}
public int getSoTimeoutMs() {
return (Integer) kp.get("soTimeoutMs");
}
public void setSoTimeoutMs(int timeout) {
kp.put("soTimeoutMs",timeout);
}
/**
* Constructs a new <code>FetchFTP</code>.
*/
@@ -293,7 +311,12 @@ public class FetchFTP extends Processor {
port = 21;
}
client.setConnectTimeout(getSoTimeoutMs());
client.setDefaultTimeout(getSoTimeoutMs());
client.setDataTimeout(getSoTimeoutMs());
client.connect(uuri.getHost(), port);
client.setSoTimeout(getSoTimeoutMs()); // must be after connect()
// Authenticate.
String[] auth = getAuth(curi);
@@ -336,6 +359,9 @@ public class FetchFTP extends Processor {
// Save the streams in the CURI, where downstream processors
// expect to find them.
if (socket != null) {
if (socket.getSoTimeout() != getSoTimeoutMs()) {
logger.warning("data socket timeout " + socket.getSoTimeout() + "ms is not expected value " + getSoTimeoutMs() + "ms");
}
// Shall we get a digest on the content downloaded?
boolean digestContent = getDigestContent();
String algorithm = null;