Skip to content
This repository was archived by the owner on Nov 6, 2026. It is now read-only.

Latest commit

 

History

History
58 lines (47 loc) · 2.45 KB

Configuration.md

File metadata and controls

58 lines (47 loc) · 2.45 KB

Configuration

Caution

box-java-sdk-gen is deprecated and no longer maintained. As of September 17, 2025, it receives no new features, bug fixes, or security patches. Do not use it for new projects.

Use box-java-sdk v10+ instead: com.box:box-java-sdk from Maven Central. The equivalent of this page is box-java-sdk/docs/configuration.md. To migrate existing code, see the migration guide.

Max retry attempts

The default maximum number of retries in case of failed API call is 5. To change this number you should initialize BoxRetryStrategy with the new value and pass it to NetworkSession.

BoxDeveloperTokenAuth auth = new BoxDeveloperTokenAuth("DEVELOPER_TOKEN");
NetworkSession session = new NetworkSession.Builder()
    .retryStrategy(new BoxRetryStrategy.Builder().maxAttempts(3).build())
    .build();
BoxClient client = new BoxClient.Builder(auth)
    .networkSession(session)
    .build();

Custom retry strategy

You can also implement your own retry strategy by subclassing RetryStrategy and overriding shouldRetry and retryAfter methods. This example shows how to set custom strategy that retries on 5xx status codes and waits 1 second between retries.

BoxDeveloperTokenAuth auth = new BoxDeveloperTokenAuth("DEVELOPER_TOKEN");
RetryStrategy customRetryStrategy = new RetryStrategy() {
    @Override
    public boolean shouldRetry(FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
        return fetchResponse.status >= 500;
    }

    @Override
    public double retryAfter(FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
        return 1.0;
    }
};
NetworkSession session = new NetworkSession.Builder()
    .retryStrategy(customRetryStrategy)
    .build();
BoxClient client = new BoxClient.Builder(auth)
    .networkSession(session)
    .build();