Skip to content

Commit baa14ca

Browse files
author
box-sdk-build
committed
Merge remote-tracking branch 'origin/combined-sdk' into codegen-11233-4de40e1-576cd17
2 parents 78fa7fa + dafdc27 commit baa14ca

2 files changed

Lines changed: 81 additions & 29 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ for (BoxItem.Info itemInfo : rootFolder) {
158158
}
159159
```
160160

161+
> **Important:** `The com.box.sdk package` does **not** apply default connection or read timeouts. Unless you configure them, connection and read timeout values are **`0` milliseconds**, which means the client does not enforce a limit while establishing a connection or while reading the response body.
162+
163+
To set connect and read timeouts, follow the instructions in [configuration.md](./docs/sdk/configuration.md#network-timeouts).
164+
161165
# Authentication
162166

163167
Both the `com.box.sdkgen` and `com.box.sdk` packages support multiple authentication methods, including

docs/sdk/configuration.md

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
- [Proxy configuration](#proxy-configuration)
44
- [Custom proxy authenticator](#custom-proxy-authenticator)
55
- [Example: NTLM authenticator](#example-ntlm-authenticator)
6-
- [Configure retries of calls and timeouts](#configure-retries-of-calls-and-timeouts)
7-
- [Maximum retries](#maximum-retries)
6+
- [Network timeouts](#network-timeouts)
7+
- [Default behavior](#default-behavior)
88
- [Connection timeout](#connection-timeout)
99
- [Read timeout](#read-timeout)
10+
- [Complete example](#complete-example)
11+
- [Configure retries of calls](#configure-retries-of-calls)
12+
- [Maximum retries](#maximum-retries)
1013
- [URLs configuration](#urls-configuration)
1114
- [Base URL](#base-url)
1215
- [Base Upload URL](#base-upload-url)
@@ -133,7 +136,78 @@ api.setProxyAuthenticator(new NTLMAuthenticator("some proxy username", "some pro
133136
[set-basic-proxy-auth]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAPIConnection.html#setProxyBasicAuthentication-java.lang.String-java.lang.String-
134137
[set-proxy-authenticator]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAPIConnection.html#setProxyAuthenticator-okhttp3.Authenticator-
135138

136-
# Configure retries of calls and timeouts
139+
# Network timeouts
140+
141+
The legacy **`com.box.sdk`** package uses OkHttp for HTTP calls. Connect and read timeouts are controlled through [`BoxAPIConnection`](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAPIConnection.html) and [`BoxGlobalSettings`](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxGlobalSettings.html).
142+
143+
## Default behavior
144+
145+
> **Important:** The legacy SDK does **not** apply default connection or read timeouts. Unless you configure them, connection and read timeout values are **`0` milliseconds**, which means the client does not enforce a limit while establishing a connection or while reading the response body.
146+
147+
If your application needs bounded network behavior (recommended for production workloads), you **must** set connect and read timeouts explicitly using the options below.
148+
149+
## Connection timeout
150+
151+
Controls how long the client waits to establish a connection, in milliseconds.
152+
153+
There is **no default** connection timeout until you set one.
154+
155+
**Per connection**[`BoxAPIConnection#setConnectTimeout`](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAPIConnection.html#setConnectTimeout-int-) rebuilds the internal HTTP client when called:
156+
157+
```java
158+
BoxAPIConnection api = new BoxAPIConnection("access_token");
159+
api.setConnectTimeout(30_000); // milliseconds
160+
```
161+
162+
**All new connections**[`BoxGlobalSettings#setConnectTimeout`](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxGlobalSettings.html#setConnectTimeout-int-) applies to connections created after it is set. Configure globals **before** constructing `BoxAPIConnection`:
163+
164+
```java
165+
BoxGlobalSettings.setConnectTimeout(30_000);
166+
BoxAPIConnection api = new BoxAPIConnection("access_token");
167+
```
168+
169+
## Read timeout
170+
171+
Controls how long the client waits for response data while reading from the connection, in milliseconds.
172+
173+
There is **no default** read timeout until you set one.
174+
175+
**Per connection**[`BoxAPIConnection#setReadTimeout`](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAPIConnection.html#setReadTimeout-int-):
176+
177+
```java
178+
BoxAPIConnection api = new BoxAPIConnection("access_token");
179+
api.setReadTimeout(60_000); // milliseconds
180+
```
181+
182+
**All new connections**[`BoxGlobalSettings#setReadTimeout`](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxGlobalSettings.html#setReadTimeout-int-):
183+
184+
```java
185+
BoxGlobalSettings.setReadTimeout(60_000);
186+
BoxAPIConnection api = new BoxAPIConnection("access_token");
187+
```
188+
189+
## Complete example
190+
191+
Set both timeouts globally before creating a connection:
192+
193+
```java
194+
BoxGlobalSettings.setConnectTimeout(30_000);
195+
BoxGlobalSettings.setReadTimeout(60_000);
196+
197+
BoxAPIConnection api = new BoxAPIConnection("access_token");
198+
// api uses 30s connect timeout and 60s read timeout
199+
```
200+
201+
Or set both on a single connection:
202+
203+
```java
204+
BoxAPIConnection api = new BoxAPIConnection("access_token");
205+
api.setConnectTimeout(30_000);
206+
api.setReadTimeout(60_000);
207+
```
208+
209+
# Configure retries of calls
210+
137211
SDK can retry failed calls when:
138212
- failed writting request body
139213
- when recieved HTTP response code:
@@ -157,32 +231,6 @@ api.setMaxRetryAttempts(10);
157231

158232
default value for retry attempts is `5`.
159233

160-
## Connection timeout
161-
162-
To set up how log (in milliseconds) API waits to establish connection
163-
use [BoxApiConnection.setConnectTimeout](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAPIConnection.html#setConnectTimeout-int-):
164-
165-
```java
166-
// You can use any subclass of BoxAPIConnection
167-
int connectionTimeout = 100; // timeout in milliseconds
168-
api.setConnectTimeout(connectionTimeout);
169-
```
170-
171-
default value is `0` which mean API waits forever to establish connection.
172-
173-
## Read timeout
174-
175-
To set up how log (in milliseconds) API waits to read data from connection
176-
use [BoxApiConnection.setReadTimeout](https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxAPIConnection.html#setReadTimeout-int-):
177-
178-
```java
179-
// You can use any subclass of BoxAPIConnection
180-
int readTimeout = 100; // timeout in milliseconds
181-
api.setReadTimeout(readTimeout);
182-
```
183-
184-
default value is `0` which mean API waits forever to read data from connection.
185-
186234
# URLs configuration
187235

188236
### Base URL

0 commit comments

Comments
 (0)