diff --git a/src/main/java/com/textkernel/tx/TxClient.java b/src/main/java/com/textkernel/tx/TxClient.java index 65f7822e7..349f10a48 100644 --- a/src/main/java/com/textkernel/tx/TxClient.java +++ b/src/main/java/com/textkernel/tx/TxClient.java @@ -123,11 +123,24 @@ public TxClient(String accountId, String serviceKey, DataCenter dataCenter) { * Create an SDK client to perform Tx API calls with the account information found at https://cloud.textkernel.com/tx/console * @param accountId - The account id for your account * @param serviceKey - The service key for your account - * @param dataCenter - The Data Center for your account. Either {@link DataCenter#US}, {@link DataCenter#EU} or {@link DataCenter#AU} + * @param dataCenter - The Data Center for your account. Either {@link DataCenter#US}, {@link DataCenter#EU}, or @link DataCenter#AU} * @param trackingTags - Optional tags to use to track API usage for your account * @throws IllegalArgumentException if the accountId, serviceKey, or dataCenter are null/empty */ public TxClient(String accountId, String serviceKey, DataCenter dataCenter, List trackingTags) { + this(accountId, serviceKey, dataCenter, trackingTags, 30); + } + + /** + * Create an SDK client to perform Tx API calls with the account information found at https://cloud.textkernel.com/tx/console + * @param accountId - The account id for your account + * @param serviceKey - The service key for your account + * @param dataCenter - The Data Center for your account. Either {@link DataCenter#US}, {@link DataCenter#EU} or {@link DataCenter#AU} + * @param trackingTags - Optional tags to use to track API usage for your account + * @param httpTimeoutSecs - Optional override for the OkHttp client read timeout (write and connect are 10 seconds, read is 30 seconds by default) + * @throws IllegalArgumentException if the accountId, serviceKey, or dataCenter are null/empty + */ + public TxClient(String accountId, String serviceKey, DataCenter dataCenter, List trackingTags, long httpTimeoutSecs) { if (accountId == null || accountId.length() == 0) { throw new IllegalArgumentException("'accountId' must have a valid value"); @@ -141,6 +154,10 @@ public TxClient(String accountId, String serviceKey, DataCenter dataCenter, List throw new IllegalArgumentException("'dataCenter' must not be null"); } + if (httpTimeoutSecs <= 0) { + throw new IllegalArgumentException("'httpTimeoutSecs' must be greater than 0"); + } + _endpoints = new ApiEndpoints(dataCenter); final String trackingTagsHeaderValue;//must be final to be passed into the interceptor below @@ -184,7 +201,7 @@ public Response intercept(Interceptor.Chain chain) throws IOException { }) .connectTimeout(10, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + .readTimeout(httpTimeoutSecs, TimeUnit.SECONDS) .build(); }