|
2 | 2 |
|
3 | 3 |
|
4 | 4 | import java.io.IOException; |
| 5 | +import java.time.Duration; |
5 | 6 | import org.iot.dsa.logging.DSLogger; |
6 | 7 | import org.iot.dsa.node.DSMap; |
7 | 8 | import org.iot.dsa.node.DSMap.Entry; |
|
17 | 18 |
|
18 | 19 | public class WebClientProxy extends DSLogger { |
19 | 20 | private CredentialProvider credentials; |
| 21 | + private Duration readTimeout = null; |
| 22 | + private Duration writeTimeout = null; |
20 | 23 |
|
21 | 24 | private OkHttpClient client; |
22 | 25 |
|
23 | 26 | public WebClientProxy(CredentialProvider credentials) { |
24 | 27 | this.credentials = credentials; |
25 | 28 | } |
| 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 | + } |
26 | 35 |
|
27 | 36 | // public static WebClientProxy buildNoAuthClient() { |
28 | 37 | // 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 { |
106 | 115 | // client.header(HttpHeaders.AUTHORIZATION, authManager.createAuthorizationHeader()); |
107 | 116 | break; |
108 | 117 | } |
| 118 | + if (readTimeout != null) { |
| 119 | + clientBuilder.readTimeout(readTimeout); |
| 120 | + } |
| 121 | + if (writeTimeout != null) { |
| 122 | + clientBuilder.writeTimeout(writeTimeout); |
| 123 | + } |
109 | 124 | return clientBuilder.build(); |
110 | 125 | } |
111 | 126 |
|
|
0 commit comments