diff --git a/generators/java/sdk/CHANGELOG.md b/generators/java/sdk/CHANGELOG.md index 896b1f4bdbd..e00930126b6 100644 --- a/generators/java/sdk/CHANGELOG.md +++ b/generators/java/sdk/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.1] - 2024-02-14 +- Feature: The RequestOptions object now supports configuring an optional timeout to apply per-request. + ```java + RequestOptions ro = RequestOptions.builder().timeout(90).build(); // Creates a timeout of 90 seconds for the request + // You could also specify the timeunit, similar to as if you were using OkHttp directly + // RequestOptions ro = RequestOptions.builder().timeout(2, TimeUnit.MINUTES).build(); + client.films.list(ro); + ``` + + ## [0.8.0] - 2024-02-11 - Feature: The SDK generator now supports whitelabelling. When this is turned on, there will be no mention of Fern in the generated code. diff --git a/generators/java/sdk/Dockerfile b/generators/java/sdk/Dockerfile index eafdb89f23c..93486479430 100644 --- a/generators/java/sdk/Dockerfile +++ b/generators/java/sdk/Dockerfile @@ -1,5 +1,5 @@ # Apple Silicon: FROM bitnami/gradle:latest -FROM bitnami/gradle:8.5.0 +FROM bitnami/gradle:latest COPY build/distributions/sdk.tar init.sh / RUN cd / \ diff --git a/generators/java/sdk/VERSION b/generators/java/sdk/VERSION index 8adc70fdd9d..c18d72be303 100644 --- a/generators/java/sdk/VERSION +++ b/generators/java/sdk/VERSION @@ -1 +1 @@ -0.8.0 \ No newline at end of file +0.8.1 \ No newline at end of file diff --git a/generators/java/sdk/src/main/java/com/fern/java/client/generators/RequestOptionsGenerator.java b/generators/java/sdk/src/main/java/com/fern/java/client/generators/RequestOptionsGenerator.java index 9f3c817b8a0..cf4c2d4be8a 100644 --- a/generators/java/sdk/src/main/java/com/fern/java/client/generators/RequestOptionsGenerator.java +++ b/generators/java/sdk/src/main/java/com/fern/java/client/generators/RequestOptionsGenerator.java @@ -32,13 +32,19 @@ import com.squareup.javapoet.MethodSpec; import com.squareup.javapoet.ParameterSpec; import com.squareup.javapoet.ParameterizedTypeName; +import com.squareup.javapoet.TypeName; import com.squareup.javapoet.TypeSpec; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.lang.model.element.Modifier; @@ -51,6 +57,16 @@ public final class RequestOptionsGenerator extends AbstractFileGenerator { Modifier.FINAL) .build(); + private static final FieldSpec.Builder TIMEOUT_FIELD_BUILDER = FieldSpec.builder( + ParameterizedTypeName.get(ClassName.get(Optional.class), TypeName.get(Integer.class)), + "timeout", + Modifier.PRIVATE); + + private static final FieldSpec.Builder TIMEOUT_TIME_UNIT_FIELD_BUILDER = FieldSpec.builder( + ParameterizedTypeName.get(TimeUnit.class), + "timeoutTimeUnit", + Modifier.PRIVATE); + private final List additionalHeaders; private final ClassName builderClassName; @@ -100,6 +116,45 @@ public GeneratedJavaFile generateFile() { fields.add(headerHandler.visitHeader(httpHeader)); } + // Add in the other (static) fields for request options + createRequestOptionField( + "getTimeout", + TIMEOUT_FIELD_BUILDER, + "null", + requestOptionsTypeSpec, + builderTypeSpec, + fields + ); + createRequestOptionField( + "getTimeoutTimeUnit", + TIMEOUT_TIME_UNIT_FIELD_BUILDER, + "TimeUnit.SECONDS", + requestOptionsTypeSpec, + builderTypeSpec, + fields + ); + + FieldSpec timeoutField = TIMEOUT_FIELD_BUILDER.build(); + FieldSpec timeUnitField = TIMEOUT_TIME_UNIT_FIELD_BUILDER.build(); + builderTypeSpec.addMethod(MethodSpec.methodBuilder(timeoutField.name) + .addModifiers(Modifier.PUBLIC) + .addParameter(Integer.class, timeoutField.name) + .addStatement("this.$L = Optional.of($L)", timeoutField.name, timeoutField.name) + .addStatement("return this") + .returns(builderClassName) + .build()); + + builderTypeSpec.addMethod(MethodSpec.methodBuilder(timeoutField.name) + .addModifiers(Modifier.PUBLIC) + .addParameter(Integer.class, timeoutField.name) + .addParameter(timeUnitField.type, timeUnitField.name) + .addStatement("this.$L = Optional.of($L)", timeoutField.name, timeoutField.name) + .addStatement("this.$L = $L", timeUnitField.name, timeUnitField.name) + .addStatement("return this") + .returns(builderClassName) + .build()); + + String constructorArgs = fields.stream().map(field -> field.builderField.name).collect(Collectors.joining(", ")); builderTypeSpec.addMethod(MethodSpec.methodBuilder("build") @@ -111,8 +166,8 @@ public GeneratedJavaFile generateFile() { MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder() .addModifiers(Modifier.PRIVATE) .addParameters(fields.stream() - .map(authSchemeFields -> ParameterSpec.builder( - authSchemeFields.builderField.type, authSchemeFields.builderField.name) + .map(field -> ParameterSpec.builder( + field.builderField.type, field.builderField.name) .build()) .collect(Collectors.toList())); for (RequestOption requestOption : fields) { @@ -133,6 +188,7 @@ public GeneratedJavaFile generateFile() { .build()); requestOptionsTypeSpec.addType(builderTypeSpec.build()); + JavaFile requestOptionsFile = JavaFile.builder(className.packageName(), requestOptionsTypeSpec.build()) .build(); return GeneratedJavaFile.builder() @@ -141,6 +197,37 @@ public GeneratedJavaFile generateFile() { .build(); } + private void createRequestOptionField( + String getterFunctionName, + FieldSpec.Builder fieldSpecBuilder, + String initializer, + TypeSpec.Builder requestOptionsTypeSpec, + TypeSpec.Builder builderTypeSpec, + List fields + ) { + FieldSpec field = fieldSpecBuilder.build(); + requestOptionsTypeSpec.addField(fieldSpecBuilder + .addModifiers(Modifier.FINAL) + .build()); + fields.add(new RequestOption( + fieldSpecBuilder + .initializer(initializer) + .build(), + field + )); + FieldSpec builderField = FieldSpec.builder( + field.type, field.name, Modifier.PRIVATE) + .initializer(initializer) + .build(); + builderTypeSpec.addField(builderField); + + requestOptionsTypeSpec.addMethod(MethodSpec.methodBuilder(getterFunctionName) + .addModifiers(Modifier.PUBLIC) + .addStatement("return $N", field.name) + .returns(field.type) + .build()); + } + private static class RequestOption { private final FieldSpec builderField; private final FieldSpec requestOptionsField; diff --git a/generators/java/sdk/src/main/java/com/fern/java/client/generators/endpoint/AbstractEndpointWriter.java b/generators/java/sdk/src/main/java/com/fern/java/client/generators/endpoint/AbstractEndpointWriter.java index dda95e25323..1a2408bfd96 100644 --- a/generators/java/sdk/src/main/java/com/fern/java/client/generators/endpoint/AbstractEndpointWriter.java +++ b/generators/java/sdk/src/main/java/com/fern/java/client/generators/endpoint/AbstractEndpointWriter.java @@ -80,6 +80,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.lang.model.element.Modifier; + +import okhttp3.OkHttpClient; import okhttp3.Response; public abstract class AbstractEndpointWriter { @@ -275,14 +277,30 @@ public abstract CodeBlock getInitializeRequestCodeBlock( boolean sendContentType); public final CodeBlock getResponseParserCodeBlock() { + String defaultedClientName = "client"; CodeBlock.Builder httpResponseBuilder = CodeBlock.builder() .beginControlFlow("try") + // Default the request client + .addStatement( + "$T $L = $N.$N()", + OkHttpClient.class, + defaultedClientName, + clientOptionsField, + generatedClientOptions.httpClient()) + .beginControlFlow("if ($L.getTimeout().isPresent())", REQUEST_OPTIONS_PARAMETER_NAME) + // Set the client's readTimeout if requestOptions overrides it has one .addStatement( - "$T $L = $N.$N().newCall($L).execute()", + "$L = $L.newBuilder().readTimeout($N.getTimeout().get(), $N.getTimeoutTimeUnit()).build()", + defaultedClientName, + defaultedClientName, + REQUEST_OPTIONS_PARAMETER_NAME, + REQUEST_OPTIONS_PARAMETER_NAME) + .endControlFlow() + .addStatement( + "$T $L = $N.newCall($L).execute()", Response.class, getResponseName(), - clientOptionsField, - generatedClientOptions.httpClient(), + defaultedClientName, getOkhttpRequestName()) .beginControlFlow("if ($L.isSuccessful())", getResponseName()); if (httpEndpoint.getResponse().isPresent()) { diff --git a/seed/java-sdk/alias/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/alias/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/alias/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/alias/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/alias/gradlew.bat b/seed/java-sdk/alias/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/alias/gradlew.bat +++ b/seed/java-sdk/alias/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/alias/src/main/java/com/seed/alias/core/RequestOptions.java b/seed/java-sdk/alias/src/main/java/com/seed/alias/core/RequestOptions.java index c8d594afa0a..09c720916ae 100644 --- a/seed/java-sdk/alias/src/main/java/com/seed/alias/core/RequestOptions.java +++ b/seed/java-sdk/alias/src/main/java/com/seed/alias/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/api-wide-base-path/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/api-wide-base-path/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/api-wide-base-path/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/api-wide-base-path/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/api-wide-base-path/gradlew.bat b/seed/java-sdk/api-wide-base-path/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/api-wide-base-path/gradlew.bat +++ b/seed/java-sdk/api-wide-base-path/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/core/RequestOptions.java b/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/core/RequestOptions.java index 3842568fe1c..6ec3c116eaf 100644 --- a/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/core/RequestOptions.java +++ b/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/resources/service/ServiceClient.java b/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/resources/service/ServiceClient.java index ebd4f561fc7..d3ed37ebe60 100644 --- a/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/resources/service/ServiceClient.java +++ b/seed/java-sdk/api-wide-base-path/src/main/java/com/seed/apiWideBasePath/resources/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -37,8 +38,13 @@ public void post(String serviceParam, int endpointParam, RequestOptions requestO .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/audiences/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/audiences/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/audiences/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/audiences/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/audiences/gradlew.bat b/seed/java-sdk/audiences/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/audiences/gradlew.bat +++ b/seed/java-sdk/audiences/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/audiences/src/main/java/com/seed/audiences/core/RequestOptions.java b/seed/java-sdk/audiences/src/main/java/com/seed/audiences/core/RequestOptions.java index 66ba5c346d5..c0a59899fe7 100644 --- a/seed/java-sdk/audiences/src/main/java/com/seed/audiences/core/RequestOptions.java +++ b/seed/java-sdk/audiences/src/main/java/com/seed/audiences/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foldera/service/ServiceClient.java b/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foldera/service/ServiceClient.java index e4efa5ddf12..db4a8e1ce57 100644 --- a/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foldera/service/ServiceClient.java +++ b/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foldera/service/ServiceClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; public class ServiceClient { @@ -35,8 +36,13 @@ public Response getDirectThread(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - okhttp3.Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + okhttp3.Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Response.class); } diff --git a/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foo/FooClient.java b/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foo/FooClient.java index 3283d6e4925..4ff2afa4b53 100644 --- a/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foo/FooClient.java +++ b/seed/java-sdk/audiences/src/main/java/com/seed/audiences/resources/foo/FooClient.java @@ -15,6 +15,7 @@ import java.util.Map; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -59,8 +60,13 @@ public ImportingType find(FindRequest request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json"); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ImportingType.class); } diff --git a/seed/java-sdk/auth-environment-variables/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/auth-environment-variables/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/auth-environment-variables/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/auth-environment-variables/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/auth-environment-variables/gradlew.bat b/seed/java-sdk/auth-environment-variables/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/auth-environment-variables/gradlew.bat +++ b/seed/java-sdk/auth-environment-variables/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/core/RequestOptions.java b/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/core/RequestOptions.java index fbe0a3000f1..06772ff6990 100644 --- a/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/core/RequestOptions.java +++ b/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String apiKey; - private RequestOptions(String apiKey) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String apiKey, Optional timeout, TimeUnit timeoutTimeUnit) { this.apiKey = apiKey; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String apiKey = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(apiKey); + return new RequestOptions(apiKey, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/resources/service/ServiceClient.java b/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/resources/service/ServiceClient.java index d589fa7ffb5..4370d9164ce 100644 --- a/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/resources/service/ServiceClient.java +++ b/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/resources/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -42,8 +43,13 @@ public String getWithApiKey(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/basic-auth/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/basic-auth/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/basic-auth/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/basic-auth/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/basic-auth/gradlew.bat b/seed/java-sdk/basic-auth/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/basic-auth/gradlew.bat +++ b/seed/java-sdk/basic-auth/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/core/RequestOptions.java b/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/core/RequestOptions.java index 2a7f260e34c..033a4a0ae77 100644 --- a/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/core/RequestOptions.java +++ b/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/resources/basicauth/BasicAuthClient.java b/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/resources/basicauth/BasicAuthClient.java index 0c73aad93bb..216e68ff47a 100644 --- a/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/resources/basicauth/BasicAuthClient.java +++ b/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/resources/basicauth/BasicAuthClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -44,8 +45,13 @@ public boolean getWithBasicAuth(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } @@ -86,8 +92,13 @@ public boolean postWithBasicAuth(Object request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/bearer-token-environment-variable/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/bearer-token-environment-variable/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/bearer-token-environment-variable/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/bearer-token-environment-variable/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/bearer-token-environment-variable/gradlew.bat b/seed/java-sdk/bearer-token-environment-variable/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/bearer-token-environment-variable/gradlew.bat +++ b/seed/java-sdk/bearer-token-environment-variable/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/core/RequestOptions.java b/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/core/RequestOptions.java index 087de6c8fde..a632d7ee1cf 100644 --- a/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/core/RequestOptions.java +++ b/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String apiKey; - private RequestOptions(String apiKey) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String apiKey, Optional timeout, TimeUnit timeoutTimeUnit) { this.apiKey = apiKey; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String apiKey = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(apiKey); + return new RequestOptions(apiKey, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/resources/service/ServiceClient.java b/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/resources/service/ServiceClient.java index d278e2f7a5e..df7b0bbed1c 100644 --- a/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/resources/service/ServiceClient.java +++ b/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/resources/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -42,8 +43,13 @@ public String getWithBearerToken(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/bytes/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/bytes/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/bytes/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/bytes/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/bytes/gradlew.bat b/seed/java-sdk/bytes/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/bytes/gradlew.bat +++ b/seed/java-sdk/bytes/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/bytes/src/main/java/com/seed/bytes/core/RequestOptions.java b/seed/java-sdk/bytes/src/main/java/com/seed/bytes/core/RequestOptions.java index 6514abcb152..bb199b03fff 100644 --- a/seed/java-sdk/bytes/src/main/java/com/seed/bytes/core/RequestOptions.java +++ b/seed/java-sdk/bytes/src/main/java/com/seed/bytes/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java b/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java index 97d494d5683..5bf2d48f837 100644 --- a/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java +++ b/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -38,8 +39,13 @@ public void upload(byte[] request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/octet-stream") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/circular-references/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/circular-references/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/circular-references/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/circular-references/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/circular-references/gradlew.bat b/seed/java-sdk/circular-references/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/circular-references/gradlew.bat +++ b/seed/java-sdk/circular-references/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/circular-references/src/main/java/com/seed/api/core/RequestOptions.java b/seed/java-sdk/circular-references/src/main/java/com/seed/api/core/RequestOptions.java index 26cef452c39..7700c11b780 100644 --- a/seed/java-sdk/circular-references/src/main/java/com/seed/api/core/RequestOptions.java +++ b/seed/java-sdk/circular-references/src/main/java/com/seed/api/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/custom-auth/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/custom-auth/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/custom-auth/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/custom-auth/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/custom-auth/gradlew.bat b/seed/java-sdk/custom-auth/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/custom-auth/gradlew.bat +++ b/seed/java-sdk/custom-auth/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/core/RequestOptions.java b/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/core/RequestOptions.java index 74a354614c8..c5fb99a6883 100644 --- a/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/core/RequestOptions.java +++ b/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String customAuthScheme; - private RequestOptions(String customAuthScheme) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String customAuthScheme, Optional timeout, TimeUnit timeoutTimeUnit) { this.customAuthScheme = customAuthScheme; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String customAuthScheme = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder customAuthScheme(String customAuthScheme) { this.customAuthScheme = customAuthScheme; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(customAuthScheme); + return new RequestOptions(customAuthScheme, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/resources/customauth/CustomAuthClient.java b/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/resources/customauth/CustomAuthClient.java index 1ed4f0b5f87..6fe97408d20 100644 --- a/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/resources/customauth/CustomAuthClient.java +++ b/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/resources/customauth/CustomAuthClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -44,8 +45,13 @@ public boolean getWithCustomAuth(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } @@ -86,8 +92,13 @@ public boolean postWithCustomAuth(Object request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/enum/.github/workflows/ci.yml b/seed/java-sdk/enum/.github/workflows/ci.yml new file mode 100644 index 00000000000..260533c2a98 --- /dev/null +++ b/seed/java-sdk/enum/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: ci + +on: [push] + +jobs: + compile: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up Java + id: setup-jre + uses: actions/setup-java@v1 + with: + java-version: "11" + architecture: x64 + + - name: Compile + run: ./gradlew compileJava + + test: + needs: [ compile ] + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up Java + id: setup-jre + uses: actions/setup-java@v1 + with: + java-version: "11" + architecture: x64 + + - name: Test + run: ./gradlew test diff --git a/seed/java-sdk/enum/.gitignore b/seed/java-sdk/enum/.gitignore new file mode 100644 index 00000000000..d4199abc2cd --- /dev/null +++ b/seed/java-sdk/enum/.gitignore @@ -0,0 +1,24 @@ +*.class +.project +.gradle +? +.classpath +.checkstyle +.settings +.node +build + +# IntelliJ +*.iml +*.ipr +*.iws +.idea/ +out/ + +# Eclipse/IntelliJ APT +generated_src/ +generated_testSrc/ +generated/ + +bin +build \ No newline at end of file diff --git a/seed/java-sdk/enum/build.gradle b/seed/java-sdk/enum/build.gradle new file mode 100644 index 00000000000..26e4017afc4 --- /dev/null +++ b/seed/java-sdk/enum/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'java-library' + id 'maven-publish' + id 'com.diffplug.spotless' version '6.11.0' +} + +repositories { + mavenCentral() + maven { + url 'https://s01.oss.sonatype.org/content/repositories/releases/' + } +} + +dependencies { + api 'com.squareup.okhttp3:okhttp:4.12.0' + api 'com.fasterxml.jackson.core:jackson-databind:2.13.0' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.3' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.3' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' +} + + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +spotless { + java { + palantirJavaFormat() + } +} + +java { + withSourcesJar() + withJavadocJar() +} + +test { + useJUnitPlatform() + testLogging { + showStandardStreams = true + } +} diff --git a/seed/java-sdk/enum/sample-app/build.gradle b/seed/java-sdk/enum/sample-app/build.gradle new file mode 100644 index 00000000000..4ee8f227b7a --- /dev/null +++ b/seed/java-sdk/enum/sample-app/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java-library' +} + +repositories { + mavenCentral() + maven { + url 'https://s01.oss.sonatype.org/content/repositories/releases/' + } +} + +dependencies { + implementation rootProject +} + + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + diff --git a/seed/java-sdk/enum/sample-app/src/main/java/sample/App.java b/seed/java-sdk/enum/sample-app/src/main/java/sample/App.java new file mode 100644 index 00000000000..1c862c0c09c --- /dev/null +++ b/seed/java-sdk/enum/sample-app/src/main/java/sample/App.java @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package sample; + +import java.lang.String; + +public final class App { + public static void main(String[] args) { + // import com.seed.enum.SeedEnumClient + } +} diff --git a/seed/java-sdk/enum/settings.gradle b/seed/java-sdk/enum/settings.gradle new file mode 100644 index 00000000000..aed36fec10b --- /dev/null +++ b/seed/java-sdk/enum/settings.gradle @@ -0,0 +1 @@ +include 'sample-app' \ No newline at end of file diff --git a/seed/java-sdk/enum/snippet.json b/seed/java-sdk/enum/snippet.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/SeedEnumClient.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/SeedEnumClient.java new file mode 100644 index 00000000000..12c4b5acd59 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/SeedEnumClient.java @@ -0,0 +1,45 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum; + +import com.seed.enum.core.ClientOptions; +import com.seed.enum.core.Suppliers; +import com.seed.enum.resources.inlinedrequest.InlinedRequestClient; +import com.seed.enum.resources.pathparam.PathParamClient; +import com.seed.enum.resources.queryparam.QueryParamClient; +import java.util.function.Supplier; + +public class SeedEnumClient { + protected final ClientOptions clientOptions; + + protected final Supplier inlinedRequestClient; + + protected final Supplier pathParamClient; + + protected final Supplier queryParamClient; + + public SeedEnumClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + this.inlinedRequestClient = Suppliers.memoize(() -> new InlinedRequestClient(clientOptions)); + this.pathParamClient = Suppliers.memoize(() -> new PathParamClient(clientOptions)); + this.queryParamClient = Suppliers.memoize(() -> new QueryParamClient(clientOptions)); + } + + public InlinedRequestClient inlinedRequest() { + return this.inlinedRequestClient.get(); + } + + public PathParamClient pathParam() { + return this.pathParamClient.get(); + } + + public QueryParamClient queryParam() { + return this.queryParamClient.get(); + } + + public static SeedEnumClientBuilder builder() { + return new SeedEnumClientBuilder(); + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/SeedEnumClientBuilder.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/SeedEnumClientBuilder.java new file mode 100644 index 00000000000..e998d8eda57 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/SeedEnumClientBuilder.java @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum; + +import com.seed.enum.core.ClientOptions; +import com.seed.enum.core.Environment; +import java.lang.String; + +public final class SeedEnumClientBuilder { + private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + + private Environment environment; + + public SeedEnumClientBuilder url(String url) { + this.environment = Environment.custom(url); + return this; + } + + public SeedEnumClient build() { + clientOptionsBuilder.environment(this.environment); + return new SeedEnumClient(clientOptionsBuilder.build()); + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ApiError.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ApiError.java new file mode 100644 index 00000000000..c217662b019 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ApiError.java @@ -0,0 +1,33 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import java.lang.Object; +import java.lang.RuntimeException; +import java.lang.String; + +public final class ApiError extends RuntimeException { + private final int statusCode; + + private final Object body; + + public ApiError(int statusCode, Object body) { + this.statusCode = statusCode; + this.body = body; + } + + public int statusCode() { + return this.statusCode; + } + + public Object body() { + return this.body; + } + + @java.lang.Override + public String toString() { + return "ApiError{" + "statusCode: " + statusCode + ", body: " + body + "}"; + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ClientOptions.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ClientOptions.java new file mode 100644 index 00000000000..3322e981c43 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ClientOptions.java @@ -0,0 +1,85 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; +import okhttp3.OkHttpClient; + +public final class ClientOptions { + private final Environment environment; + + private final Map headers; + + private final Map> headerSuppliers; + + private final OkHttpClient httpClient; + + private ClientOptions(Environment environment, Map headers, + Map> headerSuppliers, OkHttpClient httpClient) { + this.environment = environment; + this.headers = new HashMap<>(); + this.headers.putAll(headers); + this.headers.putAll(Map.of("X-Fern-Language", "JAVA")); + this.headerSuppliers = headerSuppliers; + this.httpClient = httpClient; + ; + } + + public Environment environment() { + return this.environment; + } + + public Map headers(RequestOptions requestOptions) { + Map values = new HashMap<>(this.headers); + headerSuppliers.forEach((key, supplier) -> { + values.put(key, supplier.get()); + } ); + if (requestOptions != null) { + values.putAll(requestOptions.getHeaders()); + } + return values; + } + + public OkHttpClient httpClient() { + return this.httpClient; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private Environment environment; + + private final Map headers = new HashMap<>(); + + private final Map> headerSuppliers = new HashMap<>(); + + public Builder environment(Environment environment) { + this.environment = environment; + return this; + } + + public Builder addHeader(String key, String value) { + this.headers.put(key, value); + return this; + } + + public Builder addHeader(String key, Supplier value) { + this.headerSuppliers.put(key, value); + return this; + } + + public ClientOptions build() { + OkHttpClient okhttpClient = new OkHttpClient.Builder() + .addInterceptor(new RetryInterceptor(3)) + .build(); + return new ClientOptions(environment, headers, headerSuppliers, okhttpClient); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/DateTimeDeserializer.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/DateTimeDeserializer.java new file mode 100644 index 00000000000..ee3865e8eeb --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/DateTimeDeserializer.java @@ -0,0 +1,56 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalQueries; + +/** + * Custom deserializer that handles converting ISO8601 dates into {@link OffsetDateTime} objects. + */ +class DateTimeDeserializer extends JsonDeserializer { + private static final SimpleModule MODULE; + + static { + MODULE = new SimpleModule().addDeserializer(OffsetDateTime.class, new DateTimeDeserializer()); + } + + /** + * Gets a module wrapping this deserializer as an adapter for the Jackson ObjectMapper. + * + * @return A {@link SimpleModule} to be plugged onto Jackson ObjectMapper. + */ + public static SimpleModule getModule() { + return MODULE; + } + + @Override + public OffsetDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException { + JsonToken token = parser.currentToken(); + if (token == JsonToken.VALUE_NUMBER_INT) { + return OffsetDateTime.ofInstant(Instant.ofEpochSecond(parser.getValueAsLong()), ZoneOffset.UTC); + } else { + TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest( + parser.getValueAsString(), OffsetDateTime::from, LocalDateTime::from); + + if (temporal.query(TemporalQueries.offset()) == null) { + return LocalDateTime.from(temporal).atOffset(ZoneOffset.UTC); + } else { + return OffsetDateTime.from(temporal); + } + } + } +} \ No newline at end of file diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Environment.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Environment.java new file mode 100644 index 00000000000..fc40c817b22 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Environment.java @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import java.lang.String; + +public final class Environment { + private final String url; + + private Environment(String url) { + this.url = url; + } + + public String getUrl() { + return this.url; + } + + public static Environment custom(String url) { + return new Environment(url); + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/MediaTypes.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/MediaTypes.java new file mode 100644 index 00000000000..f5e5e53aaeb --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/MediaTypes.java @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import okhttp3.MediaType; + +public final class MediaTypes { + + public static final MediaType APPLICATION_JSON = MediaType.parse("application/json"); + + private MediaTypes() { + } + +} \ No newline at end of file diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ObjectMappers.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ObjectMappers.java new file mode 100644 index 00000000000..111d6099f66 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/ObjectMappers.java @@ -0,0 +1,41 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.io.IOException; +import java.lang.Integer; +import java.lang.Object; +import java.lang.String; + +public final class ObjectMappers { + public static final ObjectMapper JSON_MAPPER = JsonMapper.builder() + .addModule(new Jdk8Module()) + .addModule(new JavaTimeModule()) + .addModule(DateTimeDeserializer.getModule()) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); + + private ObjectMappers() { + } + + public static String stringify(Object o) { + try { + return JSON_MAPPER.setSerializationInclusion(JsonInclude.Include.ALWAYS) + .writerWithDefaultPrettyPrinter() + .writeValueAsString(o); + } + catch (IOException e) { + return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()); + } + } + } diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/RequestOptions.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/RequestOptions.java new file mode 100644 index 00000000000..fafdbb046c0 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/RequestOptions.java @@ -0,0 +1,60 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import java.lang.Integer; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +public final class RequestOptions { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } + + public Map getHeaders() { + Map headers = new HashMap<>(); + return headers; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Optional timeout) { + this.timeout = timeout; + return this; + } + + public Builder timeoutTimeUnit(TimeUnit timeoutTimeUnit) { + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + + public RequestOptions build() { + return new RequestOptions(timeout, timeoutTimeUnit); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/RetryInterceptor.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/RetryInterceptor.java new file mode 100644 index 00000000000..eb67a6288bd --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/RetryInterceptor.java @@ -0,0 +1,79 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import java.io.IOException; +import java.time.Duration; +import java.util.Optional; +import java.util.Random; +import okhttp3.Interceptor; +import okhttp3.Response; + +public class RetryInterceptor implements Interceptor { + + private static final Duration ONE_SECOND = Duration.ofSeconds(1); + private final ExponentialBackoff backoff; + private final Random random = new Random(); + + public RetryInterceptor(int maxRetries) { + this.backoff = new ExponentialBackoff(maxRetries); + } + + @Override + public Response intercept(Chain chain) throws IOException { + Response response = chain.proceed(chain.request()); + + if (shouldRetry(response.code())) { + return retryChain(response, chain); + } + + return response; + } + + private Response retryChain(Response response, Chain chain) throws IOException { + Optional nextBackoff = this.backoff.nextBackoff(); + while (nextBackoff.isPresent()) { + try { + Thread.sleep(nextBackoff.get().toMillis()); + } catch (InterruptedException e) { + throw new IOException("Interrupted while trying request", e); + } + response.close(); + response = chain.proceed(chain.request()); + if (shouldRetry(response.code())) { + nextBackoff = this.backoff.nextBackoff(); + } else { + return response; + } + } + + return response; + } + + private static boolean shouldRetry(int statusCode) { + return statusCode == 408 || statusCode == 409 || statusCode == 429 || statusCode >= 500; + } + + private final class ExponentialBackoff { + + private final int maxNumRetries; + + private int retryNumber = 0; + + ExponentialBackoff(int maxNumRetries) { + this.maxNumRetries = maxNumRetries; + } + + public Optional nextBackoff() { + retryNumber += 1; + if (retryNumber > maxNumRetries) { + return Optional.empty(); + } + + int upperBound = (int) Math.pow(2, retryNumber); + return Optional.of(ONE_SECOND.multipliedBy(random.nextInt(upperBound))); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Stream.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Stream.java new file mode 100644 index 00000000000..49475845886 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Stream.java @@ -0,0 +1,98 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.io.Reader; +import java.util.Scanner; + +/** + * The {@code Stream} class implmenets {@link Iterable} to provide a simple mechanism for reading and parsing + * objects of a given type from data streamed via a {@link Reader} using a specified delimiter. + *

