Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for socket timeout in SshConnection. #158

Merged
merged 1 commit into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ Apart from selecting a protocol to use, you will also need to supply a number of
<td>The number of milliseconds Overthere waits for a connection to a remote host to be established. The default value is <code>120000</code>, i.e.
2 minutes.</td>
</tr>
<tr>
<th align="left" valign="top"><a name="socketTimeoutMillis"></a>socketTimeoutMillis</th>
<td>The number of milliseconds Overthere will waits when no data is received on an open connection before raising exception. The default value is <code>0</code>, i.e.
infinite timeout.</td>
</tr>
<tr>
<th align="left" valign="top"><a name="jumpstation"></a>jumpstation</th>
<td>If set to a non-null value, this property contains the connection options used to connect to an SSH jumpstation (See
Expand Down Expand Up @@ -988,10 +993,6 @@ The CIFS protocol implementation of Overthere defines a number of additional con
<br/>
<strong>N.B.:</strong> This connection option is only applicable for the <strong>WINRM_INTERNAL</strong> connection type.</td>
</tr>
<tr>
<th align="left" valign="top"><a name="winrmSoTimeoutMillis"></a>winrmSoTimeoutMillis</th>
<td>The number of milliseconds Overthere will waits when no data is received on an open connection before raising exception. The default value is <code>0</code>, meaning that read operations will not time out (infinite timeout).</td>
</tr>
<tr>
<th align="left" valign="top"><a name="cifs_winrsAllowDelegate"></a>winrsAllowDelegate</th>
<td>If set to <code>false</code>, the user's credentials may be passed to the remote host. This option corresponds to the <code>winrs</code> command option <code>-allowdelegate</code>. The default value is <code>false</code>.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/xebialabs/overthere/ConnectionOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public class ConnectionOptions {
*/
public static final int CONNECTION_TIMEOUT_MILLIS_DEFAULT = 120000;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#socketTimeoutMillis">the online documentation</a>
*/
public static final String SOCKET_TIMEOUT_MILLIS = "socketTimeoutMillis";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#socketTimeoutMillis">the online documentation</a>
*/
public static final int SOCKET_TIMEOUT_MILLIS_DEFAULT = 0;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#address">the online documentation</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,6 @@ public class CifsConnectionBuilder implements OverthereConnectionBuilder {
*/
public static final String DEFAULT_WINRM_TIMEOUT = "PT60.000S";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#winrmSoTimeoutMillis">the online documentation</a>
*/
public static final String WINRM_SO_TIMEOUT_MILLIS = "winrmSoTimeoutMillis";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#soTimeoutMillis">the online documentation</a>
*/
public static final int WINRM_SO_TIMEOUT_MILLIS_DEFAULT = 0;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsAllowDelegate">the online documentation</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.xebialabs.overthere.cifs.WinrmHttpsHostnameVerificationStrategy;
import com.xebialabs.overthere.spi.AddressPortMapper;

import static com.xebialabs.overthere.ConnectionOptions.*;
import static com.xebialabs.overthere.util.OverthereUtils.checkArgument;
import static com.xebialabs.overthere.util.OverthereUtils.checkNotNull;
import static com.xebialabs.overthere.OperatingSystemFamily.WINDOWS;
Expand All @@ -68,8 +69,6 @@
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_TIMEMOUT;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_KERBEROS_TICKET_CACHE;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_KERBEROS_TICKET_CACHE_DEFAULT;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_SO_TIMEOUT_MILLIS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_SO_TIMEOUT_MILLIS_DEFAULT;
import static com.xebialabs.overthere.ConnectionOptions.CONNECTION_TIMEOUT_MILLIS;
import static com.xebialabs.overthere.ConnectionOptions.CONNECTION_TIMEOUT_MILLIS_DEFAULT;
import static com.xebialabs.overthere.util.OverthereUtils.closeQuietly;
Expand Down Expand Up @@ -253,7 +252,7 @@ private WinRmClient createWinrmClient() {
client.setKerberosDebug(options.getBoolean(WINRM_KERBEROS_DEBUG, WINRM_KERBEROS_DEBUG_DEFAULT));
client.setKerberosTicketCache(options.getBoolean(WINRM_KERBEROS_TICKET_CACHE, WINRM_KERBEROS_TICKET_CACHE_DEFAULT));
client.setConnectionTimeout(options.getInteger(CONNECTION_TIMEOUT_MILLIS, CONNECTION_TIMEOUT_MILLIS_DEFAULT));
client.setSoTimeout(options.getInteger(WINRM_SO_TIMEOUT_MILLIS, WINRM_SO_TIMEOUT_MILLIS_DEFAULT));
client.setSoTimeout(options.getInteger(SOCKET_TIMEOUT_MILLIS, SOCKET_TIMEOUT_MILLIS_DEFAULT));
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public abstract class BaseOverthereConnection implements OverthereConnection {
protected final AddressPortMapper mapper;
protected final OperatingSystemFamily os;
protected final int connectionTimeoutMillis;
protected final int socketTimeoutMillis;
protected final boolean canStartProcess;
protected final String temporaryDirectoryPath;
protected final boolean deleteTemporaryDirectoryOnDisconnect;
Expand All @@ -85,6 +86,7 @@ protected BaseOverthereConnection(final String protocol, final ConnectionOptions
this.mapper = checkNotNull(mapper, "Cannot create OverthereConnection with null address-port mapper");
this.os = options.getEnum(OPERATING_SYSTEM, OperatingSystemFamily.class);
this.connectionTimeoutMillis = options.getInteger(CONNECTION_TIMEOUT_MILLIS, CONNECTION_TIMEOUT_MILLIS_DEFAULT);
this.socketTimeoutMillis = options.getInteger(SOCKET_TIMEOUT_MILLIS, SOCKET_TIMEOUT_MILLIS_DEFAULT);
this.canStartProcess = canStartProcess;
this.temporaryDirectoryPath = options.get(TEMPORARY_DIRECTORY_PATH, os.getDefaultTemporaryDirectoryPath());
this.deleteTemporaryDirectoryOnDisconnect = options.getBoolean(TEMPORARY_DIRECTORY_DELETE_ON_DISCONNECT, TEMPORARY_DIRECTORY_DELETE_ON_DISCONNECT_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ protected void connect() {
SSHClient client = sshClientFactory.create();
client.setConnectTimeout(connectionTimeoutMillis);
client.addHostKeyVerifier(new PromiscuousVerifier());
client.setTimeout(socketTimeoutMillis);
client.getConnection().getKeepAlive().setKeepAliveInterval(heartbeatInterval);

try {
Expand Down