Skip to content
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
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "6f9492d", "specHash": "131c54a", "version": "10.14.0" }
{ "engineHash": "ed5236c", "specHash": "131c54a", "version": "10.14.0" }
5 changes: 4 additions & 1 deletion docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
Expand Down
19 changes: 13 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
Loading