+ * {@code Stream} assumes that data is being pushed to the provided {@link Reader} asynchronously and utilizes a + * {@code Scanner} to block during iteration if the next object is not available. + * + * @param The type of objects in the stream. + */ +public final class Stream implements Iterable { + /** + * The {@link Class} of the objects in the stream. + */ + private final Class valueType; + /** + * The {@link Scanner} used for reading from the input stream and blocking when neede during iteration. + */ + private final Scanner scanner; + + /** + * Constructs a new {@code Stream} with the specified value type, reader, and delimiter. + * + * @param valueType The class of the objects in the stream. + * @param reader The reader that provides the streamed data. + * @param delimiter The delimiter used to separate elements in the stream. + */ + public Stream(Class valueType, Reader reader, String delimiter) { + this.scanner = new Scanner(reader).useDelimiter(delimiter); + this.valueType = valueType; + } + + /** + * Returns an iterator over the elements in this stream that blocks during iteration when the next object is + * not yet available. + * + * @return An iterator that can be used to traverse the elements in the stream. + */ + @Override + public Iterator iterator() { + return new Iterator() { + /** + * Returns {@code true} if there are more elements in the stream. + *

+ * Will block and wait for input if the stream has not ended and the next object is not yet available. + * + * @return {@code true} if there are more elements, {@code false} otherwise. + */ + @Override + public boolean hasNext() { + return scanner.hasNext(); + } + + /** + * Returns the next element in the stream. + *

+ * Will block and wait for input if the stream has not ended and the next object is not yet available. + * + * @return The next element in the stream. + * @throws NoSuchElementException If there are no more elements in the stream. + */ + @Override + public T next() { + if (!scanner.hasNext()) { + throw new NoSuchElementException(); + } else { + try { + T parsedResponse = + ObjectMappers.JSON_MAPPER.readValue(scanner.next().trim(), valueType); + return parsedResponse; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + /** + * Removing elements from {@code Stream} is not supported. + * + * @throws UnsupportedOperationException Always, as removal is not supported. + */ + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } +} \ No newline at end of file diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Suppliers.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Suppliers.java new file mode 100644 index 00000000000..aec4eb55b6d --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/core/Suppliers.java @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.core; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; + +public final class Suppliers { + private Suppliers() { + } + + public static Supplier memoize(Supplier delegate) { + AtomicReference value = new AtomicReference<>(); + return () -> { + T val = value.get(); + if (val == null) { + val = value.updateAndGet(cur -> cur == null ? Objects.requireNonNull(delegate.get()) : cur); + } + return val; + } ; + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/inlinedrequest/InlinedRequestClient.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/inlinedrequest/InlinedRequestClient.java new file mode 100644 index 00000000000..24b2caeb729 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/inlinedrequest/InlinedRequestClient.java @@ -0,0 +1,72 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.resources.inlinedrequest; + +import com.seed.enum.core.ApiError; +import com.seed.enum.core.ClientOptions; +import com.seed.enum.core.MediaTypes; +import com.seed.enum.core.ObjectMappers; +import com.seed.enum.core.RequestOptions; +import com.seed.enum.resources.inlinedrequest.requests.SendEnumInlinedRequest; +import java.io.IOException; +import java.lang.Exception; +import java.lang.Object; +import java.lang.RuntimeException; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class InlinedRequestClient { + protected final ClientOptions clientOptions; + + public InlinedRequestClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + public void send() { + send(SendEnumInlinedRequest.builder().build()); + } + + public void send(SendEnumInlinedRequest request) { + send(request,null); + } + + public void send(SendEnumInlinedRequest request, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder() + + .addPathSegments("inlined-request") + .build(); + RequestBody body; + try { + body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } + catch(Exception e) { + throw new RuntimeException(e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", body) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Content-Type", "application/json") + .build(); + try { + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); + if (response.isSuccessful()) { + return; + } + throw new ApiError(response.code(), ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/inlinedrequest/requests/SendEnumInlinedRequest.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/inlinedrequest/requests/SendEnumInlinedRequest.java new file mode 100644 index 00000000000..2323d1e9a99 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/inlinedrequest/requests/SendEnumInlinedRequest.java @@ -0,0 +1,108 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.resources.inlinedrequest.requests; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.seed.enum.core.ObjectMappers; +import com.seed.enum.types.Operand; +import java.lang.Object; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize( + builder = SendEnumInlinedRequest.Builder.class +) +public final class SendEnumInlinedRequest { + private final Optional value; + + private final Map additionalProperties; + + private SendEnumInlinedRequest(Optional value, + Map additionalProperties) { + this.value = value; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("value") + public Optional getValue() { + return value; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SendEnumInlinedRequest && equalTo((SendEnumInlinedRequest) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(SendEnumInlinedRequest other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonIgnoreProperties( + ignoreUnknown = true + ) + public static final class Builder { + private Optional value = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() { + } + + public Builder from(SendEnumInlinedRequest other) { + value(other.getValue()); + return this; + } + + @JsonSetter( + value = "value", + nulls = Nulls.SKIP + ) + public Builder value(Optional value) { + this.value = value; + return this; + } + + public Builder value(Operand value) { + this.value = Optional.of(value); + return this; + } + + public SendEnumInlinedRequest build() { + return new SendEnumInlinedRequest(value, additionalProperties); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/pathparam/PathParamClient.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/pathparam/PathParamClient.java new file mode 100644 index 00000000000..ca8a988fec6 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/pathparam/PathParamClient.java @@ -0,0 +1,59 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.resources.pathparam; + +import com.seed.enum.core.ApiError; +import com.seed.enum.core.ClientOptions; +import com.seed.enum.core.ObjectMappers; +import com.seed.enum.core.RequestOptions; +import com.seed.enum.types.Operand; +import java.io.IOException; +import java.lang.Object; +import java.lang.RuntimeException; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class PathParamClient { + protected final ClientOptions clientOptions; + + public PathParamClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + public void send(Operand value) { + send(value,null); + } + + public void send(Operand value, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder() + + .addPathSegments("path-param") + .addPathSegment(value.toString()) + .build(); + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", RequestBody.create("", null)) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .build(); + try { + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); + if (response.isSuccessful()) { + return; + } + throw new ApiError(response.code(), ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/QueryParamClient.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/QueryParamClient.java new file mode 100644 index 00000000000..1a1eca92b86 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/QueryParamClient.java @@ -0,0 +1,99 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.resources.queryparam; + +import com.seed.enum.core.ApiError; +import com.seed.enum.core.ClientOptions; +import com.seed.enum.core.ObjectMappers; +import com.seed.enum.core.RequestOptions; +import com.seed.enum.resources.queryparam.requests.SendEnumAsQueryParamRequest; +import com.seed.enum.resources.queryparam.requests.SendEnumListAsQueryParamRequest; +import java.io.IOException; +import java.lang.Object; +import java.lang.RuntimeException; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class QueryParamClient { + protected final ClientOptions clientOptions; + + public QueryParamClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + public void send() { + send(SendEnumAsQueryParamRequest.builder().build()); + } + + public void send(SendEnumAsQueryParamRequest request) { + send(request,null); + } + + public void send(SendEnumAsQueryParamRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder() + + .addPathSegments("query");if (request.getValue().isPresent()) { + httpUrl.addQueryParameter("value", request.getValue().get().toString()); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("POST", RequestBody.create("", null)) + .headers(Headers.of(clientOptions.headers(requestOptions))); + Request okhttpRequest = _requestBuilder.build(); + try { + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); + if (response.isSuccessful()) { + return; + } + throw new ApiError(response.code(), ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void sendList() { + sendList(SendEnumListAsQueryParamRequest.builder().build()); + } + + public void sendList(SendEnumListAsQueryParamRequest request) { + sendList(request,null); + } + + public void sendList(SendEnumListAsQueryParamRequest request, RequestOptions requestOptions) { + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder() + + .addPathSegments("query-list");if (request.getValue().isPresent()) { + httpUrl.addQueryParameter("value", request.getValue().get().toString()); + } + Request.Builder _requestBuilder = new Request.Builder() + .url(httpUrl.build()) + .method("POST", RequestBody.create("", null)) + .headers(Headers.of(clientOptions.headers(requestOptions))); + Request okhttpRequest = _requestBuilder.build(); + try { + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); + if (response.isSuccessful()) { + return; + } + throw new ApiError(response.code(), ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class)); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + } diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/requests/SendEnumAsQueryParamRequest.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/requests/SendEnumAsQueryParamRequest.java new file mode 100644 index 00000000000..942c70d417c --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/requests/SendEnumAsQueryParamRequest.java @@ -0,0 +1,108 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.resources.queryparam.requests; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.seed.enum.core.ObjectMappers; +import com.seed.enum.types.Operand; +import java.lang.Object; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize( + builder = SendEnumAsQueryParamRequest.Builder.class +) +public final class SendEnumAsQueryParamRequest { + private final Optional value; + + private final Map additionalProperties; + + private SendEnumAsQueryParamRequest(Optional value, + Map additionalProperties) { + this.value = value; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("value") + public Optional getValue() { + return value; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SendEnumAsQueryParamRequest && equalTo((SendEnumAsQueryParamRequest) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(SendEnumAsQueryParamRequest other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonIgnoreProperties( + ignoreUnknown = true + ) + public static final class Builder { + private Optional value = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() { + } + + public Builder from(SendEnumAsQueryParamRequest other) { + value(other.getValue()); + return this; + } + + @JsonSetter( + value = "value", + nulls = Nulls.SKIP + ) + public Builder value(Optional value) { + this.value = value; + return this; + } + + public Builder value(Operand value) { + this.value = Optional.of(value); + return this; + } + + public SendEnumAsQueryParamRequest build() { + return new SendEnumAsQueryParamRequest(value, additionalProperties); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/requests/SendEnumListAsQueryParamRequest.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/requests/SendEnumListAsQueryParamRequest.java new file mode 100644 index 00000000000..543ef8710b6 --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/resources/queryparam/requests/SendEnumListAsQueryParamRequest.java @@ -0,0 +1,108 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.resources.queryparam.requests; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.seed.enum.core.ObjectMappers; +import com.seed.enum.types.Operand; +import java.lang.Object; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize( + builder = SendEnumListAsQueryParamRequest.Builder.class +) +public final class SendEnumListAsQueryParamRequest { + private final Optional value; + + private final Map additionalProperties; + + private SendEnumListAsQueryParamRequest(Optional value, + Map additionalProperties) { + this.value = value; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("value") + public Optional getValue() { + return value; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SendEnumListAsQueryParamRequest && equalTo((SendEnumListAsQueryParamRequest) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(SendEnumListAsQueryParamRequest other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static Builder builder() { + return new Builder(); + } + + @JsonIgnoreProperties( + ignoreUnknown = true + ) + public static final class Builder { + private Optional value = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() { + } + + public Builder from(SendEnumListAsQueryParamRequest other) { + value(other.getValue()); + return this; + } + + @JsonSetter( + value = "value", + nulls = Nulls.SKIP + ) + public Builder value(Optional value) { + this.value = value; + return this; + } + + public Builder value(Operand value) { + this.value = Optional.of(value); + return this; + } + + public SendEnumListAsQueryParamRequest build() { + return new SendEnumListAsQueryParamRequest(value, additionalProperties); + } + } +} diff --git a/seed/java-sdk/enum/src/main/java/com/seed/enum/types/Operand.java b/seed/java-sdk/enum/src/main/java/com/seed/enum/types/Operand.java new file mode 100644 index 00000000000..7935e68f9ac --- /dev/null +++ b/seed/java-sdk/enum/src/main/java/com/seed/enum/types/Operand.java @@ -0,0 +1,28 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum.types; + +import com.fasterxml.jackson.annotation.JsonValue; +import java.lang.String; + +public enum Operand { + GREATER_THAN(">"), + + EQUAL_TO("="), + + LESS_THAN("less_than"); + + private final String value; + + Operand(String value) { + this.value = value; + } + + @JsonValue + @java.lang.Override + public String toString() { + return this.value; + } +} diff --git a/seed/java-sdk/enum/src/test/java/com/seed/enum/TestClient.java b/seed/java-sdk/enum/src/test/java/com/seed/enum/TestClient.java new file mode 100644 index 00000000000..f9e2f1651c9 --- /dev/null +++ b/seed/java-sdk/enum/src/test/java/com/seed/enum/TestClient.java @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.enum; + +public final class TestClient { + public void test() { + // Add tests here and mark this file in .fernignore + assert true; + } +} diff --git a/seed/java-sdk/error-property/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/error-property/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/error-property/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/error-property/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/error-property/gradlew.bat b/seed/java-sdk/error-property/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/error-property/gradlew.bat +++ b/seed/java-sdk/error-property/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/core/RequestOptions.java b/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/core/RequestOptions.java index 866cda6ccf1..8d2d82a9365 100644 --- a/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/core/RequestOptions.java +++ b/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/resources/propertybasederror/PropertyBasedErrorClient.java b/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/resources/propertybasederror/PropertyBasedErrorClient.java index b1bb32e61c2..0296372f870 100644 --- a/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/resources/propertybasederror/PropertyBasedErrorClient.java +++ b/seed/java-sdk/error-property/src/main/java/com/seed/errorProperty/resources/propertybasederror/PropertyBasedErrorClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -42,8 +43,13 @@ public String throwError(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/examples/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/examples/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/examples/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/examples/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/examples/gradlew.bat b/seed/java-sdk/examples/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/examples/gradlew.bat +++ b/seed/java-sdk/examples/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClient.java b/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClient.java index 42bd66257e3..e056be7ea50 100644 --- a/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClient.java +++ b/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClient.java @@ -16,6 +16,7 @@ import java.util.function.Supplier; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -58,8 +59,13 @@ public String echo(String request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/examples/src/main/java/com/seed/examples/core/RequestOptions.java b/seed/java-sdk/examples/src/main/java/com/seed/examples/core/RequestOptions.java index d97c040b772..192049a44ec 100644 --- a/seed/java-sdk/examples/src/main/java/com/seed/examples/core/RequestOptions.java +++ b/seed/java-sdk/examples/src/main/java/com/seed/examples/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/notification/service/ServiceClient.java b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/notification/service/ServiceClient.java index 8485d11b8d2..c12421105e3 100644 --- a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/notification/service/ServiceClient.java +++ b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/notification/service/ServiceClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -38,8 +39,13 @@ public Exception getException(String notificationId, RequestOptions requestOptio .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Exception.class); } diff --git a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/service/ServiceClient.java b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/service/ServiceClient.java index 013dce0a326..1027fc6f326 100644 --- a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/service/ServiceClient.java +++ b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/file/service/ServiceClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -44,8 +45,13 @@ public File getFile(String filename, GetFileRequest request, RequestOptions requ _requestBuilder.addHeader("X-File-API-Version", request.getXFileApiVersion()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), File.class); } diff --git a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/health/service/ServiceClient.java b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/health/service/ServiceClient.java index b9b265bc786..3f749ab5f5c 100644 --- a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/health/service/ServiceClient.java +++ b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/health/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -36,8 +37,13 @@ public void check(String id, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -65,8 +71,13 @@ public boolean ping(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/service/ServiceClient.java b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/service/ServiceClient.java index 852c1dc0a6b..adfc011715a 100644 --- a/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/service/ServiceClient.java +++ b/seed/java-sdk/examples/src/main/java/com/seed/examples/resources/service/ServiceClient.java @@ -14,6 +14,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -42,8 +43,13 @@ public Movie getMovie(String movieId, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Movie.class); } @@ -78,8 +84,13 @@ public String createMovie(Movie request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -113,8 +124,13 @@ public Metadata getMetadata(GetMetadataRequest request, RequestOptions requestOp _requestBuilder.addHeader("X-API-Version", request.getXApiVersion()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Metadata.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/exhaustive/custom-dependency/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/exhaustive/custom-dependency/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/exhaustive/custom-dependency/gradlew.bat b/seed/java-sdk/exhaustive/custom-dependency/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/gradlew.bat +++ b/seed/java-sdk/exhaustive/custom-dependency/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/core/RequestOptions.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/core/RequestOptions.java index 4a94345a07a..ba482fad922 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/core/RequestOptions.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java index 7caf2149e46..ab7394eee86 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java @@ -17,6 +17,7 @@ import java.util.Set; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -52,8 +53,13 @@ public List getAndReturnListOfPrimitives(List request, RequestOp .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -91,8 +97,13 @@ public List getAndReturnListOfObjects( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -129,8 +140,13 @@ public Set getAndReturnSetOfPrimitives(Set request, RequestOptio .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -168,8 +184,13 @@ public Set getAndReturnSetOfObjects( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -206,8 +227,13 @@ public Map getAndReturnMapPrimToPrim(Map request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -246,8 +272,13 @@ public Map getAndReturnMapOfPrimToObject( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -292,8 +323,13 @@ public Optional getAndReturnOptional( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java index e22a3453cda..67f22ff0da6 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,8 +47,13 @@ public WeatherReport getAndReturnEnum(WeatherReport request, RequestOptions requ .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), WeatherReport.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java index 1882a9f5bd0..00285499213 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java @@ -13,6 +13,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -41,8 +42,13 @@ public String testGet(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -77,8 +83,13 @@ public ObjectWithOptionalField testPost(ObjectWithRequiredField request, Request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -114,8 +125,13 @@ public ObjectWithOptionalField testPut(String id, ObjectWithRequiredField reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -156,8 +172,13 @@ public ObjectWithOptionalField testPatch( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -186,8 +207,13 @@ public boolean testDelete(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java index 392db9f6c4a..d325ce042d5 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java @@ -16,6 +16,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -56,8 +57,13 @@ public ObjectWithOptionalField getAndReturnWithOptionalField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -94,8 +100,13 @@ public ObjectWithRequiredField getAndReturnWithRequiredField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithRequiredField.class); } @@ -131,8 +142,13 @@ public ObjectWithMapOfMap getAndReturnWithMapOfMap(ObjectWithMapOfMap request, R .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithMapOfMap.class); } @@ -174,8 +190,13 @@ public NestedObjectWithOptionalField getAndReturnNestedWithOptionalField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), NestedObjectWithOptionalField.class); @@ -213,8 +234,13 @@ public NestedObjectWithRequiredField getAndReturnNestedWithRequiredField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), NestedObjectWithRequiredField.class); diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java index 6c54532c8e0..87aa296af3c 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java @@ -14,6 +14,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -49,8 +50,13 @@ public String getWithPath(String param, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -84,8 +90,13 @@ public void getWithQuery(GetWithQuery request, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -119,8 +130,13 @@ public void getWithAllowMultipleQuery(GetWithMultipleQuery request, RequestOptio .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -155,8 +171,13 @@ public void getWithPathAndQuery(String param, GetWithPathAndQuery request, Reque .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -199,8 +220,13 @@ public String modifyWithPath(String param, String request, RequestOptions reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java index 1eccfa48453..1df7ef0160a 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java @@ -13,6 +13,7 @@ import java.util.UUID; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -48,8 +49,13 @@ public String getAndReturnString(String request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -85,8 +91,13 @@ public int getAndReturnInt(int request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), int.class); } @@ -122,8 +133,13 @@ public long getAndReturnLong(long request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), long.class); } @@ -159,8 +175,13 @@ public double getAndReturnDouble(double request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), double.class); } @@ -196,8 +217,13 @@ public boolean getAndReturnBool(boolean request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } @@ -233,8 +259,13 @@ public OffsetDateTime getAndReturnDatetime(OffsetDateTime request, RequestOption .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), OffsetDateTime.class); } @@ -270,8 +301,13 @@ public String getAndReturnDate(String request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -307,8 +343,13 @@ public UUID getAndReturnUuid(UUID request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), UUID.class); } @@ -344,8 +385,13 @@ public byte[] getAndReturnBase64(byte[] request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), byte[].class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java index 1c8da15ca80..b97bc5e412e 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,8 +47,13 @@ public Animal getAndReturnUnion(Animal request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Animal.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java index b0e96b530a9..143861b2eef 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java @@ -13,6 +13,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -55,8 +56,13 @@ public ObjectWithOptionalField postWithObjectBodyandResponse( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java index a9a9dc8c0c6..1338c54d154 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -51,8 +52,13 @@ public boolean postWithNoAuth(Object request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java index 6329ba168c8..a2be45418dc 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -38,8 +39,13 @@ public ObjectWithOptionalField getWithNoRequestBody(RequestOptions requestOption .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -67,8 +73,13 @@ public String postWithNoRequestBody(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java index 8a1015827e8..7179ba1fcfd 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -49,8 +50,13 @@ public void getWithCustomHeader(ReqWithHeaders request, RequestOptions requestOp _requestBuilder.addHeader("X-TEST-ENDPOINT-HEADER", request.getXTestEndpointHeader()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/exhaustive/forward-compatible-enums/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/gradlew.bat b/seed/java-sdk/exhaustive/forward-compatible-enums/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/gradlew.bat +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/core/RequestOptions.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/core/RequestOptions.java index 4a94345a07a..ba482fad922 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/core/RequestOptions.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java index 7caf2149e46..ab7394eee86 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java @@ -17,6 +17,7 @@ import java.util.Set; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -52,8 +53,13 @@ public List getAndReturnListOfPrimitives(List request, RequestOp .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -91,8 +97,13 @@ public List getAndReturnListOfObjects( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -129,8 +140,13 @@ public Set getAndReturnSetOfPrimitives(Set request, RequestOptio .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -168,8 +184,13 @@ public Set getAndReturnSetOfObjects( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -206,8 +227,13 @@ public Map getAndReturnMapPrimToPrim(Map request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -246,8 +272,13 @@ public Map getAndReturnMapOfPrimToObject( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -292,8 +323,13 @@ public Optional getAndReturnOptional( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java index e22a3453cda..67f22ff0da6 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,8 +47,13 @@ public WeatherReport getAndReturnEnum(WeatherReport request, RequestOptions requ .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), WeatherReport.class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java index 1882a9f5bd0..00285499213 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java @@ -13,6 +13,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -41,8 +42,13 @@ public String testGet(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -77,8 +83,13 @@ public ObjectWithOptionalField testPost(ObjectWithRequiredField request, Request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -114,8 +125,13 @@ public ObjectWithOptionalField testPut(String id, ObjectWithRequiredField reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -156,8 +172,13 @@ public ObjectWithOptionalField testPatch( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -186,8 +207,13 @@ public boolean testDelete(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java index 392db9f6c4a..d325ce042d5 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java @@ -16,6 +16,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -56,8 +57,13 @@ public ObjectWithOptionalField getAndReturnWithOptionalField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -94,8 +100,13 @@ public ObjectWithRequiredField getAndReturnWithRequiredField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithRequiredField.class); } @@ -131,8 +142,13 @@ public ObjectWithMapOfMap getAndReturnWithMapOfMap(ObjectWithMapOfMap request, R .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithMapOfMap.class); } @@ -174,8 +190,13 @@ public NestedObjectWithOptionalField getAndReturnNestedWithOptionalField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), NestedObjectWithOptionalField.class); @@ -213,8 +234,13 @@ public NestedObjectWithRequiredField getAndReturnNestedWithRequiredField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), NestedObjectWithRequiredField.class); diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java index 6c54532c8e0..87aa296af3c 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java @@ -14,6 +14,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -49,8 +50,13 @@ public String getWithPath(String param, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -84,8 +90,13 @@ public void getWithQuery(GetWithQuery request, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -119,8 +130,13 @@ public void getWithAllowMultipleQuery(GetWithMultipleQuery request, RequestOptio .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -155,8 +171,13 @@ public void getWithPathAndQuery(String param, GetWithPathAndQuery request, Reque .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -199,8 +220,13 @@ public String modifyWithPath(String param, String request, RequestOptions reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java index 1eccfa48453..1df7ef0160a 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java @@ -13,6 +13,7 @@ import java.util.UUID; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -48,8 +49,13 @@ public String getAndReturnString(String request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -85,8 +91,13 @@ public int getAndReturnInt(int request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), int.class); } @@ -122,8 +133,13 @@ public long getAndReturnLong(long request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), long.class); } @@ -159,8 +175,13 @@ public double getAndReturnDouble(double request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), double.class); } @@ -196,8 +217,13 @@ public boolean getAndReturnBool(boolean request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } @@ -233,8 +259,13 @@ public OffsetDateTime getAndReturnDatetime(OffsetDateTime request, RequestOption .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), OffsetDateTime.class); } @@ -270,8 +301,13 @@ public String getAndReturnDate(String request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -307,8 +343,13 @@ public UUID getAndReturnUuid(UUID request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), UUID.class); } @@ -344,8 +385,13 @@ public byte[] getAndReturnBase64(byte[] request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), byte[].class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java index 1c8da15ca80..b97bc5e412e 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,8 +47,13 @@ public Animal getAndReturnUnion(Animal request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Animal.class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java index b0e96b530a9..143861b2eef 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java @@ -13,6 +13,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -55,8 +56,13 @@ public ObjectWithOptionalField postWithObjectBodyandResponse( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java index a9a9dc8c0c6..1338c54d154 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -51,8 +52,13 @@ public boolean postWithNoAuth(Object request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java index 6329ba168c8..a2be45418dc 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -38,8 +39,13 @@ public ObjectWithOptionalField getWithNoRequestBody(RequestOptions requestOption .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -67,8 +73,13 @@ public String postWithNoRequestBody(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java index 8a1015827e8..7179ba1fcfd 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -49,8 +50,13 @@ public void getWithCustomHeader(ReqWithHeaders request, RequestOptions requestOp _requestBuilder.addHeader("X-TEST-ENDPOINT-HEADER", request.getXTestEndpointHeader()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/exhaustive/local-files/core/RequestOptions.java b/seed/java-sdk/exhaustive/local-files/core/RequestOptions.java index 8c9e71205bb..c4ad09f8506 100644 --- a/seed/java-sdk/exhaustive/local-files/core/RequestOptions.java +++ b/seed/java-sdk/exhaustive/local-files/core/RequestOptions.java @@ -4,15 +4,32 @@ package com.fern.sdk.core; +import java.lang.Integer; import java.lang.String; import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -30,13 +47,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/exhaustive/local-files/resources/endpoints/container/ContainerClient.java b/seed/java-sdk/exhaustive/local-files/resources/endpoints/container/ContainerClient.java index 6e80ddc3e0d..6bcf4a7f639 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/endpoints/container/ContainerClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/endpoints/container/ContainerClient.java @@ -22,6 +22,7 @@ import java.util.Set; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -57,7 +58,11 @@ public List getAndReturnListOfPrimitives(List request, .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), new TypeReference>() {}); } @@ -93,7 +98,11 @@ public List getAndReturnListOfObjects( .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), new TypeReference>() {}); } @@ -128,7 +137,11 @@ public Set getAndReturnSetOfPrimitives(Set request, .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), new TypeReference>() {}); } @@ -164,7 +177,11 @@ public Set getAndReturnSetOfObjects(Set>() {}); } @@ -199,7 +216,11 @@ public Map getAndReturnMapPrimToPrim(Map request .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), new TypeReference>() {}); } @@ -235,7 +256,11 @@ public Map getAndReturnMapOfPrimToObject( .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), new TypeReference>() {}); } @@ -278,7 +303,11 @@ public Optional getAndReturnOptional( .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), new TypeReference>() {}); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/endpoints/enum_/EnumClient.java b/seed/java-sdk/exhaustive/local-files/resources/endpoints/enum_/EnumClient.java index b682121e751..405208a63ce 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/endpoints/enum_/EnumClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/endpoints/enum_/EnumClient.java @@ -16,6 +16,7 @@ import java.lang.RuntimeException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -50,7 +51,11 @@ public WeatherReport getAndReturnEnum(WeatherReport request, RequestOptions requ .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), WeatherReport.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/endpoints/httpmethods/HttpMethodsClient.java b/seed/java-sdk/exhaustive/local-files/resources/endpoints/httpmethods/HttpMethodsClient.java index 79df8bea82c..244bf421d4c 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/endpoints/httpmethods/HttpMethodsClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/endpoints/httpmethods/HttpMethodsClient.java @@ -18,6 +18,7 @@ import java.lang.String; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,7 +47,11 @@ public String testGet(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -81,7 +86,11 @@ public ObjectWithOptionalField testPost(ObjectWithRequiredField request, .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -117,7 +126,11 @@ public ObjectWithOptionalField testPut(String id, ObjectWithRequiredField reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -157,7 +170,11 @@ public ObjectWithOptionalField testPatch(String id, ObjectWithOptionalField requ .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -185,7 +202,11 @@ public boolean testDelete(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/endpoints/object/ObjectClient.java b/seed/java-sdk/exhaustive/local-files/resources/endpoints/object/ObjectClient.java index 903df462128..d2b1ad66d5c 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/endpoints/object/ObjectClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/endpoints/object/ObjectClient.java @@ -20,6 +20,7 @@ import java.lang.RuntimeException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -59,7 +60,11 @@ public ObjectWithOptionalField getAndReturnWithOptionalField(ObjectWithOptionalF .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -94,7 +99,11 @@ public ObjectWithRequiredField getAndReturnWithRequiredField(ObjectWithRequiredF .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithRequiredField.class); } @@ -129,7 +138,11 @@ public ObjectWithMapOfMap getAndReturnWithMapOfMap(ObjectWithMapOfMap request, .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithMapOfMap.class); } @@ -169,7 +182,11 @@ public NestedObjectWithOptionalField getAndReturnNestedWithOptionalField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), NestedObjectWithOptionalField.class); } @@ -205,7 +222,11 @@ public NestedObjectWithRequiredField getAndReturnNestedWithRequiredField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), NestedObjectWithRequiredField.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/endpoints/params/ParamsClient.java b/seed/java-sdk/exhaustive/local-files/resources/endpoints/params/ParamsClient.java index b807bc50aab..e3f0b6cb6b0 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/endpoints/params/ParamsClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/endpoints/params/ParamsClient.java @@ -20,6 +20,7 @@ import java.lang.String; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -54,7 +55,11 @@ public String getWithPath(String param, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -86,7 +91,11 @@ public void getWithQuery(GetWithQuery request, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -119,7 +128,11 @@ public void getWithAllowMultipleQuery(GetWithMultipleQuery request, .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -152,7 +165,11 @@ public void getWithPathAndQuery(String param, GetWithPathAndQuery request, .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -193,7 +210,11 @@ public String modifyWithPath(String param, String request, RequestOptions reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/endpoints/primitive/PrimitiveClient.java b/seed/java-sdk/exhaustive/local-files/resources/endpoints/primitive/PrimitiveClient.java index 1537c4cbcd3..da46579b608 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/endpoints/primitive/PrimitiveClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/endpoints/primitive/PrimitiveClient.java @@ -18,6 +18,7 @@ import java.util.UUID; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -52,7 +53,11 @@ public String getAndReturnString(String request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -86,7 +91,11 @@ public int getAndReturnInt(int request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), int.class); } @@ -120,7 +129,11 @@ public long getAndReturnLong(long request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), long.class); } @@ -154,7 +167,11 @@ public double getAndReturnDouble(double request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), double.class); } @@ -188,7 +205,11 @@ public boolean getAndReturnBool(boolean request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } @@ -223,7 +244,11 @@ public OffsetDateTime getAndReturnDatetime(OffsetDateTime request, .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), OffsetDateTime.class); } @@ -257,7 +282,11 @@ public String getAndReturnDate(String request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -291,7 +320,11 @@ public UUID getAndReturnUuid(UUID request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), UUID.class); } @@ -325,7 +358,11 @@ public byte[] getAndReturnBase64(byte[] request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), byte[].class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/endpoints/union/UnionClient.java b/seed/java-sdk/exhaustive/local-files/resources/endpoints/union/UnionClient.java index 5fa6acbe899..a9dec640fbf 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/endpoints/union/UnionClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/endpoints/union/UnionClient.java @@ -16,6 +16,7 @@ import java.lang.RuntimeException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -50,7 +51,11 @@ public Animal getAndReturnUnion(Animal request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Animal.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/inlinedrequests/InlinedRequestsClient.java b/seed/java-sdk/exhaustive/local-files/resources/inlinedrequests/InlinedRequestsClient.java index abe277cffbc..4d4c7763f62 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/inlinedrequests/InlinedRequestsClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/inlinedrequests/InlinedRequestsClient.java @@ -17,6 +17,7 @@ import java.lang.RuntimeException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -58,7 +59,11 @@ public ObjectWithOptionalField postWithObjectBodyandResponse(PostWithObjectBody .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/noauth/NoAuthClient.java b/seed/java-sdk/exhaustive/local-files/resources/noauth/NoAuthClient.java index 5974b78931f..184c7da0cc5 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/noauth/NoAuthClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/noauth/NoAuthClient.java @@ -15,6 +15,7 @@ import java.lang.RuntimeException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -55,7 +56,11 @@ public boolean postWithNoAuth(Object request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/noreqbody/NoReqBodyClient.java b/seed/java-sdk/exhaustive/local-files/resources/noreqbody/NoReqBodyClient.java index fbb4cd243f5..cd39e52a02a 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/noreqbody/NoReqBodyClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/noreqbody/NoReqBodyClient.java @@ -15,6 +15,7 @@ import java.lang.String; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -42,7 +43,11 @@ public ObjectWithOptionalField getWithNoRequestBody(RequestOptions requestOption .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -69,7 +74,11 @@ public String postWithNoRequestBody(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/local-files/resources/reqwithheaders/ReqWithHeadersClient.java b/seed/java-sdk/exhaustive/local-files/resources/reqwithheaders/ReqWithHeadersClient.java index c2d3739e577..5f2bafebdee 100644 --- a/seed/java-sdk/exhaustive/local-files/resources/reqwithheaders/ReqWithHeadersClient.java +++ b/seed/java-sdk/exhaustive/local-files/resources/reqwithheaders/ReqWithHeadersClient.java @@ -16,6 +16,7 @@ import java.lang.RuntimeException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -52,7 +53,11 @@ public void getWithCustomHeader(ReqWithHeaders request, RequestOptions requestOp _requestBuilder.addHeader("X-TEST-ENDPOINT-HEADER", request.getXTestEndpointHeader()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder().readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()).build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/exhaustive/no-custom-config/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/exhaustive/no-custom-config/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/exhaustive/no-custom-config/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/exhaustive/no-custom-config/gradlew.bat b/seed/java-sdk/exhaustive/no-custom-config/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/gradlew.bat +++ b/seed/java-sdk/exhaustive/no-custom-config/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/core/RequestOptions.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/core/RequestOptions.java index 4a94345a07a..ba482fad922 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/core/RequestOptions.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java index 7caf2149e46..ab7394eee86 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/container/ContainerClient.java @@ -17,6 +17,7 @@ import java.util.Set; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -52,8 +53,13 @@ public List getAndReturnListOfPrimitives(List request, RequestOp .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -91,8 +97,13 @@ public List getAndReturnListOfObjects( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -129,8 +140,13 @@ public Set getAndReturnSetOfPrimitives(Set request, RequestOptio .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -168,8 +184,13 @@ public Set getAndReturnSetOfObjects( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -206,8 +227,13 @@ public Map getAndReturnMapPrimToPrim(Map request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -246,8 +272,13 @@ public Map getAndReturnMapOfPrimToObject( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -292,8 +323,13 @@ public Optional getAndReturnOptional( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java index e22a3453cda..67f22ff0da6 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/enum_/EnumClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,8 +47,13 @@ public WeatherReport getAndReturnEnum(WeatherReport request, RequestOptions requ .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), WeatherReport.class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java index 1882a9f5bd0..00285499213 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/httpmethods/HttpMethodsClient.java @@ -13,6 +13,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -41,8 +42,13 @@ public String testGet(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -77,8 +83,13 @@ public ObjectWithOptionalField testPost(ObjectWithRequiredField request, Request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -114,8 +125,13 @@ public ObjectWithOptionalField testPut(String id, ObjectWithRequiredField reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -156,8 +172,13 @@ public ObjectWithOptionalField testPatch( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -186,8 +207,13 @@ public boolean testDelete(String id, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java index 392db9f6c4a..d325ce042d5 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/object/ObjectClient.java @@ -16,6 +16,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -56,8 +57,13 @@ public ObjectWithOptionalField getAndReturnWithOptionalField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -94,8 +100,13 @@ public ObjectWithRequiredField getAndReturnWithRequiredField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithRequiredField.class); } @@ -131,8 +142,13 @@ public ObjectWithMapOfMap getAndReturnWithMapOfMap(ObjectWithMapOfMap request, R .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithMapOfMap.class); } @@ -174,8 +190,13 @@ public NestedObjectWithOptionalField getAndReturnNestedWithOptionalField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), NestedObjectWithOptionalField.class); @@ -213,8 +234,13 @@ public NestedObjectWithRequiredField getAndReturnNestedWithRequiredField( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), NestedObjectWithRequiredField.class); diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java index 6c54532c8e0..87aa296af3c 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/params/ParamsClient.java @@ -14,6 +14,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -49,8 +50,13 @@ public String getWithPath(String param, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -84,8 +90,13 @@ public void getWithQuery(GetWithQuery request, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -119,8 +130,13 @@ public void getWithAllowMultipleQuery(GetWithMultipleQuery request, RequestOptio .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -155,8 +171,13 @@ public void getWithPathAndQuery(String param, GetWithPathAndQuery request, Reque .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -199,8 +220,13 @@ public String modifyWithPath(String param, String request, RequestOptions reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java index 1eccfa48453..1df7ef0160a 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/primitive/PrimitiveClient.java @@ -13,6 +13,7 @@ import java.util.UUID; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -48,8 +49,13 @@ public String getAndReturnString(String request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -85,8 +91,13 @@ public int getAndReturnInt(int request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), int.class); } @@ -122,8 +133,13 @@ public long getAndReturnLong(long request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), long.class); } @@ -159,8 +175,13 @@ public double getAndReturnDouble(double request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), double.class); } @@ -196,8 +217,13 @@ public boolean getAndReturnBool(boolean request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } @@ -233,8 +259,13 @@ public OffsetDateTime getAndReturnDatetime(OffsetDateTime request, RequestOption .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), OffsetDateTime.class); } @@ -270,8 +301,13 @@ public String getAndReturnDate(String request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -307,8 +343,13 @@ public UUID getAndReturnUuid(UUID request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), UUID.class); } @@ -344,8 +385,13 @@ public byte[] getAndReturnBase64(byte[] request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), byte[].class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java index 1c8da15ca80..b97bc5e412e 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/endpoints/union/UnionClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,8 +47,13 @@ public Animal getAndReturnUnion(Animal request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Animal.class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java index b0e96b530a9..143861b2eef 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/inlinedrequests/InlinedRequestsClient.java @@ -13,6 +13,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -55,8 +56,13 @@ public ObjectWithOptionalField postWithObjectBodyandResponse( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java index a9a9dc8c0c6..1338c54d154 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noauth/NoAuthClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -51,8 +52,13 @@ public boolean postWithNoAuth(Object request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), boolean.class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java index 6329ba168c8..a2be45418dc 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/noreqbody/NoReqBodyClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -38,8 +39,13 @@ public ObjectWithOptionalField getWithNoRequestBody(RequestOptions requestOption .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ObjectWithOptionalField.class); } @@ -67,8 +73,13 @@ public String postWithNoRequestBody(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java index 8a1015827e8..7179ba1fcfd 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/resources/reqwithheaders/ReqWithHeadersClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -49,8 +50,13 @@ public void getWithCustomHeader(ReqWithHeaders request, RequestOptions requestOp _requestBuilder.addHeader("X-TEST-ENDPOINT-HEADER", request.getXTestEndpointHeader()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/extends/.github/workflows/ci.yml b/seed/java-sdk/extends/.github/workflows/ci.yml new file mode 100644 index 00000000000..260533c2a98 --- /dev/null +++ b/seed/java-sdk/extends/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: ci + +on: [push] + +jobs: + compile: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up Java + id: setup-jre + uses: actions/setup-java@v1 + with: + java-version: "11" + architecture: x64 + + - name: Compile + run: ./gradlew compileJava + + test: + needs: [ compile ] + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up Java + id: setup-jre + uses: actions/setup-java@v1 + with: + java-version: "11" + architecture: x64 + + - name: Test + run: ./gradlew test diff --git a/seed/java-sdk/extends/.gitignore b/seed/java-sdk/extends/.gitignore new file mode 100644 index 00000000000..d4199abc2cd --- /dev/null +++ b/seed/java-sdk/extends/.gitignore @@ -0,0 +1,24 @@ +*.class +.project +.gradle +? +.classpath +.checkstyle +.settings +.node +build + +# IntelliJ +*.iml +*.ipr +*.iws +.idea/ +out/ + +# Eclipse/IntelliJ APT +generated_src/ +generated_testSrc/ +generated/ + +bin +build \ No newline at end of file diff --git a/seed/java-sdk/extends/build.gradle b/seed/java-sdk/extends/build.gradle new file mode 100644 index 00000000000..26e4017afc4 --- /dev/null +++ b/seed/java-sdk/extends/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'java-library' + id 'maven-publish' + id 'com.diffplug.spotless' version '6.11.0' +} + +repositories { + mavenCentral() + maven { + url 'https://s01.oss.sonatype.org/content/repositories/releases/' + } +} + +dependencies { + api 'com.squareup.okhttp3:okhttp:4.12.0' + api 'com.fasterxml.jackson.core:jackson-databind:2.13.0' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.3' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.3' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' +} + + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +spotless { + java { + palantirJavaFormat() + } +} + +java { + withSourcesJar() + withJavadocJar() +} + +test { + useJUnitPlatform() + testLogging { + showStandardStreams = true + } +} diff --git a/seed/java-sdk/extends/sample-app/build.gradle b/seed/java-sdk/extends/sample-app/build.gradle new file mode 100644 index 00000000000..4ee8f227b7a --- /dev/null +++ b/seed/java-sdk/extends/sample-app/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java-library' +} + +repositories { + mavenCentral() + maven { + url 'https://s01.oss.sonatype.org/content/repositories/releases/' + } +} + +dependencies { + implementation rootProject +} + + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + diff --git a/seed/java-sdk/extends/sample-app/src/main/java/sample/App.java b/seed/java-sdk/extends/sample-app/src/main/java/sample/App.java new file mode 100644 index 00000000000..b4517237f44 --- /dev/null +++ b/seed/java-sdk/extends/sample-app/src/main/java/sample/App.java @@ -0,0 +1,13 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package sample; + +import java.lang.String; + +public final class App { + public static void main(String[] args) { + // import com.seed.extends.SeedExtendsClient + } +} diff --git a/seed/java-sdk/extends/settings.gradle b/seed/java-sdk/extends/settings.gradle new file mode 100644 index 00000000000..aed36fec10b --- /dev/null +++ b/seed/java-sdk/extends/settings.gradle @@ -0,0 +1 @@ +include 'sample-app' \ No newline at end of file diff --git a/seed/java-sdk/extends/snippet.json b/seed/java-sdk/extends/snippet.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/SeedExtendsClient.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/SeedExtendsClient.java new file mode 100644 index 00000000000..54af6abc349 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/SeedExtendsClient.java @@ -0,0 +1,19 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends; + +import com.seed.extends.core.ClientOptions; + +public class SeedExtendsClient { + protected final ClientOptions clientOptions; + + public SeedExtendsClient(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + public static SeedExtendsClientBuilder builder() { + return new SeedExtendsClientBuilder(); + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/SeedExtendsClientBuilder.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/SeedExtendsClientBuilder.java new file mode 100644 index 00000000000..224c618f71e --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/SeedExtendsClientBuilder.java @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends; + +import com.seed.extends.core.ClientOptions; +import com.seed.extends.core.Environment; +import java.lang.String; + +public final class SeedExtendsClientBuilder { + private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + + private Environment environment; + + public SeedExtendsClientBuilder url(String url) { + this.environment = Environment.custom(url); + return this; + } + + public SeedExtendsClient build() { + clientOptionsBuilder.environment(this.environment); + return new SeedExtendsClient(clientOptionsBuilder.build()); + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ApiError.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ApiError.java new file mode 100644 index 00000000000..f3cb3fd271e --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ApiError.java @@ -0,0 +1,33 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import java.lang.Object; +import java.lang.RuntimeException; +import java.lang.String; + +public final class ApiError extends RuntimeException { + private final int statusCode; + + private final Object body; + + public ApiError(int statusCode, Object body) { + this.statusCode = statusCode; + this.body = body; + } + + public int statusCode() { + return this.statusCode; + } + + public Object body() { + return this.body; + } + + @java.lang.Override + public String toString() { + return "ApiError{" + "statusCode: " + statusCode + ", body: " + body + "}"; + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ClientOptions.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ClientOptions.java new file mode 100644 index 00000000000..048e65b2507 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ClientOptions.java @@ -0,0 +1,85 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; +import okhttp3.OkHttpClient; + +public final class ClientOptions { + private final Environment environment; + + private final Map headers; + + private final Map> headerSuppliers; + + private final OkHttpClient httpClient; + + private ClientOptions(Environment environment, Map headers, + Map> headerSuppliers, OkHttpClient httpClient) { + this.environment = environment; + this.headers = new HashMap<>(); + this.headers.putAll(headers); + this.headers.putAll(Map.of("X-Fern-Language", "JAVA")); + this.headerSuppliers = headerSuppliers; + this.httpClient = httpClient; + ; + } + + public Environment environment() { + return this.environment; + } + + public Map headers(RequestOptions requestOptions) { + Map values = new HashMap<>(this.headers); + headerSuppliers.forEach((key, supplier) -> { + values.put(key, supplier.get()); + } ); + if (requestOptions != null) { + values.putAll(requestOptions.getHeaders()); + } + return values; + } + + public OkHttpClient httpClient() { + return this.httpClient; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private Environment environment; + + private final Map headers = new HashMap<>(); + + private final Map> headerSuppliers = new HashMap<>(); + + public Builder environment(Environment environment) { + this.environment = environment; + return this; + } + + public Builder addHeader(String key, String value) { + this.headers.put(key, value); + return this; + } + + public Builder addHeader(String key, Supplier value) { + this.headerSuppliers.put(key, value); + return this; + } + + public ClientOptions build() { + OkHttpClient okhttpClient = new OkHttpClient.Builder() + .addInterceptor(new RetryInterceptor(3)) + .build(); + return new ClientOptions(environment, headers, headerSuppliers, okhttpClient); + } + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/DateTimeDeserializer.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/DateTimeDeserializer.java new file mode 100644 index 00000000000..06db1e8e970 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/DateTimeDeserializer.java @@ -0,0 +1,56 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalQueries; + +/** + * Custom deserializer that handles converting ISO8601 dates into {@link OffsetDateTime} objects. + */ +class DateTimeDeserializer extends JsonDeserializer { + private static final SimpleModule MODULE; + + static { + MODULE = new SimpleModule().addDeserializer(OffsetDateTime.class, new DateTimeDeserializer()); + } + + /** + * Gets a module wrapping this deserializer as an adapter for the Jackson ObjectMapper. + * + * @return A {@link SimpleModule} to be plugged onto Jackson ObjectMapper. + */ + public static SimpleModule getModule() { + return MODULE; + } + + @Override + public OffsetDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException { + JsonToken token = parser.currentToken(); + if (token == JsonToken.VALUE_NUMBER_INT) { + return OffsetDateTime.ofInstant(Instant.ofEpochSecond(parser.getValueAsLong()), ZoneOffset.UTC); + } else { + TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest( + parser.getValueAsString(), OffsetDateTime::from, LocalDateTime::from); + + if (temporal.query(TemporalQueries.offset()) == null) { + return LocalDateTime.from(temporal).atOffset(ZoneOffset.UTC); + } else { + return OffsetDateTime.from(temporal); + } + } + } +} \ No newline at end of file diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Environment.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Environment.java new file mode 100644 index 00000000000..5adc4b2a075 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Environment.java @@ -0,0 +1,23 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import java.lang.String; + +public final class Environment { + private final String url; + + private Environment(String url) { + this.url = url; + } + + public String getUrl() { + return this.url; + } + + public static Environment custom(String url) { + return new Environment(url); + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/MediaTypes.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/MediaTypes.java new file mode 100644 index 00000000000..66ad1f815f4 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/MediaTypes.java @@ -0,0 +1,16 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import okhttp3.MediaType; + +public final class MediaTypes { + + public static final MediaType APPLICATION_JSON = MediaType.parse("application/json"); + + private MediaTypes() { + } + +} \ No newline at end of file diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ObjectMappers.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ObjectMappers.java new file mode 100644 index 00000000000..55c4e50272e --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/ObjectMappers.java @@ -0,0 +1,41 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.io.IOException; +import java.lang.Integer; +import java.lang.Object; +import java.lang.String; + +public final class ObjectMappers { + public static final ObjectMapper JSON_MAPPER = JsonMapper.builder() + .addModule(new Jdk8Module()) + .addModule(new JavaTimeModule()) + .addModule(DateTimeDeserializer.getModule()) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .build(); + + private ObjectMappers() { + } + + public static String stringify(Object o) { + try { + return JSON_MAPPER.setSerializationInclusion(JsonInclude.Include.ALWAYS) + .writerWithDefaultPrettyPrinter() + .writeValueAsString(o); + } + catch (IOException e) { + return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()); + } + } + } diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/RequestOptions.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/RequestOptions.java new file mode 100644 index 00000000000..482d32afcc6 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/RequestOptions.java @@ -0,0 +1,60 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import java.lang.Integer; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +public final class RequestOptions { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } + + public Map getHeaders() { + Map headers = new HashMap<>(); + return headers; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Optional timeout) { + this.timeout = timeout; + return this; + } + + public Builder timeoutTimeUnit(TimeUnit timeoutTimeUnit) { + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + + public RequestOptions build() { + return new RequestOptions(timeout, timeoutTimeUnit); + } + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/RetryInterceptor.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/RetryInterceptor.java new file mode 100644 index 00000000000..7fab625305a --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/RetryInterceptor.java @@ -0,0 +1,79 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import java.io.IOException; +import java.time.Duration; +import java.util.Optional; +import java.util.Random; +import okhttp3.Interceptor; +import okhttp3.Response; + +public class RetryInterceptor implements Interceptor { + + private static final Duration ONE_SECOND = Duration.ofSeconds(1); + private final ExponentialBackoff backoff; + private final Random random = new Random(); + + public RetryInterceptor(int maxRetries) { + this.backoff = new ExponentialBackoff(maxRetries); + } + + @Override + public Response intercept(Chain chain) throws IOException { + Response response = chain.proceed(chain.request()); + + if (shouldRetry(response.code())) { + return retryChain(response, chain); + } + + return response; + } + + private Response retryChain(Response response, Chain chain) throws IOException { + Optional nextBackoff = this.backoff.nextBackoff(); + while (nextBackoff.isPresent()) { + try { + Thread.sleep(nextBackoff.get().toMillis()); + } catch (InterruptedException e) { + throw new IOException("Interrupted while trying request", e); + } + response.close(); + response = chain.proceed(chain.request()); + if (shouldRetry(response.code())) { + nextBackoff = this.backoff.nextBackoff(); + } else { + return response; + } + } + + return response; + } + + private static boolean shouldRetry(int statusCode) { + return statusCode == 408 || statusCode == 409 || statusCode == 429 || statusCode >= 500; + } + + private final class ExponentialBackoff { + + private final int maxNumRetries; + + private int retryNumber = 0; + + ExponentialBackoff(int maxNumRetries) { + this.maxNumRetries = maxNumRetries; + } + + public Optional nextBackoff() { + retryNumber += 1; + if (retryNumber > maxNumRetries) { + return Optional.empty(); + } + + int upperBound = (int) Math.pow(2, retryNumber); + return Optional.of(ONE_SECOND.multipliedBy(random.nextInt(upperBound))); + } + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Stream.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Stream.java new file mode 100644 index 00000000000..bf0152a1397 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Stream.java @@ -0,0 +1,98 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.io.Reader; +import java.util.Scanner; + +/** + * The {@code Stream} class implmenets {@link Iterable} to provide a simple mechanism for reading and parsing + * objects of a given type from data streamed via a {@link Reader} using a specified delimiter. + *

+ * {@code Stream} assumes that data is being pushed to the provided {@link Reader} asynchronously and utilizes a + * {@code Scanner} to block during iteration if the next object is not available. + * + * @param The type of objects in the stream. + */ +public final class Stream implements Iterable { + /** + * The {@link Class} of the objects in the stream. + */ + private final Class valueType; + /** + * The {@link Scanner} used for reading from the input stream and blocking when neede during iteration. + */ + private final Scanner scanner; + + /** + * Constructs a new {@code Stream} with the specified value type, reader, and delimiter. + * + * @param valueType The class of the objects in the stream. + * @param reader The reader that provides the streamed data. + * @param delimiter The delimiter used to separate elements in the stream. + */ + public Stream(Class valueType, Reader reader, String delimiter) { + this.scanner = new Scanner(reader).useDelimiter(delimiter); + this.valueType = valueType; + } + + /** + * Returns an iterator over the elements in this stream that blocks during iteration when the next object is + * not yet available. + * + * @return An iterator that can be used to traverse the elements in the stream. + */ + @Override + public Iterator iterator() { + return new Iterator() { + /** + * Returns {@code true} if there are more elements in the stream. + *

+ * Will block and wait for input if the stream has not ended and the next object is not yet available. + * + * @return {@code true} if there are more elements, {@code false} otherwise. + */ + @Override + public boolean hasNext() { + return scanner.hasNext(); + } + + /** + * Returns the next element in the stream. + *

+ * Will block and wait for input if the stream has not ended and the next object is not yet available. + * + * @return The next element in the stream. + * @throws NoSuchElementException If there are no more elements in the stream. + */ + @Override + public T next() { + if (!scanner.hasNext()) { + throw new NoSuchElementException(); + } else { + try { + T parsedResponse = + ObjectMappers.JSON_MAPPER.readValue(scanner.next().trim(), valueType); + return parsedResponse; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + /** + * Removing elements from {@code Stream} is not supported. + * + * @throws UnsupportedOperationException Always, as removal is not supported. + */ + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } +} \ No newline at end of file diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Suppliers.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Suppliers.java new file mode 100644 index 00000000000..dc5b8d1c408 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/core/Suppliers.java @@ -0,0 +1,25 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.core; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; + +public final class Suppliers { + private Suppliers() { + } + + public static Supplier memoize(Supplier delegate) { + AtomicReference value = new AtomicReference<>(); + return () -> { + T val = value.get(); + if (val == null) { + val = value.updateAndGet(cur -> cur == null ? Objects.requireNonNull(delegate.get()) : cur); + } + return val; + } ; + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/types/Docs.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/Docs.java new file mode 100644 index 00000000000..f9241c4da90 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/Docs.java @@ -0,0 +1,110 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.types; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.seed.extends.core.ObjectMappers; +import java.lang.Object; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize( + builder = Docs.Builder.class +) +public final class Docs implements IDocs { + private final String docs; + + private final Map additionalProperties; + + private Docs(String docs, Map additionalProperties) { + this.docs = docs; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("docs") + @java.lang.Override + public String getDocs() { + return docs; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Docs && equalTo((Docs) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Docs other) { + return docs.equals(other.docs); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.docs); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static DocsStage builder() { + return new Builder(); + } + + public interface DocsStage { + _FinalStage docs(String docs); + + Builder from(Docs other); + } + + public interface _FinalStage { + Docs build(); + } + + @JsonIgnoreProperties( + ignoreUnknown = true + ) + public static final class Builder implements DocsStage, _FinalStage { + private String docs; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() { + } + + @java.lang.Override + public Builder from(Docs other) { + docs(other.getDocs()); + return this; + } + + @java.lang.Override + @JsonSetter("docs") + public _FinalStage docs(String docs) { + this.docs = docs; + return this; + } + + @java.lang.Override + public Docs build() { + return new Docs(docs, additionalProperties); + } + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/types/ExampleType.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/ExampleType.java new file mode 100644 index 00000000000..53817c6d3f3 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/ExampleType.java @@ -0,0 +1,132 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.types; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.seed.extends.core.ObjectMappers; +import java.lang.Object; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize( + builder = ExampleType.Builder.class +) +public final class ExampleType implements IDocs { + private final String docs; + + private final String name; + + private final Map additionalProperties; + + private ExampleType(String docs, String name, Map additionalProperties) { + this.docs = docs; + this.name = name; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("docs") + @java.lang.Override + public String getDocs() { + return docs; + } + + @JsonProperty("name") + public String getName() { + return name; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ExampleType && equalTo((ExampleType) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ExampleType other) { + return docs.equals(other.docs) && name.equals(other.name); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.docs, this.name); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static DocsStage builder() { + return new Builder(); + } + + public interface DocsStage { + NameStage docs(String docs); + + Builder from(ExampleType other); + } + + public interface NameStage { + _FinalStage name(String name); + } + + public interface _FinalStage { + ExampleType build(); + } + + @JsonIgnoreProperties( + ignoreUnknown = true + ) + public static final class Builder implements DocsStage, NameStage, _FinalStage { + private String docs; + + private String name; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() { + } + + @java.lang.Override + public Builder from(ExampleType other) { + docs(other.getDocs()); + name(other.getName()); + return this; + } + + @java.lang.Override + @JsonSetter("docs") + public NameStage docs(String docs) { + this.docs = docs; + return this; + } + + @java.lang.Override + @JsonSetter("name") + public _FinalStage name(String name) { + this.name = name; + return this; + } + + @java.lang.Override + public ExampleType build() { + return new ExampleType(docs, name, additionalProperties); + } + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/types/IDocs.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/IDocs.java new file mode 100644 index 00000000000..07e1e8bdd02 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/IDocs.java @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.types; + +import java.lang.String; + +public interface IDocs { + String getDocs(); +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/types/IJson.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/IJson.java new file mode 100644 index 00000000000..59150427b63 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/IJson.java @@ -0,0 +1,11 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.types; + +import java.lang.String; + +public interface IJson extends IDocs { + String getRaw(); +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/types/Json.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/Json.java new file mode 100644 index 00000000000..5acface83a4 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/Json.java @@ -0,0 +1,133 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.types; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.seed.extends.core.ObjectMappers; +import java.lang.Object; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize( + builder = Json.Builder.class +) +public final class Json implements IJson, IDocs { + private final String raw; + + private final String docs; + + private final Map additionalProperties; + + private Json(String raw, String docs, Map additionalProperties) { + this.raw = raw; + this.docs = docs; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("raw") + @java.lang.Override + public String getRaw() { + return raw; + } + + @JsonProperty("docs") + @java.lang.Override + public String getDocs() { + return docs; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Json && equalTo((Json) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Json other) { + return raw.equals(other.raw) && docs.equals(other.docs); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.raw, this.docs); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static RawStage builder() { + return new Builder(); + } + + public interface RawStage { + DocsStage raw(String raw); + + Builder from(Json other); + } + + public interface DocsStage { + _FinalStage docs(String docs); + } + + public interface _FinalStage { + Json build(); + } + + @JsonIgnoreProperties( + ignoreUnknown = true + ) + public static final class Builder implements RawStage, DocsStage, _FinalStage { + private String raw; + + private String docs; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() { + } + + @java.lang.Override + public Builder from(Json other) { + raw(other.getRaw()); + docs(other.getDocs()); + return this; + } + + @java.lang.Override + @JsonSetter("raw") + public DocsStage raw(String raw) { + this.raw = raw; + return this; + } + + @java.lang.Override + @JsonSetter("docs") + public _FinalStage docs(String docs) { + this.docs = docs; + return this; + } + + @java.lang.Override + public Json build() { + return new Json(raw, docs, additionalProperties); + } + } +} diff --git a/seed/java-sdk/extends/src/main/java/com/seed/extends/types/NestedType.java b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/NestedType.java new file mode 100644 index 00000000000..207fee4bc18 --- /dev/null +++ b/seed/java-sdk/extends/src/main/java/com/seed/extends/types/NestedType.java @@ -0,0 +1,156 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends.types; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.seed.extends.core.ObjectMappers; +import java.lang.Object; +import java.lang.String; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize( + builder = NestedType.Builder.class +) +public final class NestedType implements IJson { + private final String raw; + + private final String docs; + + private final String name; + + private final Map additionalProperties; + + private NestedType(String raw, String docs, String name, + Map additionalProperties) { + this.raw = raw; + this.docs = docs; + this.name = name; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("raw") + @java.lang.Override + public String getRaw() { + return raw; + } + + @JsonProperty("docs") + @java.lang.Override + public String getDocs() { + return docs; + } + + @JsonProperty("name") + public String getName() { + return name; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof NestedType && equalTo((NestedType) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(NestedType other) { + return raw.equals(other.raw) && docs.equals(other.docs) && name.equals(other.name); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.raw, this.docs, this.name); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static RawStage builder() { + return new Builder(); + } + + public interface RawStage { + DocsStage raw(String raw); + + Builder from(NestedType other); + } + + public interface DocsStage { + NameStage docs(String docs); + } + + public interface NameStage { + _FinalStage name(String name); + } + + public interface _FinalStage { + NestedType build(); + } + + @JsonIgnoreProperties( + ignoreUnknown = true + ) + public static final class Builder implements RawStage, DocsStage, NameStage, _FinalStage { + private String raw; + + private String docs; + + private String name; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() { + } + + @java.lang.Override + public Builder from(NestedType other) { + raw(other.getRaw()); + docs(other.getDocs()); + name(other.getName()); + return this; + } + + @java.lang.Override + @JsonSetter("raw") + public DocsStage raw(String raw) { + this.raw = raw; + return this; + } + + @java.lang.Override + @JsonSetter("docs") + public NameStage docs(String docs) { + this.docs = docs; + return this; + } + + @java.lang.Override + @JsonSetter("name") + public _FinalStage name(String name) { + this.name = name; + return this; + } + + @java.lang.Override + public NestedType build() { + return new NestedType(raw, docs, name, additionalProperties); + } + } +} diff --git a/seed/java-sdk/extends/src/test/java/com/seed/extends/TestClient.java b/seed/java-sdk/extends/src/test/java/com/seed/extends/TestClient.java new file mode 100644 index 00000000000..cab07a48372 --- /dev/null +++ b/seed/java-sdk/extends/src/test/java/com/seed/extends/TestClient.java @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ + +package com.seed.extends; + +public final class TestClient { + public void test() { + // Add tests here and mark this file in .fernignore + assert true; + } +} diff --git a/seed/java-sdk/file-download/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/file-download/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/file-download/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/file-download/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/file-download/gradlew.bat b/seed/java-sdk/file-download/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/file-download/gradlew.bat +++ b/seed/java-sdk/file-download/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/core/RequestOptions.java b/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/core/RequestOptions.java index 46b97eb6077..29cfbc0992c 100644 --- a/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/core/RequestOptions.java +++ b/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/resources/service/ServiceClient.java b/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/resources/service/ServiceClient.java index 90ecd2d6ba5..13e67e576f0 100644 --- a/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/resources/service/ServiceClient.java +++ b/seed/java-sdk/file-download/src/main/java/com/seed/fileDownload/resources/service/ServiceClient.java @@ -11,6 +11,7 @@ import java.io.InputStream; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -37,8 +38,13 @@ public InputStream downloadFile(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return response.body().byteStream(); } diff --git a/seed/java-sdk/file-upload/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/file-upload/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/file-upload/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/file-upload/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/file-upload/gradlew.bat b/seed/java-sdk/file-upload/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/file-upload/gradlew.bat +++ b/seed/java-sdk/file-upload/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/core/RequestOptions.java b/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/core/RequestOptions.java index 0272a33250f..1adacb72600 100644 --- a/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/core/RequestOptions.java +++ b/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/resources/service/ServiceClient.java b/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/resources/service/ServiceClient.java index 2d724369ee4..db231e27bf7 100644 --- a/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/resources/service/ServiceClient.java +++ b/seed/java-sdk/file-upload/src/main/java/com/seed/fileUpload/resources/service/ServiceClient.java @@ -18,6 +18,7 @@ import okhttp3.HttpUrl; import okhttp3.MediaType; import okhttp3.MultipartBody; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -95,8 +96,13 @@ public void post(File file, Optional maybeFile, MyRequest request, Request .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -131,8 +137,13 @@ public void justFile(File file, JustFileRequet request, RequestOptions requestOp .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -180,8 +191,13 @@ public void justFileWithQueryParams( .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/folders/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/folders/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/folders/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/folders/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/folders/gradlew.bat b/seed/java-sdk/folders/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/folders/gradlew.bat +++ b/seed/java-sdk/folders/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/folders/src/main/java/com/seed/api/SeedApiClient.java b/seed/java-sdk/folders/src/main/java/com/seed/api/SeedApiClient.java index a7aa6d55385..98fa9861a33 100644 --- a/seed/java-sdk/folders/src/main/java/com/seed/api/SeedApiClient.java +++ b/seed/java-sdk/folders/src/main/java/com/seed/api/SeedApiClient.java @@ -14,6 +14,7 @@ import java.util.function.Supplier; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -45,8 +46,13 @@ public void foo(RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/folders/src/main/java/com/seed/api/core/RequestOptions.java b/seed/java-sdk/folders/src/main/java/com/seed/api/core/RequestOptions.java index 26cef452c39..7700c11b780 100644 --- a/seed/java-sdk/folders/src/main/java/com/seed/api/core/RequestOptions.java +++ b/seed/java-sdk/folders/src/main/java/com/seed/api/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/FolderClient.java b/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/FolderClient.java index e3663bdd06d..380badd8df6 100644 --- a/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/FolderClient.java +++ b/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/FolderClient.java @@ -13,6 +13,7 @@ import java.util.function.Supplier; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -41,8 +42,13 @@ public void foo(RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/service/ServiceClient.java b/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/service/ServiceClient.java index 43a1d5a9cf0..da2e55cdd47 100644 --- a/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/service/ServiceClient.java +++ b/seed/java-sdk/folders/src/main/java/com/seed/api/resources/folder/service/ServiceClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -37,8 +38,13 @@ public void endpoint(RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -73,8 +79,13 @@ public void unknownRequest(Object request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/imdb/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/imdb/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/imdb/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/imdb/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/imdb/gradlew.bat b/seed/java-sdk/imdb/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/imdb/gradlew.bat +++ b/seed/java-sdk/imdb/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/imdb/src/main/java/com/seed/api/core/RequestOptions.java b/seed/java-sdk/imdb/src/main/java/com/seed/api/core/RequestOptions.java index 11a77d9bcd8..546f912573a 100644 --- a/seed/java-sdk/imdb/src/main/java/com/seed/api/core/RequestOptions.java +++ b/seed/java-sdk/imdb/src/main/java/com/seed/api/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/imdb/src/main/java/com/seed/api/resources/imdb/ImdbClient.java b/seed/java-sdk/imdb/src/main/java/com/seed/api/resources/imdb/ImdbClient.java index e60d01d5729..3011ca9dc07 100644 --- a/seed/java-sdk/imdb/src/main/java/com/seed/api/resources/imdb/ImdbClient.java +++ b/seed/java-sdk/imdb/src/main/java/com/seed/api/resources/imdb/ImdbClient.java @@ -13,6 +13,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -54,8 +55,13 @@ public String createMovie(CreateMovieRequest request, RequestOptions requestOpti .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } @@ -84,8 +90,13 @@ public Movie getMovie(String movieId, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Movie.class); } diff --git a/seed/java-sdk/literal-headers/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/literal-headers/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/literal-headers/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/literal-headers/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/literal-headers/gradlew.bat b/seed/java-sdk/literal-headers/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/literal-headers/gradlew.bat +++ b/seed/java-sdk/literal-headers/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/core/RequestOptions.java b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/core/RequestOptions.java index 0043b1e629d..9dfc9c3b278 100644 --- a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/core/RequestOptions.java +++ b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/core/RequestOptions.java @@ -5,15 +5,31 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String apiHeader; private final String apiTest; - private RequestOptions(String apiHeader, String apiTest) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String apiHeader, String apiTest, Optional timeout, TimeUnit timeoutTimeUnit) { this.apiHeader = apiHeader; this.apiTest = apiTest; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -36,6 +52,10 @@ public static final class Builder { private String apiTest = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder apiHeader(String apiHeader) { this.apiHeader = apiHeader; return this; @@ -46,8 +66,19 @@ public Builder apiTest(String apiTest) { return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(apiHeader, apiTest); + return new RequestOptions(apiHeader, apiTest, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/noheaders/NoHeadersClient.java b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/noheaders/NoHeadersClient.java index 980e9d98da2..faf320094a8 100644 --- a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/noheaders/NoHeadersClient.java +++ b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/noheaders/NoHeadersClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -36,8 +37,13 @@ public void get(RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/onlyliteralheaders/OnlyLiteralHeadersClient.java b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/onlyliteralheaders/OnlyLiteralHeadersClient.java index 8baff08bfeb..1a903173a65 100644 --- a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/onlyliteralheaders/OnlyLiteralHeadersClient.java +++ b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/onlyliteralheaders/OnlyLiteralHeadersClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -36,8 +37,13 @@ public void get(RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/withnonliteralheaders/WithNonLiteralHeadersClient.java b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/withnonliteralheaders/WithNonLiteralHeadersClient.java index b1d19bad28b..422a11d1e05 100644 --- a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/withnonliteralheaders/WithNonLiteralHeadersClient.java +++ b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/resources/withnonliteralheaders/WithNonLiteralHeadersClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -49,8 +50,13 @@ public void get(WithNonLiteralHeadersRequest request, RequestOptions requestOpti "trueEndpointHeader", request.getTrueEndpointHeader().toString()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/literal/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/literal/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/literal/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/literal/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/literal/gradlew.bat b/seed/java-sdk/literal/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/literal/gradlew.bat +++ b/seed/java-sdk/literal/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/literal/src/main/java/com/seed/literal/core/RequestOptions.java b/seed/java-sdk/literal/src/main/java/com/seed/literal/core/RequestOptions.java index 14aa65cd9cd..a59a84406de 100644 --- a/seed/java-sdk/literal/src/main/java/com/seed/literal/core/RequestOptions.java +++ b/seed/java-sdk/literal/src/main/java/com/seed/literal/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/literal/src/main/java/com/seed/literal/resources/literal/LiteralClient.java b/seed/java-sdk/literal/src/main/java/com/seed/literal/resources/literal/LiteralClient.java index 8aed041687a..bb76a80692b 100644 --- a/seed/java-sdk/literal/src/main/java/com/seed/literal/resources/literal/LiteralClient.java +++ b/seed/java-sdk/literal/src/main/java/com/seed/literal/resources/literal/LiteralClient.java @@ -17,6 +17,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -51,8 +52,13 @@ public CreateOptionsResponse createOptions(CreateOptionsRequest request, Request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), CreateOptionsResponse.class); } @@ -87,8 +93,13 @@ public Options getOptions(GetOptionsRequest request, RequestOptions requestOptio .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Options.class); } @@ -124,8 +135,13 @@ public UndiscriminatedOptions getUndiscriminatedOptions( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), UndiscriminatedOptions.class); } diff --git a/seed/java-sdk/multi-url-environment/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/multi-url-environment/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/multi-url-environment/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/multi-url-environment/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/multi-url-environment/gradlew.bat b/seed/java-sdk/multi-url-environment/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/multi-url-environment/gradlew.bat +++ b/seed/java-sdk/multi-url-environment/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/core/RequestOptions.java b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/core/RequestOptions.java index 0763347536d..60dfb3a573a 100644 --- a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/core/RequestOptions.java +++ b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/ec2/Ec2Client.java b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/ec2/Ec2Client.java index 7eb9653a128..67c55118a02 100644 --- a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/ec2/Ec2Client.java +++ b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/ec2/Ec2Client.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -47,8 +48,13 @@ public void bootInstance(BootInstanceRequest request, RequestOptions requestOpti .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/s3/S3Client.java b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/s3/S3Client.java index 3afc4e67851..16e8c78bb26 100644 --- a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/s3/S3Client.java +++ b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/resources/s3/S3Client.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -47,8 +48,13 @@ public String getPresignedUrl(GetPresignedUrlRequest request, RequestOptions req .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/no-environment/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/no-environment/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/no-environment/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/no-environment/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/no-environment/gradlew.bat b/seed/java-sdk/no-environment/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/no-environment/gradlew.bat +++ b/seed/java-sdk/no-environment/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/core/RequestOptions.java b/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/core/RequestOptions.java index fd26288ea93..48931ed00ef 100644 --- a/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/core/RequestOptions.java +++ b/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/resources/dummy/DummyClient.java b/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/resources/dummy/DummyClient.java index 3229827c5c5..c9b572e5429 100644 --- a/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/resources/dummy/DummyClient.java +++ b/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/resources/dummy/DummyClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -36,8 +37,13 @@ public String getDummy(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/object/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/object/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/object/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/object/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/object/gradlew.bat b/seed/java-sdk/object/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/object/gradlew.bat +++ b/seed/java-sdk/object/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/object/src/main/java/com/seed/object/core/RequestOptions.java b/seed/java-sdk/object/src/main/java/com/seed/object/core/RequestOptions.java index f863ee4a632..a278cbab3ca 100644 --- a/seed/java-sdk/object/src/main/java/com/seed/object/core/RequestOptions.java +++ b/seed/java-sdk/object/src/main/java/com/seed/object/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/objects-with-imports/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/objects-with-imports/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/objects-with-imports/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/objects-with-imports/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/objects-with-imports/gradlew.bat b/seed/java-sdk/objects-with-imports/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/objects-with-imports/gradlew.bat +++ b/seed/java-sdk/objects-with-imports/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/objects-with-imports/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java b/seed/java-sdk/objects-with-imports/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java index c108b66777c..2328d968e21 100644 --- a/seed/java-sdk/objects-with-imports/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java +++ b/seed/java-sdk/objects-with-imports/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/optional/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/optional/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/optional/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/optional/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/optional/gradlew.bat b/seed/java-sdk/optional/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/optional/gradlew.bat +++ b/seed/java-sdk/optional/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java b/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java index c108b66777c..2328d968e21 100644 --- a/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java +++ b/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/resources/optional/OptionalClient.java b/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/resources/optional/OptionalClient.java index 366987b96be..f52b1abf648 100644 --- a/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/resources/optional/OptionalClient.java +++ b/seed/java-sdk/optional/src/main/java/com/seed/objectsWithImports/resources/optional/OptionalClient.java @@ -13,6 +13,7 @@ import java.util.Optional; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -54,8 +55,13 @@ public String sendOptionalBody(Optional> request, RequestOpt .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/package-yml/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/package-yml/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/package-yml/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/package-yml/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/package-yml/gradlew.bat b/seed/java-sdk/package-yml/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/package-yml/gradlew.bat +++ b/seed/java-sdk/package-yml/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/SeedPackageYmlClient.java b/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/SeedPackageYmlClient.java index 931d81ae0e4..9e3da6cbe12 100644 --- a/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/SeedPackageYmlClient.java +++ b/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/SeedPackageYmlClient.java @@ -14,6 +14,7 @@ import java.util.function.Supplier; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -50,8 +51,13 @@ public String echo(String request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/core/RequestOptions.java b/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/core/RequestOptions.java index 09adb909150..52b5eaab42e 100644 --- a/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/core/RequestOptions.java +++ b/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/resources/service/ServiceClient.java b/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/resources/service/ServiceClient.java index 4dac3464e79..6344c7bc724 100644 --- a/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/resources/service/ServiceClient.java +++ b/seed/java-sdk/package-yml/src/main/java/com/seed/packageYml/resources/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -35,8 +36,13 @@ public void nop(String nestedId, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/plain-text/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/plain-text/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/plain-text/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/plain-text/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/plain-text/gradlew.bat b/seed/java-sdk/plain-text/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/plain-text/gradlew.bat +++ b/seed/java-sdk/plain-text/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/core/RequestOptions.java b/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/core/RequestOptions.java index f7729e95a94..af885b752ad 100644 --- a/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/core/RequestOptions.java +++ b/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/resources/service/ServiceClient.java b/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/resources/service/ServiceClient.java index ddb30cb2e34..8ae22942716 100644 --- a/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/resources/service/ServiceClient.java +++ b/seed/java-sdk/plain-text/src/main/java/com/seed/plainText/resources/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -37,8 +38,13 @@ public String getText(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return response.body().string(); } diff --git a/seed/java-sdk/query-parameters/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/query-parameters/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/query-parameters/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/query-parameters/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/query-parameters/gradlew.bat b/seed/java-sdk/query-parameters/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/query-parameters/gradlew.bat +++ b/seed/java-sdk/query-parameters/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/core/RequestOptions.java b/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/core/RequestOptions.java index 451e25b9d90..10515c4cad3 100644 --- a/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/core/RequestOptions.java +++ b/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/resources/user/UserClient.java b/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/resources/user/UserClient.java index c27c6e6d2b4..96119b1d019 100644 --- a/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/resources/user/UserClient.java +++ b/seed/java-sdk/query-parameters/src/main/java/com/seed/queryParameters/resources/user/UserClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -47,8 +48,13 @@ public User getUsername(GetUsersRequest request, RequestOptions requestOptions) .addHeader("Content-Type", "application/json"); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), User.class); } diff --git a/seed/java-sdk/reserved-keywords/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/reserved-keywords/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/reserved-keywords/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/reserved-keywords/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/reserved-keywords/gradlew.bat b/seed/java-sdk/reserved-keywords/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/reserved-keywords/gradlew.bat +++ b/seed/java-sdk/reserved-keywords/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/core/RequestOptions.java b/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/core/RequestOptions.java index 90da30d55df..e0ad938bf6b 100644 --- a/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/core/RequestOptions.java +++ b/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/resources/package_/PackageClient.java b/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/resources/package_/PackageClient.java index e85f3c90329..f57dc49f382 100644 --- a/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/resources/package_/PackageClient.java +++ b/seed/java-sdk/reserved-keywords/src/main/java/com/seed/nurseryApi/resources/package_/PackageClient.java @@ -11,6 +11,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -37,8 +38,13 @@ public void test(TestRequest request, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/single-url-environment-default/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/single-url-environment-default/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/single-url-environment-default/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/single-url-environment-default/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/single-url-environment-default/gradlew.bat b/seed/java-sdk/single-url-environment-default/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/single-url-environment-default/gradlew.bat +++ b/seed/java-sdk/single-url-environment-default/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/core/RequestOptions.java b/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/core/RequestOptions.java index 5da3729272d..24505dc3bd6 100644 --- a/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/core/RequestOptions.java +++ b/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/resources/dummy/DummyClient.java b/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/resources/dummy/DummyClient.java index 7d60ccf0896..fb9eaa24e77 100644 --- a/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/resources/dummy/DummyClient.java +++ b/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/resources/dummy/DummyClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -36,8 +37,13 @@ public String getDummy(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/single-url-environment-no-default/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/single-url-environment-no-default/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/single-url-environment-no-default/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/single-url-environment-no-default/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/single-url-environment-no-default/gradlew.bat b/seed/java-sdk/single-url-environment-no-default/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/single-url-environment-no-default/gradlew.bat +++ b/seed/java-sdk/single-url-environment-no-default/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/core/RequestOptions.java b/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/core/RequestOptions.java index 7690485e2e4..feca67f16a3 100644 --- a/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/core/RequestOptions.java +++ b/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/core/RequestOptions.java @@ -5,12 +5,28 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; - private RequestOptions(String token) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -28,13 +44,28 @@ public static Builder builder() { public static final class Builder { private String token = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token); + return new RequestOptions(token, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/resources/dummy/DummyClient.java b/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/resources/dummy/DummyClient.java index d1dc023708e..5027a4fbec2 100644 --- a/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/resources/dummy/DummyClient.java +++ b/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/resources/dummy/DummyClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -36,8 +37,13 @@ public String getDummy(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), String.class); } diff --git a/seed/java-sdk/streaming/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/streaming/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/streaming/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/streaming/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/streaming/gradlew.bat b/seed/java-sdk/streaming/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/streaming/gradlew.bat +++ b/seed/java-sdk/streaming/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/streaming/src/main/java/com/seed/streaming/core/RequestOptions.java b/seed/java-sdk/streaming/src/main/java/com/seed/streaming/core/RequestOptions.java index f34611c5252..5d8c2c5ed8a 100644 --- a/seed/java-sdk/streaming/src/main/java/com/seed/streaming/core/RequestOptions.java +++ b/seed/java-sdk/streaming/src/main/java/com/seed/streaming/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/streaming/src/main/java/com/seed/streaming/resources/dummy/DummyClient.java b/seed/java-sdk/streaming/src/main/java/com/seed/streaming/resources/dummy/DummyClient.java index 1b012b4035c..7c7e7fea910 100644 --- a/seed/java-sdk/streaming/src/main/java/com/seed/streaming/resources/dummy/DummyClient.java +++ b/seed/java-sdk/streaming/src/main/java/com/seed/streaming/resources/dummy/DummyClient.java @@ -14,6 +14,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -48,8 +49,13 @@ public Iterable generateStream(GenerateStreamRequestzs request, .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return new Stream( StreamResponse.class, response.body().charStream(), "\n"); diff --git a/seed/java-sdk/trace/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/trace/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/trace/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/trace/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/trace/gradlew.bat b/seed/java-sdk/trace/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/trace/gradlew.bat +++ b/seed/java-sdk/trace/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/core/RequestOptions.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/core/RequestOptions.java index ebdeba359da..e93c5b51484 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/core/RequestOptions.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/core/RequestOptions.java @@ -5,15 +5,31 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { private final String token; private final String xRandomHeader; - private RequestOptions(String token, String xRandomHeader) { + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(String token, String xRandomHeader, Optional timeout, TimeUnit timeoutTimeUnit) { this.token = token; this.xRandomHeader = xRandomHeader; + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; } public Map getHeaders() { @@ -36,6 +52,10 @@ public static final class Builder { private String xRandomHeader = null; + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + public Builder token(String token) { this.token = token; return this; @@ -46,8 +66,19 @@ public Builder xRandomHeader(String xRandomHeader) { return this; } + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(token, xRandomHeader); + return new RequestOptions(token, xRandomHeader, timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/admin/AdminClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/admin/AdminClient.java index e2b5da03d94..ff992fa227f 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/admin/AdminClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/admin/AdminClient.java @@ -20,6 +20,7 @@ import java.util.UUID; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -57,8 +58,13 @@ public void updateTestSubmissionStatus( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -96,8 +102,13 @@ public void sendTestSubmissionUpdate( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -135,8 +146,13 @@ public void updateWorkspaceSubmissionStatus( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -174,8 +190,13 @@ public void sendWorkspaceSubmissionUpdate( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -215,8 +236,13 @@ public void storeTracedTestCase( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -256,8 +282,13 @@ public void storeTracedTestCaseV2( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -295,8 +326,13 @@ public void storeTracedWorkspace( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -334,8 +370,13 @@ public void storeTracedWorkspaceV2( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/homepage/HomepageClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/homepage/HomepageClient.java index a853e89df66..ad42d71aa9a 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/homepage/HomepageClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/homepage/HomepageClient.java @@ -13,6 +13,7 @@ import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -40,8 +41,13 @@ public List getHomepageProblems(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -77,8 +83,13 @@ public void setHomepageProblems(List request, RequestOptions requestOpti .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/migration/MigrationClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/migration/MigrationClient.java index 4bb383eb197..dbc5d2eb610 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/migration/MigrationClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/migration/MigrationClient.java @@ -14,6 +14,7 @@ import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -43,8 +44,13 @@ public List getAttemptedMigrations( _requestBuilder.addHeader("admin-key-header", request.getAdminKeyHeader()); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/playlist/PlaylistClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/playlist/PlaylistClient.java index 582d4fffac2..0c10601852b 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/playlist/PlaylistClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/playlist/PlaylistClient.java @@ -18,6 +18,7 @@ import java.util.Optional; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -64,8 +65,13 @@ public Playlist createPlaylist(int serviceParam, CreatePlaylistRequest request, .addHeader("Content-Type", "application/json"); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Playlist.class); } @@ -110,8 +116,13 @@ public List getPlaylists(int serviceParam, GetPlaylistsRequest request .addHeader("Content-Type", "application/json"); Request okhttpRequest = _requestBuilder.build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -148,8 +159,13 @@ public Playlist getPlaylist(int serviceParam, String playlistId, RequestOptions .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Playlist.class); } @@ -207,8 +223,13 @@ public Optional updatePlaylist( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -244,8 +265,13 @@ public void deletePlaylist(int serviceParam, String playlistId, RequestOptions r .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/problem/ProblemClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/problem/ProblemClient.java index ee3923de416..273febff964 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/problem/ProblemClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/problem/ProblemClient.java @@ -16,6 +16,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -57,8 +58,13 @@ public CreateProblemResponse createProblem(CreateProblemRequest request, Request .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), CreateProblemResponse.class); } @@ -102,8 +108,13 @@ public UpdateProblemResponse updateProblem( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), UpdateProblemResponse.class); } @@ -138,8 +149,13 @@ public void deleteProblem(String problemId, RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -182,8 +198,13 @@ public GetDefaultStarterFilesResponse getDefaultStarterFiles( .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), GetDefaultStarterFilesResponse.class); diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/submission/SubmissionClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/submission/SubmissionClient.java index 569bd1b171f..f2b7611a931 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/submission/SubmissionClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/submission/SubmissionClient.java @@ -15,6 +15,7 @@ import java.util.Optional; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -50,8 +51,13 @@ public ExecutionSessionResponse createExecutionSession(Language language, Reques .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ExecutionSessionResponse.class); } @@ -86,8 +92,13 @@ public Optional getExecutionSession(String sessionId, .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -123,8 +134,13 @@ public void stopExecutionSession(String sessionId, RequestOptions requestOptions .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -153,8 +169,13 @@ public GetExecutionSessionStateResponse getExecutionSessionsState(RequestOptions .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), GetExecutionSessionStateResponse.class); diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/sysprop/SyspropClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/sysprop/SyspropClient.java index a34f57635e5..1a3cbe85963 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/sysprop/SyspropClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/sysprop/SyspropClient.java @@ -13,6 +13,7 @@ import java.util.Map; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -41,8 +42,13 @@ public void setNumWarmInstances(Language language, int numWarmInstances, Request .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } @@ -71,8 +77,13 @@ public Map getNumWarmInstances(RequestOptions requestOptions) .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/V2Client.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/V2Client.java index 5ce4ee0a199..ccbfa6dc11e 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/V2Client.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/V2Client.java @@ -14,6 +14,7 @@ import java.util.function.Supplier; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -44,8 +45,13 @@ public void test(RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; } diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/problem/ProblemClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/problem/ProblemClient.java index f01837d5379..ab47b1b4f34 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/problem/ProblemClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/problem/ProblemClient.java @@ -14,6 +14,7 @@ import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -47,8 +48,13 @@ public List getLightweightProblems(RequestOptions requ .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -84,8 +90,13 @@ public List getProblems(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -122,8 +133,13 @@ public ProblemInfoV2 getLatestProblem(String problemId, RequestOptions requestOp .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ProblemInfoV2.class); } @@ -161,8 +177,13 @@ public ProblemInfoV2 getProblemVersion(String problemId, int problemVersion, Req .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ProblemInfoV2.class); } diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/v3/problem/ProblemClient.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/v3/problem/ProblemClient.java index 663e4245f54..6ef967c0123 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/v3/problem/ProblemClient.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/resources/v2/v3/problem/ProblemClient.java @@ -14,6 +14,7 @@ import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -47,8 +48,13 @@ public List getLightweightProblems(RequestOptions requ .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -84,8 +90,13 @@ public List getProblems(RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); @@ -122,8 +133,13 @@ public ProblemInfoV2 getLatestProblem(String problemId, RequestOptions requestOp .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ProblemInfoV2.class); } @@ -161,8 +177,13 @@ public ProblemInfoV2 getProblemVersion(String problemId, int problemVersion, Req .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ProblemInfoV2.class); } diff --git a/seed/java-sdk/undiscriminated-unions/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/undiscriminated-unions/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/undiscriminated-unions/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/undiscriminated-unions/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/undiscriminated-unions/gradlew.bat b/seed/java-sdk/undiscriminated-unions/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/undiscriminated-unions/gradlew.bat +++ b/seed/java-sdk/undiscriminated-unions/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/core/RequestOptions.java b/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/core/RequestOptions.java index 74e92f92d4f..c7ac0a9d8a3 100644 --- a/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/core/RequestOptions.java +++ b/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/resources/union/UnionClient.java b/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/resources/union/UnionClient.java index 36da0c15515..8af1451a8d7 100644 --- a/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/resources/union/UnionClient.java +++ b/seed/java-sdk/undiscriminated-unions/src/main/java/com/seed/undiscriminatedUnions/resources/union/UnionClient.java @@ -12,6 +12,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -45,8 +46,13 @@ public MyUnion get(MyUnion request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), MyUnion.class); } diff --git a/seed/java-sdk/unknown/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/unknown/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/unknown/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/unknown/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/unknown/gradlew.bat b/seed/java-sdk/unknown/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/unknown/gradlew.bat +++ b/seed/java-sdk/unknown/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/core/RequestOptions.java b/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/core/RequestOptions.java index 761d352388f..fab3e1c09f5 100644 --- a/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/core/RequestOptions.java +++ b/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/resources/unknown/UnknownClient.java b/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/resources/unknown/UnknownClient.java index 506984451ad..42cd1af5f7e 100644 --- a/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/resources/unknown/UnknownClient.java +++ b/seed/java-sdk/unknown/src/main/java/com/seed/unknownAsAny/resources/unknown/UnknownClient.java @@ -13,6 +13,7 @@ import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,8 +47,13 @@ public List post(Object request, RequestOptions requestOptions) { .addHeader("Content-Type", "application/json") .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue( response.body().string(), new TypeReference>() {}); diff --git a/seed/java-sdk/variables/gradle/wrapper/gradle-wrapper.properties b/seed/java-sdk/variables/gradle/wrapper/gradle-wrapper.properties index 1af9e0930b8..a80b22ce5cf 100644 --- a/seed/java-sdk/variables/gradle/wrapper/gradle-wrapper.properties +++ b/seed/java-sdk/variables/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/seed/java-sdk/variables/gradlew.bat b/seed/java-sdk/variables/gradlew.bat index 6689b85beec..7101f8e4676 100644 --- a/seed/java-sdk/variables/gradlew.bat +++ b/seed/java-sdk/variables/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/seed/java-sdk/variables/src/main/java/com/seed/variables/core/RequestOptions.java b/seed/java-sdk/variables/src/main/java/com/seed/variables/core/RequestOptions.java index b16d745d996..29bd96865c3 100644 --- a/seed/java-sdk/variables/src/main/java/com/seed/variables/core/RequestOptions.java +++ b/seed/java-sdk/variables/src/main/java/com/seed/variables/core/RequestOptions.java @@ -5,9 +5,26 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; public final class RequestOptions { - private RequestOptions() {} + private final Optional timeout; + + private final TimeUnit timeoutTimeUnit; + + private RequestOptions(Optional timeout, TimeUnit timeoutTimeUnit) { + this.timeout = timeout; + this.timeoutTimeUnit = timeoutTimeUnit; + } + + public Optional getTimeout() { + return timeout; + } + + public TimeUnit getTimeoutTimeUnit() { + return timeoutTimeUnit; + } public Map getHeaders() { Map headers = new HashMap<>(); @@ -19,8 +36,23 @@ public static Builder builder() { } public static final class Builder { + private Optional timeout = null; + + private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS; + + public Builder timeout(Integer timeout) { + this.timeout = Optional.of(timeout); + return this; + } + + public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) { + this.timeout = Optional.of(timeout); + this.timeoutTimeUnit = timeoutTimeUnit; + return this; + } + public RequestOptions build() { - return new RequestOptions(); + return new RequestOptions(timeout, timeoutTimeUnit); } } } diff --git a/seed/java-sdk/variables/src/main/java/com/seed/variables/resources/service/ServiceClient.java b/seed/java-sdk/variables/src/main/java/com/seed/variables/resources/service/ServiceClient.java index 38ad1a05d92..27bdf979f67 100644 --- a/seed/java-sdk/variables/src/main/java/com/seed/variables/resources/service/ServiceClient.java +++ b/seed/java-sdk/variables/src/main/java/com/seed/variables/resources/service/ServiceClient.java @@ -10,6 +10,7 @@ import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -36,8 +37,13 @@ public void post(RequestOptions requestOptions) { .headers(Headers.of(clientOptions.headers(requestOptions))) .build(); try { - Response response = - clientOptions.httpClient().newCall(okhttpRequest).execute(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions.getTimeout().isPresent()) { + client = client.newBuilder() + .readTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit()) + .build(); + } + Response response = client.newCall(okhttpRequest).execute(); if (response.isSuccessful()) { return; }