diff --git a/.codegen.json b/.codegen.json index 53db925b9..feb6a33d0 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "6f9492d", "specHash": "131c54a", "version": "10.14.0" } +{ "engineHash": "ed5236c", "specHash": "131c54a", "version": "10.14.0" } diff --git a/docs/client.md b/docs/client.md index 7e63120f4..c78e51b7e 100644 --- a/docs/client.md +++ b/docs/client.md @@ -183,10 +183,13 @@ BoxClient clientWithInterceptor = client.withInterceptors(interceptors); In order to configure timeout for API calls, calling the `client.withTimeouts(config)` method creates a new client with timeout settings, leaving the original client unmodified. +All timeout values are in milliseconds. + ```java TimeoutConfig timeoutConfig = new TimeoutConfig.Builder() - .connectionTimeoutMs(10000L) + .connectionTimeoutMs(5000L) .readTimeoutMs(30000L) + .requestTimeoutMs(60000L) .build(); BoxClient newClient = client.withTimeouts(timeoutConfig); ``` diff --git a/docs/configuration.md b/docs/configuration.md index ebb79bdcd..a07fc503f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -178,13 +178,20 @@ BoxClient client = new BoxClient.Builder(auth) ## Timeouts You can configure network timeouts with `TimeoutConfig` on `NetworkSession`. -Java SDK supports separate values for connection and read timeouts, both in milliseconds. +The SDK supports three timeout values, all in milliseconds: + +| Parameter | Description | +| --------------------- | -------------------------------------------------------------------------------------------------------- | +| `connectionTimeoutMs` | Maximum time to wait for the TCP connection to be established. Maps to OkHttp `connectTimeout`. | +| `readTimeoutMs` | Maximum idle time between data packets while reading the response. Maps to OkHttp `readTimeout`. | +| `requestTimeoutMs` | Maximum total time for the entire HTTP request (connect + send + receive). Maps to OkHttp `callTimeout`. | ```java BoxDeveloperTokenAuth auth = new BoxDeveloperTokenAuth("DEVELOPER_TOKEN"); TimeoutConfig timeoutConfig = new TimeoutConfig.Builder() - .connectionTimeoutMs(10000L) + .connectionTimeoutMs(5000L) .readTimeoutMs(30000L) + .requestTimeoutMs(60000L) .build(); NetworkSession session = new NetworkSession() @@ -199,10 +206,10 @@ How timeout handling works: - `connectionTimeoutMs` controls how long the client waits to establish a connection. - `readTimeoutMs` controls how long the client waits for data while reading the response. -- If timeout config is not provided, the SDK uses the OkHttp default timeout settings: connect timeout of 10 seconds, read timeout of 10 seconds, and write timeout of 10 seconds. +- `requestTimeoutMs` controls the maximum total time for the entire request lifecycle, including connection, sending the request body, and reading the response. +- If timeout config is not provided, the SDK uses default timeouts: `connectionTimeoutMs: 10000` (10 seconds), `readTimeoutMs: 60000` (60 seconds), and `requestTimeoutMs: 21600000` (6 hours). - Each timeout is optional. If a value is not provided, the client keeps its existing timeout for that setting. -- To disable both timeouts, set `connectionTimeoutMs(0L)` and `readTimeoutMs(0L)`. -- You can also disable only one timeout by setting just one of them to `0L` and leaving the other configured. -- Timeout failures are handled as request exceptions, then retry behavior is controlled by the configured retry strategy +- To disable a timeout, set its value to `0L`. +- Timeout failures are handled as request exceptions, then retry behavior is controlled by the configured retry strategy. - If retries are exhausted after timeout failures, the SDK throws `BoxSDKError` with the underlying timeout exception as the cause. - Timeout applies to a single HTTP request attempt to the Box API (not the total time across all retries). diff --git a/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java b/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java index b7278de44..208cd0603 100644 --- a/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java +++ b/src/main/java/com/box/sdkgen/networking/boxnetworkclient/BoxNetworkClient.java @@ -120,6 +120,14 @@ public BoxNetworkClient withTimeoutConfig(TimeoutConfig config) { } clientBuilder.readTimeout(readTimeoutMs.longValue(), TimeUnit.MILLISECONDS); } + + Long requestTimeoutMs = config.getRequestTimeoutMs(); + if (requestTimeoutMs != null) { + if (requestTimeoutMs < 0) { + throw new IllegalArgumentException("requestTimeoutMs cannot be negative"); + } + clientBuilder.callTimeout(requestTimeoutMs.longValue(), TimeUnit.MILLISECONDS); + } return new BoxNetworkClient(clientBuilder.build()); } diff --git a/src/main/java/com/box/sdkgen/networking/network/NetworkSession.java b/src/main/java/com/box/sdkgen/networking/network/NetworkSession.java index 60a32bff6..5b553561e 100644 --- a/src/main/java/com/box/sdkgen/networking/network/NetworkSession.java +++ b/src/main/java/com/box/sdkgen/networking/network/NetworkSession.java @@ -38,6 +38,13 @@ public NetworkSession() { networkClient = new BoxNetworkClient(); retryStrategy = new BoxRetryStrategy(); dataSanitizer = new DataSanitizer(); + timeoutConfig = + new TimeoutConfig.Builder() + .connectionTimeoutMs(10000L) + .readTimeoutMs(60000L) + .requestTimeoutMs(21600000L) + .build(); + networkClient = ((BoxNetworkClient) networkClient).withTimeoutConfig(timeoutConfig); } protected NetworkSession(Builder builder) { diff --git a/src/main/java/com/box/sdkgen/networking/timeoutconfig/TimeoutConfig.java b/src/main/java/com/box/sdkgen/networking/timeoutconfig/TimeoutConfig.java index 728f5b092..bdd2fc665 100644 --- a/src/main/java/com/box/sdkgen/networking/timeoutconfig/TimeoutConfig.java +++ b/src/main/java/com/box/sdkgen/networking/timeoutconfig/TimeoutConfig.java @@ -6,11 +6,14 @@ public class TimeoutConfig { public Long readTimeoutMs; + public Long requestTimeoutMs; + public TimeoutConfig() {} protected TimeoutConfig(Builder builder) { this.connectionTimeoutMs = builder.connectionTimeoutMs; this.readTimeoutMs = builder.readTimeoutMs; + this.requestTimeoutMs = builder.requestTimeoutMs; } public Long getConnectionTimeoutMs() { @@ -21,12 +24,18 @@ public Long getReadTimeoutMs() { return readTimeoutMs; } + public Long getRequestTimeoutMs() { + return requestTimeoutMs; + } + public static class Builder { protected Long connectionTimeoutMs; protected Long readTimeoutMs; + protected Long requestTimeoutMs; + public Builder connectionTimeoutMs(Long connectionTimeoutMs) { this.connectionTimeoutMs = connectionTimeoutMs; return this; @@ -37,6 +46,11 @@ public Builder readTimeoutMs(Long readTimeoutMs) { return this; } + public Builder requestTimeoutMs(Long requestTimeoutMs) { + this.requestTimeoutMs = requestTimeoutMs; + return this; + } + public TimeoutConfig build() { return new TimeoutConfig(this); }