Skip to content

Commit a5bbd58

Browse files
author
box-sdk-build
committed
Merge remote-tracking branch 'origin/combined-sdk' into codegen-1031-49fe45b-fa34496
2 parents 42efa0d + 6aadb6d commit a5bbd58

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/sdk/configuration.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Revoke URL](#revoke-url-deprecated)
1616
- [SSL configuration](#ssl-configuration)
1717
- [Instrumenation of OpenTelemetry](#instrumenation-of-opentelemetry)
18+
- [OkHttp Default Retry Behavior](#okhttp-default-retry-behavior)
1819

1920
# Proxy configuration
2021

@@ -326,4 +327,31 @@ public class BoxAPIConnectionWithTelemetry extends BoxAPIConnection {
326327
```
327328

328329
Please note that you should not modify either `httpClient` or `request` parameters in the createNewCall method.
329-
Altering these parameters can discard the BoxAPIConnection configuration and lead to unexpected behavior.
330+
Altering these parameters can discard the BoxAPIConnection configuration and lead to unexpected behavior.
331+
332+
# OkHttp Default Retry Behavior
333+
334+
When using the Box Java SDK, HTTP requests are made through an underlying OkHttp client. By default, OkHttp enables automatic retries for certain types of connection failures (e.g. network errors) via the `retryOnConnectionFailure(true)` setting. While this can improve reliability for transient issues, this can cause issues during file uploads with `BoxFolder.uploadFile(InputStream, String)`, particularly when the provided `InputStream` is consumed during a failed request and reused in a retry, potentially resulting in a 0-byte file being uploaded.
335+
336+
To leverage the Box SDK’s retry strategy and avoid issues with OkHttp’s default retries, you can disable OkHttp’s automatic retries by customizing the BoxAPIConnection.
337+
To disable OkHttp’s automatic retries, create a custom BoxAPIConnection subclass and override the `modifyHttpClientBuilder` method to set `retryOnConnectionFailure(false)`. This allows the Box SDK to handle retries instead of OkHttp.
338+
Here's an example implementation:
339+
```java
340+
import com.box.sdk.BoxAPIConnection;
341+
import com.box.sdk.BoxConfig;
342+
import okhttp3.OkHttpClient;
343+
344+
public class CustomBoxAPIConnection extends BoxAPIConnection {
345+
346+
public CustomBoxAPIConnection(BoxConfig boxConfig) {
347+
super(boxConfig);
348+
}
349+
350+
@Override
351+
protected OkHttpClient.Builder modifyHttpClientBuilder(OkHttpClient.Builder httpClientBuilder) {
352+
httpClientBuilder.retryOnConnectionFailure(false); // Disable OkHttp retries
353+
return httpClientBuilder;
354+
}
355+
}
356+
357+
```

0 commit comments

Comments
 (0)