From 851aa5fb5682c689ec8864942003af70113e3c7c Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 29 Mar 2016 14:40:24 +0200 Subject: [PATCH 1/3] serverAliveInterval and serverAliveCountMax in and Patch by Issa Gorissen https://bz.apache.org/bugzilla/show_bug.cgi?id=59162 --- CONTRIBUTORS | 1 + WHATSNEW | 5 +++ contributors.xml | 4 ++ .../ant/taskdefs/optional/ssh/SSHBase.java | 44 +++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index af1a509f4..74d6c636f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -154,6 +154,7 @@ Ingenonsya France Ingmar Stein Irene Rusman Isaac Shabtay +Issa Gorissen Ivan Ivanov J Bleijenbergh Jack J. Woehr diff --git a/WHATSNEW b/WHATSNEW index a0c575dac..a2dd3d54b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -80,6 +80,11 @@ Other changes: * now supports Java9 modules. https://github.com/apache/ant/pull/16 + * and have two new attributes serverAliveInterval and + serverAliveCountMax that can be used to keep a intermediaries from + closing idle connections. + Bugzilla Report 59162 + Changes from Ant 1.9.5 TO Ant 1.9.6 =================================== diff --git a/contributors.xml b/contributors.xml index 4029a0d09..85066b750 100644 --- a/contributors.xml +++ b/contributors.xml @@ -640,6 +640,10 @@ Isaac Shabtay + + Issa + Gorissen + Ivan Ivanov diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java index 68419a85d..df7996a3f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java @@ -42,6 +42,8 @@ public abstract class SSHBase extends Task implements LogListener { private boolean failOnError = true; private boolean verbose; private final SSHUserInfo userInfo; + private int serverAliveCountMax = 3; + private int serverAliveIntervalSeconds = 0; /** * Constructor for SSHBase. @@ -104,6 +106,42 @@ public abstract class SSHBase extends Task implements LogListener { return verbose; } + /** + * Set the serverAliveCountMax value. + * @since Ant 1.9.7 + */ + public void setServerAliveCountMax(final int countMax) { + if (countMax <= 0) throw new IllegalArgumentException("ssh server alive count max setting cannot be negative or zero"); + this.serverAliveCountMax = countMax; + } + + /** + * Get the serverAliveCountMax value. + * @return the serverAliveCountMax value + * @since Ant 1.9.7 + */ + public int getServerAliveCountMax() { + return serverAliveCountMax; + } + + /** + * Set the serverAliveIntervalSeconds value in seconds. + * @since Ant 1.9.7 + */ + public void setServerAliveIntervalSeconds(final int interval) { + if (interval < 0) throw new IllegalArgumentException("ssh server alive interval setting cannot be negative"); + this.serverAliveIntervalSeconds = interval; + } + + /** + * Get the serverAliveIntervalSeconds value in seconds. + * @return the serverAliveIntervalSeconds value in seconds + * @since Ant 1.9.7 + */ + public int getServerAliveIntervalSeconds() { + return serverAliveIntervalSeconds; + } + /** * Username known to remote host. * @@ -221,6 +259,12 @@ public abstract class SSHBase extends Task implements LogListener { session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password"); session.setUserInfo(userInfo); + + if (serverAliveIntervalSeconds > 0) { + session.setServerAliveCountMax(serverAliveCountMax); + session.setServerAliveInterval(serverAliveIntervalSeconds * 1000); + } + log("Connecting to " + host + ":" + port); session.connect(); return session; From edeb171a781501ed906b2d2bdd38e22b3fe81e02 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 29 Mar 2016 14:43:06 +0200 Subject: [PATCH 2/3] cosmetics --- .../tools/ant/taskdefs/optional/ssh/SSHBase.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java index df7996a3f..d6abb95d5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java @@ -111,7 +111,9 @@ public abstract class SSHBase extends Task implements LogListener { * @since Ant 1.9.7 */ public void setServerAliveCountMax(final int countMax) { - if (countMax <= 0) throw new IllegalArgumentException("ssh server alive count max setting cannot be negative or zero"); + if (countMax <= 0) { + throw new BuildException("ssh server alive count max setting cannot be negative or zero"); + } this.serverAliveCountMax = countMax; } @@ -129,7 +131,9 @@ public abstract class SSHBase extends Task implements LogListener { * @since Ant 1.9.7 */ public void setServerAliveIntervalSeconds(final int interval) { - if (interval < 0) throw new IllegalArgumentException("ssh server alive interval setting cannot be negative"); + if (interval < 0) { + throw new BuildException("ssh server alive interval setting cannot be negative"); + } this.serverAliveIntervalSeconds = interval; } @@ -260,9 +264,9 @@ public abstract class SSHBase extends Task implements LogListener { "publickey,keyboard-interactive,password"); session.setUserInfo(userInfo); - if (serverAliveIntervalSeconds > 0) { - session.setServerAliveCountMax(serverAliveCountMax); - session.setServerAliveInterval(serverAliveIntervalSeconds * 1000); + if (getServerAliveIntervalSeconds() > 0) { + session.setServerAliveCountMax(getServerAliveCountMax()); + session.setServerAliveInterval(getServerAliveIntervalSeconds() * 1000); } log("Connecting to " + host + ":" + port); From 356972ab3a5e0e867a2a90ece8f7e401ac145426 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 29 Mar 2016 14:48:39 +0200 Subject: [PATCH 3/3] document serverAliveInterval and serverAliveCountMax --- manual/Tasks/scp.html | 17 +++++++++++++++++ manual/Tasks/sshexec.html | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/manual/Tasks/scp.html b/manual/Tasks/scp.html index 6d06bd213..909084ef6 100644 --- a/manual/Tasks/scp.html +++ b/manual/Tasks/scp.html @@ -200,6 +200,23 @@ for more information. This task has been tested with jsch-0.1.2 and later.

remote server. Default is 755. since Ant 1.9.5. No + + serverAliveIntervalSeconds + Sets a timeout interval in seconds after which if no data has + been received from the server, the task will send a message through + the encrypted channel to request a response from the server. + since Ant 1.9.7 + No, the default is 0, indicating + that these messages will not be sent to the server + + + serverAliveCountMax + The number of server alive messages which may be + sent without receiving any messages back from the server. Only + used if serverAliveIntervalSeconds is not 0. + since Ant 1.9.7 + No, defaults to 3 +

Parameters specified as nested elements

diff --git a/manual/Tasks/sshexec.html b/manual/Tasks/sshexec.html index 2aab2a6bc..d085abdd1 100644 --- a/manual/Tasks/sshexec.html +++ b/manual/Tasks/sshexec.html @@ -230,6 +230,23 @@ and won't work with versions of jsch earlier than since Ant 1.9.4 No, defaults to false + + serverAliveIntervalSeconds + Sets a timeout interval in seconds after which if no data has + been received from the server, the task will send a message through + the encrypted channel to request a response from the server. + since Ant 1.9.7 + No, the default is 0, indicating + that these messages will not be sent to the server + + + serverAliveCountMax + The number of server alive messages which may be + sent without receiving any messages back from the server. Only + used if serverAliveIntervalSeconds is not 0. + since Ant 1.9.7 + No, defaults to 3 +

Examples