Skip to content

Commit 9dca8c2

Browse files
authored
1.2.0
make read/write timeouts configurable in WebClientProxy
1 parent af8a4cb commit 9dca8c2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repositories {
2424

2525
dependencies {
2626
//implementation 'org.iot-dsa:dslink-v2-websocket:+' //for a locally installed sdk
27-
api 'com.github.iot-dsa-v2.sdk-dslink-java-v2:dslink-v2-websocket:0.63.0'
27+
api 'com.github.iot-dsa-v2.sdk-dslink-java-v2:dslink-v2-websocket:+'
2828
api 'com.squareup.okhttp3:okhttp:3.14.0'
2929
implementation 'commons-logging:commons-logging:+'
3030
implementation 'org.apache.commons:commons-lang3:3.8.1'

dslink.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dslink-java-v2-restadapter",
3-
"version": "1.1.9",
3+
"version": "1.2.0",
44
"description": "Java DSA to REST adapter DSLink",
55
"main": "bin/dslink-java-v2-restadapter",
66
"configs": {

src/main/java/org/iot/dsa/dslink/restadapter/WebClientProxy.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import java.io.IOException;
5+
import java.time.Duration;
56
import org.iot.dsa.logging.DSLogger;
67
import org.iot.dsa.node.DSMap;
78
import org.iot.dsa.node.DSMap.Entry;
@@ -17,12 +18,20 @@
1718

1819
public class WebClientProxy extends DSLogger {
1920
private CredentialProvider credentials;
21+
private Duration readTimeout = null;
22+
private Duration writeTimeout = null;
2023

2124
private OkHttpClient client;
2225

2326
public WebClientProxy(CredentialProvider credentials) {
2427
this.credentials = credentials;
2528
}
29+
30+
public WebClientProxy(CredentialProvider credentials, long readTimeoutMillis, long writeTimeoutMillis) {
31+
this(credentials);
32+
this.readTimeout = Duration.ofMillis(readTimeoutMillis);
33+
this.writeTimeout = Duration.ofMillis(writeTimeoutMillis);
34+
}
2635

2736
// public static WebClientProxy buildNoAuthClient() {
2837
// return new WebClientProxy(null, null, null, null, null, Util.AUTH_SCHEME.NO_AUTH);
@@ -106,6 +115,12 @@ public Request authenticate(Route route, Response response) throws IOException {
106115
// client.header(HttpHeaders.AUTHORIZATION, authManager.createAuthorizationHeader());
107116
break;
108117
}
118+
if (readTimeout != null) {
119+
clientBuilder.readTimeout(readTimeout);
120+
}
121+
if (writeTimeout != null) {
122+
clientBuilder.writeTimeout(writeTimeout);
123+
}
109124
return clientBuilder.build();
110125
}
111126

0 commit comments

Comments
 (0)