Skip to content

Commit

Permalink
Add method to DracoonClient to set HTTP timeouts
Browse files Browse the repository at this point in the history
See: #SDKJAVA-32
  • Loading branch information
mkellnhofer committed Feb 15, 2018
1 parent 2b6b2a5 commit 7f5f4e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/main/java/com/dracoon/sdk/DracoonClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ public interface Shares {
protected String mEncryptionPassword;

protected boolean mIsHttpRetryEnabled;
protected int mHttpConnectTimeout;
protected int mHttpReadTimeout;
protected int mHttpWriteTimeout;

/**
* Constructs a new Dracoon client.
Expand Down Expand Up @@ -473,6 +476,9 @@ public Builder(String serverUrl) {
mClient = new DracoonClientImpl(serverUrl);

mClient.mIsHttpRetryEnabled = false;
mClient.mHttpConnectTimeout = 15;
mClient.mHttpReadTimeout = 15;
mClient.mHttpWriteTimeout = 15;
}

/**
Expand Down Expand Up @@ -527,6 +533,25 @@ public Builder httpRetryEnabled(boolean isHttpRetryEnabled) {
return this;
}

/**
* Sets HTTP timeouts. A value of 0 means no timeout.<br>
* <br>
* The HTTP timeouts are set to 15 seconds by default.
*
* @param httpConnectTimeout The connect timeout for new connections in seconds.
* @param httpReadTimeout The read timeout for new connections in seconds.
* @param httpWriteTimeout The write timeout for new connections in seconds.
*
* @return a reference to this object
*/
public Builder httpTimeout(int httpConnectTimeout, int httpReadTimeout,
int httpWriteTimeout) {
mClient.mHttpConnectTimeout = httpConnectTimeout;
mClient.mHttpReadTimeout = httpReadTimeout;
mClient.mHttpWriteTimeout = httpWriteTimeout;
return this;
}

/**
* Creates a new {@link DracoonClient} instance with the supplied configuration.
*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/dracoon/sdk/internal/DracoonClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public void init() {

private void initOkHttp() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(15, TimeUnit.SECONDS);
builder.readTimeout(15, TimeUnit.SECONDS);
builder.writeTimeout(15, TimeUnit.SECONDS);
builder.connectTimeout(mHttpConnectTimeout, TimeUnit.SECONDS);
builder.readTimeout(mHttpReadTimeout, TimeUnit.SECONDS);
builder.writeTimeout(mHttpWriteTimeout, TimeUnit.SECONDS);
builder.retryOnConnectionFailure(false);
mOkHttpClient = builder.build();
}
Expand Down

0 comments on commit 7f5f4e2

Please sign in to comment.