diff --git a/.gitignore b/.gitignore index d8865b678..6cfd5f3f3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ target/ build/ .gradle/ !gradle/wrapper/gradle-wrapper.jar +out/ .DS_Store settings.xml diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 12d38de6a..73c00c601 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Sep 21 15:06:03 CEST 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/pom.xml b/pom.xml index 402cb3b39..42fd23745 100644 --- a/pom.xml +++ b/pom.xml @@ -150,7 +150,7 @@ symphony-bdk-bom symphony-bdk-core - symphony-bdk-core-invokers + symphony-bdk-http symphony-bdk-examples symphony-bdk-spring symphony-bdk-template diff --git a/settings.gradle b/settings.gradle index 4744b553b..f974ead1f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,8 +3,8 @@ rootProject.name = 'symphony-api-client-java-parent' include(':symphony-bdk-bom') include(':symphony-bdk-core') -include(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-api') -include(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-jersey2') +include(':symphony-bdk-http:symphony-bdk-http-api') +include(':symphony-bdk-http:symphony-bdk-http-jersey2') include(':symphony-bdk-template:symphony-bdk-template-api') include(':symphony-bdk-template:symphony-bdk-template-freemarker') diff --git a/symphony-bdk-bom/pom.xml b/symphony-bdk-bom/pom.xml index 79d5a0d93..797a75f3b 100644 --- a/symphony-bdk-bom/pom.xml +++ b/symphony-bdk-bom/pom.xml @@ -55,12 +55,12 @@ com.symphony.platformsolutions - symphony-bdk-core-invoker-api + symphony-bdk-http-api ${project.version} com.symphony.platformsolutions - symphony-bdk-core-invoker-jersey2 + symphony-bdk-http-jersey2 ${project.version} diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/resources/META-INF/services/com.symphony.bdk.core.api.invoker.ApiClientBuilderProvider b/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/resources/META-INF/services/com.symphony.bdk.core.api.invoker.ApiClientBuilderProvider deleted file mode 100644 index ca3c26d7a..000000000 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/resources/META-INF/services/com.symphony.bdk.core.api.invoker.ApiClientBuilderProvider +++ /dev/null @@ -1 +0,0 @@ -com.symphony.bdk.core.api.invoker.jersey2.ApiClientBuilderProviderJersey2 diff --git a/symphony-bdk-core/build.gradle b/symphony-bdk-core/build.gradle index 0cbf05391..8d29ba8ad 100644 --- a/symphony-bdk-core/build.gradle +++ b/symphony-bdk-core/build.gradle @@ -2,6 +2,7 @@ plugins { // beta version provides incremental build support id "org.openapi.generator" version "5.0.0-beta2" id "de.undercouch.download" version "4.1.1" + id "java-library" } description = 'Symphony Java BDK Core' @@ -28,7 +29,7 @@ jacocoTestCoverageVerification { } dependencies { - implementation project(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-api') + implementation project(':symphony-bdk-http:symphony-bdk-http-api') implementation project(':symphony-bdk-template:symphony-bdk-template-api') compileOnly 'org.projectlombok:lombok' @@ -37,21 +38,21 @@ dependencies { implementation 'org.mapstruct:mapstruct:1.3.1.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' - implementation 'org.apiguardian:apiguardian-api' + api 'org.apiguardian:apiguardian-api' implementation 'org.slf4j:slf4j-api' implementation 'commons-io:commons-io' implementation 'org.apache.commons:commons-lang3' implementation 'com.brsanthu:migbase64' implementation 'io.jsonwebtoken:jjwt' implementation 'org.bouncycastle:bcpkix-jdk15on' - implementation 'com.fasterxml.jackson.core:jackson-databind' - implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml' + api 'com.fasterxml.jackson.core:jackson-databind' + api 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml' implementation 'io.github.resilience4j:resilience4j-retry' implementation 'io.swagger:swagger-annotations' implementation 'com.google.code.findbugs:jsr305' implementation 'org.glassfish.jersey.core:jersey-client' - testImplementation project(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-jersey2') + testImplementation project(':symphony-bdk-http:symphony-bdk-http-jersey2') testRuntimeOnly project(':symphony-bdk-template:symphony-bdk-template-freemarker') testCompileOnly 'org.projectlombok:lombok' @@ -97,7 +98,7 @@ apisToGenerate.each { api, path -> generateApiDocumentation = false apiPackage = 'com.symphony.bdk.gen.api' modelPackage = 'com.symphony.bdk.gen.api.model' - invokerPackage = 'com.symphony.bdk.core.api.invoker' + invokerPackage = 'com.symphony.bdk.http.api' templateDir = "${rootDir}/templates" globalProperties = [ models : "", diff --git a/symphony-bdk-core/pom.xml b/symphony-bdk-core/pom.xml index b383880c0..a7141cdcb 100644 --- a/symphony-bdk-core/pom.xml +++ b/symphony-bdk-core/pom.xml @@ -47,7 +47,7 @@ com.symphony.platformsolutions - symphony-bdk-core-invoker-api + symphony-bdk-http-api @@ -159,7 +159,7 @@ com.symphony.platformsolutions - symphony-bdk-core-invoker-jersey2 + symphony-bdk-http-jersey2 test @@ -188,7 +188,7 @@ false ${codegen.base.package} ${codegen.base.package}.model - com.symphony.bdk.core.api.invoker + com.symphony.bdk.http.api ${maven.multiModuleProjectDirectory}/templates true diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java index 2392f57c4..6449cb127 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core; -import com.symphony.bdk.core.api.invoker.ApiClient; +import com.symphony.bdk.http.api.ApiClient; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.client.ApiClientFactory; import com.symphony.bdk.core.config.model.BdkConfig; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/SymphonyBdk.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/SymphonyBdk.java index 7c40aa58f..77a5136b1 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/SymphonyBdk.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/SymphonyBdk.java @@ -16,6 +16,10 @@ import com.symphony.bdk.core.service.stream.StreamService; import com.symphony.bdk.core.service.user.UserService; +import com.symphony.bdk.core.util.ServiceLookup; +import com.symphony.bdk.http.api.ApiClientBuilderProvider; +import com.symphony.bdk.http.api.HttpClient; + import lombok.extern.slf4j.Slf4j; import org.apiguardian.api.API; @@ -61,6 +65,16 @@ protected SymphonyBdk(BdkConfig config, ApiClientFactory apiClientFactory) this.activityRegistry = new ActivityRegistry(this.sessionService.getSession(botSession), this.datafeedService::subscribe); } + /** + * Get the {@link HttpClient.Builder} from a Bdk entry point. + * The returned HttpClient builder instance depends on which {@link ApiClientBuilderProvider} is implemented. + * + * @return {@link HttpClient.Builder} HttpClient builder instance. + */ + public HttpClient.Builder http() { + return HttpClient.builder(ServiceLookup.lookupSingleService(ApiClientBuilderProvider.class)); + } + /** * Get the {@link MessageService} from a Bdk entry point. * The returned message service instance. diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/exception/AuthUnauthorizedException.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/exception/AuthUnauthorizedException.java index 35fcb6a0c..3292a0ab4 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/exception/AuthUnauthorizedException.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/exception/AuthUnauthorizedException.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.auth.exception; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import org.apiguardian.api.API; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImpl.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImpl.java index 6277fc67f..9b11b9d41 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImpl.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImpl.java @@ -1,8 +1,8 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.BotAuthenticator; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImpl.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImpl.java index 3dd371e5b..7ed82899c 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImpl.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImpl.java @@ -1,8 +1,8 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.BotAuthenticator; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImpl.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImpl.java index d8af3980e..28b99d630 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImpl.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImpl.java @@ -1,8 +1,8 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AppAuthSession; import com.symphony.bdk.core.auth.ExtensionAppAuthenticator; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImpl.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImpl.java index 8842ee05a..fa19d99bf 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImpl.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImpl.java @@ -1,8 +1,8 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.OboAuthenticator; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImpl.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImpl.java index fd3c83c77..9bdbfcdc2 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImpl.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImpl.java @@ -1,8 +1,8 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.OboAuthenticator; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/ApiClientFactory.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/ApiClientFactory.java index a343f2d15..0ea7acca8 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/ApiClientFactory.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/ApiClientFactory.java @@ -2,25 +2,21 @@ import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiClientBuilder; -import com.symphony.bdk.core.api.invoker.ApiClientBuilderProvider; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiClientBuilder; +import com.symphony.bdk.http.api.ApiClientBuilderProvider; import com.symphony.bdk.core.client.exception.ApiClientInitializationException; import com.symphony.bdk.core.config.model.BdkAuthenticationConfig; import com.symphony.bdk.core.config.model.BdkConfig; import com.symphony.bdk.core.config.model.BdkSslConfig; +import com.symphony.bdk.core.util.ServiceLookup; -import lombok.Generated; import lombok.extern.slf4j.Slf4j; import org.apiguardian.api.API; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.List; -import java.util.ServiceLoader; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import javax.annotation.Nonnull; @@ -41,7 +37,7 @@ public class ApiClientFactory { private final ApiClientBuilderProvider apiClientBuilderProvider; public ApiClientFactory(@Nonnull BdkConfig config) { - this(config, findApiClientBuilderProvider()); + this(config, ServiceLookup.lookupSingleService(ApiClientBuilderProvider.class)); } public ApiClientFactory(@Nonnull BdkConfig config, @Nonnull ApiClientBuilderProvider apiClientBuilderProvider) { @@ -154,31 +150,4 @@ private byte[] getBytesFromFile(String filePath) { throw new ApiClientInitializationException("Could not read file " + filePath, e); } } - - /** - * Load {@link ApiClient} implementation class using {@link ServiceLoader}. - * - * @return an {@link ApiClientBuilderProvider}. - */ - @Generated - // exclude from code coverage as it is very difficult to mock the ServiceLoader class (which is - // final) - private static ApiClientBuilderProvider findApiClientBuilderProvider() { - - final ServiceLoader apiClientServiceLoader = - ServiceLoader.load(ApiClientBuilderProvider.class); - - final List apiClientProviders = - StreamSupport.stream(apiClientServiceLoader.spliterator(), false) - .collect(Collectors.toList()); - - if (apiClientProviders.isEmpty()) { - throw new IllegalStateException("No ApiClientProvider implementation found in classpath."); - } else if (apiClientProviders.size() > 1) { - log.warn("More than 1 ApiClientProvider implementation found in classpath, will use : {}", - apiClientProviders.stream().findFirst().get()); - } - - return apiClientProviders.stream().findFirst().get(); - } } diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/exception/ApiClientInitializationException.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/exception/ApiClientInitializationException.java index a0d8d4e16..e68d766bb 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/exception/ApiClientInitializationException.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/client/exception/ApiClientInitializationException.java @@ -1,7 +1,9 @@ package com.symphony.bdk.core.client.exception; +import com.symphony.bdk.http.api.ApiClient; + /** - * Exception thrown when initializing the {@link com.symphony.bdk.core.api.invoker.ApiClient}. This can be triggered + * Exception thrown when initializing the {@link ApiClient}. This can be triggered * when in several situation such as: *
    *
  • trying to build a Client with certificate but path and password have not been properly configured
  • diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/MessageService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/MessageService.java index 733ad4237..235770219 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/MessageService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/MessageService.java @@ -3,7 +3,7 @@ import static com.symphony.bdk.core.util.SupplierWithApiException.callAndCatchApiException; -import com.symphony.bdk.core.api.invoker.util.ApiUtils; +import com.symphony.bdk.http.api.util.ApiUtils; import com.symphony.bdk.core.service.pagination.PaginatedApi; import com.symphony.bdk.core.service.pagination.PaginatedService; import com.symphony.bdk.core.auth.AuthSession; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/SessionService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/SessionService.java index 4ceffafff..bf67d4553 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/SessionService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/SessionService.java @@ -1,7 +1,7 @@ package com.symphony.bdk.core.service; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.gen.api.SessionApi; import com.symphony.bdk.gen.api.model.UserV2; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/DatafeedService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/DatafeedService.java index 3d86d7f0e..daee75af7 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/DatafeedService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/DatafeedService.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.service.datafeed; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; /** diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/AbstractDatafeedService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/AbstractDatafeedService.java index ae758df18..913e0d94a 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/AbstractDatafeedService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/AbstractDatafeedService.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.service.datafeed.impl; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.config.model.BdkConfig; import com.symphony.bdk.core.config.model.BdkRetryConfig; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1.java index 7cdebe0be..e05202665 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.service.datafeed.impl; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.config.model.BdkConfig; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2.java index f89f62471..1d6d4cd67 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.service.datafeed.impl; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.config.model.BdkConfig; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedApi.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedApi.java index b82f3d35f..285209e9b 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedApi.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedApi.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.service.pagination; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import org.apiguardian.api.API; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedService.java index 6f177823a..8c9b9e28c 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/pagination/PaginatedService.java @@ -1,7 +1,7 @@ package com.symphony.bdk.core.service.pagination; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import org.apiguardian.api.API; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/OboStreamService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/OboStreamService.java index 433622213..ec06f1d4a 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/OboStreamService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/OboStreamService.java @@ -1,7 +1,7 @@ package com.symphony.bdk.core.service.stream; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.gen.api.StreamsApi; import com.symphony.bdk.gen.api.model.StreamAttributes; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/StreamService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/StreamService.java index 41cef9e8d..89cdb961b 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/StreamService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/StreamService.java @@ -1,7 +1,7 @@ package com.symphony.bdk.core.service.stream; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.service.stream.constant.AttachmentSort; import com.symphony.bdk.gen.api.StreamsApi; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/OboUserService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/OboUserService.java index 71419dd85..67f36a7f1 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/OboUserService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/OboUserService.java @@ -1,7 +1,7 @@ package com.symphony.bdk.core.service.user; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.gen.api.UserApi; import com.symphony.bdk.gen.api.UsersApi; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/UserService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/UserService.java index 31373c226..1d4056376 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/UserService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/UserService.java @@ -1,7 +1,7 @@ package com.symphony.bdk.core.service.user; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.service.user.constant.RoleId; import com.symphony.bdk.core.service.user.mapper.UserDetailMapper; diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/util/ServiceLookup.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/util/ServiceLookup.java new file mode 100644 index 000000000..85b7fd3b8 --- /dev/null +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/util/ServiceLookup.java @@ -0,0 +1,38 @@ +package com.symphony.bdk.core.util; + +import lombok.Generated; +import lombok.extern.slf4j.Slf4j; +import org.apiguardian.api.API; + +import java.util.List; +import java.util.ServiceLoader; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +@Slf4j +@Generated +@API(status = API.Status.INTERNAL) +public class ServiceLookup { + + /** + * Load a service implementation class using {@link ServiceLoader}. + * + * @return a service implementation class. + */ + public static T lookupSingleService(Class clz) { + + final ServiceLoader classServiceLoader = ServiceLoader.load(clz); + + final List services = StreamSupport.stream(classServiceLoader.spliterator(), false) + .collect(Collectors.toList()); + + if (services.isEmpty()) { + throw new IllegalStateException("No service implementation found in classpath."); + } else if (services.size() > 1) { + log.warn("More than 1 service implementation found in classpath, will use : {}", + services.get(0)); + } + + return services.get(0); + } +} diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/util/SupplierWithApiException.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/util/SupplierWithApiException.java index 27ba7f4b9..44b3858d1 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/util/SupplierWithApiException.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/util/SupplierWithApiException.java @@ -1,7 +1,7 @@ package com.symphony.bdk.core.util; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import org.apiguardian.api.API; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/ServiceFactoryTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/ServiceFactoryTest.java index 386824315..6a413fc6b 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/ServiceFactoryTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/ServiceFactoryTest.java @@ -5,7 +5,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiClient; +import com.symphony.bdk.http.api.ApiClient; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.client.ApiClientFactory; import com.symphony.bdk.core.config.BdkConfigLoader; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/SymphonyBdkTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/SymphonyBdkTest.java index 0ed0b26ac..2d33aa774 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/SymphonyBdkTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/SymphonyBdkTest.java @@ -23,6 +23,8 @@ import com.symphony.bdk.core.test.JsonHelper; import com.symphony.bdk.core.test.MockApiClient; +import com.symphony.bdk.http.api.HttpClient; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -95,6 +97,12 @@ void getMessageServiceTest() { assertNotNull(messageService); } + @Test + void getHttpClientBuilderTest() { + HttpClient.Builder builder = this.symphonyBdk.http(); + assertNotNull(builder); + } + @Test void oboAuthenticateTest() throws AuthUnauthorizedException { this.mockApiClient.onPost(LOGIN_PUBKEY_APP_AUTHENTICATE, "{ \"token\": \"1234\", \"name\": \"sessionToken\" }"); diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/AuthenticatorFactoryTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/AuthenticatorFactoryTest.java index a381d7e2b..97369ffad 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/AuthenticatorFactoryTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/AuthenticatorFactoryTest.java @@ -6,8 +6,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.jersey2.ApiClientBuilderJersey2; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.jersey2.ApiClientBuilderJersey2; import com.symphony.bdk.core.auth.exception.AuthInitializationException; import com.symphony.bdk.core.auth.impl.BotAuthenticatorCertImpl; import com.symphony.bdk.core.auth.impl.BotAuthenticatorRsaImpl; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImplTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImplTest.java index 83304f09b..61c989fc5 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImplTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorCertImplTest.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.test.BdkMockServer; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImplTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImplTest.java index 4143dfc31..913148817 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImplTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/BotAuthenticatorRsaImplTest.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.test.BdkMockServer; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImplTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImplTest.java index 7dae6227f..74366c836 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImplTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/ExtensionAppAuthenticatorRsaImplTest.java @@ -3,7 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AppAuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.test.MockApiClient; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImplTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImplTest.java index 651e6a9e4..a2977382d 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImplTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorCertImplTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.test.MockApiClient; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImplTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImplTest.java index b4277a9b7..1c2469f73 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImplTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/auth/impl/OboAuthenticatorRsaImplTest.java @@ -1,6 +1,6 @@ package com.symphony.bdk.core.auth.impl; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.test.BdkMockServer; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/client/ApiClientFactoryTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/client/ApiClientFactoryTest.java index c3003a4a2..dbbe05001 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/client/ApiClientFactoryTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/client/ApiClientFactoryTest.java @@ -3,8 +3,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.jersey2.ApiClientJersey2; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.jersey2.ApiClientJersey2; import com.symphony.bdk.core.client.exception.ApiClientInitializationException; import com.symphony.bdk.core.config.model.BdkConfig; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/MessageServiceTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/MessageServiceTest.java index b5c982b5e..43bea2e99 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/MessageServiceTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/MessageServiceTest.java @@ -14,9 +14,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.service.stream.constant.AttachmentSort; import com.symphony.bdk.core.test.JsonHelper; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/SessionServiceTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/SessionServiceTest.java index 17db88e9d..02db9d9df 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/SessionServiceTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/SessionServiceTest.java @@ -5,8 +5,8 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.gen.api.SessionApi; import com.symphony.bdk.gen.api.model.UserV2; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1Test.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1Test.java index dd3bf8966..6d8cad141 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1Test.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV1Test.java @@ -12,7 +12,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.auth.impl.AuthSessionRsaImpl; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2Test.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2Test.java index e9a8f28bf..a90c34a28 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2Test.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/datafeed/impl/DatafeedServiceV2Test.java @@ -8,7 +8,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.auth.impl.AuthSessionRsaImpl; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/pagination/PaginatedServiceTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/pagination/PaginatedServiceTest.java index 56881ef0a..e8dff8c07 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/pagination/PaginatedServiceTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/pagination/PaginatedServiceTest.java @@ -7,7 +7,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/stream/StreamServiceTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/stream/StreamServiceTest.java index fc60411c5..4d15f6629 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/stream/StreamServiceTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/stream/StreamServiceTest.java @@ -5,8 +5,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.service.stream.constant.AttachmentSort; import com.symphony.bdk.core.test.MockApiClient; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/user/UserServiceTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/user/UserServiceTest.java index 04c353724..7505ea114 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/user/UserServiceTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/user/UserServiceTest.java @@ -10,9 +10,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiRuntimeException; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiRuntimeException; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.service.user.constant.RoleId; import com.symphony.bdk.core.service.user.constant.UserFeature; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/BdkMockServer.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/BdkMockServer.java index 0b29685ac..0172f7684 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/BdkMockServer.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/BdkMockServer.java @@ -4,8 +4,8 @@ import static org.mockserver.model.HttpRequest.request; import static org.mockserver.model.HttpResponse.response; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.jersey2.ApiClientBuilderJersey2; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.jersey2.ApiClientBuilderJersey2; import org.mockserver.client.MockServerClient; import org.mockserver.integration.ClientAndServer; diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/MockApiClient.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/MockApiClient.java index d4d0fcac7..c32e3c7b9 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/MockApiClient.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/MockApiClient.java @@ -10,8 +10,8 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.jersey2.ApiClientJersey2; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.jersey2.ApiClientJersey2; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/symphony-bdk-examples/bdk-core-examples/build.gradle b/symphony-bdk-examples/bdk-core-examples/build.gradle index 27185cadb..4ea99407c 100644 --- a/symphony-bdk-examples/bdk-core-examples/build.gradle +++ b/symphony-bdk-examples/bdk-core-examples/build.gradle @@ -3,8 +3,9 @@ description = 'Symphony Java BDK Examples - Core' dependencies { implementation project(':symphony-bdk-core') implementation project(':symphony-bdk-template:symphony-bdk-template-api') - implementation project(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-api') - implementation project(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-jersey2') + implementation project(':symphony-bdk-http:symphony-bdk-http-api') + implementation project(':symphony-bdk-http:symphony-bdk-http-jersey2') + implementation project(':symphony-bdk-template:symphony-bdk-template-freemarker') implementation 'org.slf4j:slf4j-api' runtimeOnly 'ch.qos.logback:logback-classic' diff --git a/symphony-bdk-examples/bdk-core-examples/pom.xml b/symphony-bdk-examples/bdk-core-examples/pom.xml index 0bc4777dc..16db855ab 100644 --- a/symphony-bdk-examples/bdk-core-examples/pom.xml +++ b/symphony-bdk-examples/bdk-core-examples/pom.xml @@ -34,7 +34,7 @@ com.symphony.platformsolutions - symphony-bdk-core-invoker-jersey2 + symphony-bdk-http-jersey2 diff --git a/symphony-bdk-examples/bdk-core-examples/src/main/java/com/symphony/bdk/examples/HttpClientExampleMain.java b/symphony-bdk-examples/bdk-core-examples/src/main/java/com/symphony/bdk/examples/HttpClientExampleMain.java new file mode 100644 index 000000000..b6e3d1562 --- /dev/null +++ b/symphony-bdk-examples/bdk-core-examples/src/main/java/com/symphony/bdk/examples/HttpClientExampleMain.java @@ -0,0 +1,47 @@ +package com.symphony.bdk.examples; + +import static com.symphony.bdk.core.config.BdkConfigLoader.loadFromSymphonyDir; + +import com.symphony.bdk.core.SymphonyBdk; +import com.symphony.bdk.core.auth.exception.AuthInitializationException; +import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; +import com.symphony.bdk.core.auth.jwt.JwtHelper; +import com.symphony.bdk.core.config.exception.BdkConfigException; +import com.symphony.bdk.core.config.model.BdkConfig; +import com.symphony.bdk.gen.api.model.AuthenticateRequest; +import com.symphony.bdk.gen.api.model.Token; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.util.TypeReference; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.IOUtils; + +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.security.GeneralSecurityException; +import java.security.PrivateKey; + +@Slf4j +public class HttpClientExampleMain { + + public static void main(String[] args) throws BdkConfigException, IOException, GeneralSecurityException, + ApiException, AuthUnauthorizedException, AuthInitializationException { + + JwtHelper jwtHelper = new JwtHelper(); + BdkConfig config = loadFromSymphonyDir("config.yaml"); + final SymphonyBdk bdk = new SymphonyBdk(config); + PrivateKey privateKey = jwtHelper.parseRsaPrivateKey( + IOUtils.toString(new FileInputStream(config.getBot().getPrivateKeyPath()), StandardCharsets.UTF_8)); + final String jwt = + jwtHelper.createSignedJwt(config.getBot().getUsername(), JwtHelper.JWT_EXPIRATION_MILLIS, privateKey); + final AuthenticateRequest req = new AuthenticateRequest(); + req.setToken(jwt); + + Token token = bdk.http() + .path("https://devx1.symphony.com/login/pubkey/authenticate") + .body(req) + .post(new TypeReference() {}); + log.info(token.getToken()); + } +} diff --git a/symphony-bdk-core-invokers/pom.xml b/symphony-bdk-http/pom.xml similarity index 65% rename from symphony-bdk-core-invokers/pom.xml rename to symphony-bdk-http/pom.xml index 492618fbc..326cc6913 100644 --- a/symphony-bdk-core-invokers/pom.xml +++ b/symphony-bdk-http/pom.xml @@ -9,14 +9,14 @@ 1.2.0-SNAPSHOT - symphony-bdk-core-invokers - Symphony Java BDK Core Invokers - Symphony Java BDK Core Invokers Module + symphony-bdk-http + Symphony Java BDK Core Http + Symphony Java BDK Core Http Module pom - symphony-bdk-core-invoker-api - symphony-bdk-core-invoker-jersey2 + symphony-bdk-http-api + symphony-bdk-http-jersey2 diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/build.gradle b/symphony-bdk-http/symphony-bdk-http-api/build.gradle similarity index 81% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/build.gradle rename to symphony-bdk-http/symphony-bdk-http-api/build.gradle index 4b68b9edc..39c5d13c1 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/build.gradle +++ b/symphony-bdk-http/symphony-bdk-http-api/build.gradle @@ -1,4 +1,4 @@ -description = 'Symphony Java BDK Core Invoker API' +description = 'Symphony Java BDK Core Http API' dependencies { compileOnly 'org.projectlombok:lombok' diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/pom.xml b/symphony-bdk-http/symphony-bdk-http-api/pom.xml similarity index 90% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/pom.xml rename to symphony-bdk-http/symphony-bdk-http-api/pom.xml index 7f4fc8590..dfb6c208d 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/pom.xml +++ b/symphony-bdk-http/symphony-bdk-http-api/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - symphony-bdk-core-invokers + symphony-bdk-http com.symphony.platformsolutions 1.2.0-SNAPSHOT - symphony-bdk-core-invoker-api - Symphony Java BDK Core Invoker API + symphony-bdk-http-api + Symphony Java BDK Core Http API Symphony Java BDK Core Invoker API Module diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClient.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClient.java similarity index 95% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClient.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClient.java index 48c83f03e..e055f6c36 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClient.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClient.java @@ -1,8 +1,8 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; -import org.apiguardian.api.API; +import com.symphony.bdk.http.api.util.TypeReference; -import javax.ws.rs.core.GenericType; +import org.apiguardian.api.API; import java.util.List; import java.util.Map; @@ -42,7 +42,7 @@ ApiResponse invokeAPI( String accept, String contentType, String[] authNames, - GenericType returnType + TypeReference returnType ) throws ApiException; /** diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClientBuilder.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClientBuilder.java similarity index 98% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClientBuilder.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClientBuilder.java index 431f20cd6..8aa203aa6 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClientBuilder.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClientBuilder.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; import org.apiguardian.api.API; diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClientBuilderProvider.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClientBuilderProvider.java similarity index 86% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClientBuilderProvider.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClientBuilderProvider.java index b85f8a5b8..a8033d669 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiClientBuilderProvider.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiClientBuilderProvider.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; /** * New {@link ApiClientBuilder} instances provider. diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiException.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiException.java similarity index 98% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiException.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiException.java index cbf010ce5..5a5c90615 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiException.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiException.java @@ -1,13 +1,14 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; import lombok.Getter; import org.apiguardian.api.API; -import javax.ws.rs.core.GenericType; import java.net.HttpURLConnection; import java.util.List; import java.util.Map; +import javax.ws.rs.core.GenericType; + /** * Main exception raised when invoking {@link ApiClient#invokeAPI(String, String, List, Object, Map, Map, Map, String, String, String[], GenericType)}. * diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiResponse.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiResponse.java similarity index 96% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiResponse.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiResponse.java index 84753b988..4f4bcd1d8 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiResponse.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiResponse.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; import lombok.Getter; import org.apiguardian.api.API; diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiRuntimeException.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiRuntimeException.java similarity index 93% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiRuntimeException.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiRuntimeException.java index 7eb64635b..39262e73f 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/ApiRuntimeException.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiRuntimeException.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; import lombok.Getter; import org.apiguardian.api.API; diff --git a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/HttpClient.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/HttpClient.java new file mode 100644 index 000000000..57fdea2d8 --- /dev/null +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/HttpClient.java @@ -0,0 +1,241 @@ +package com.symphony.bdk.http.api; + +import com.symphony.bdk.http.api.util.TypeReference; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * HttpClient is the main entry point to fluent API used to build an {@link ApiClient} and execute + * client requests in order to consume responses returned + */ +public class HttpClient { + + /** + * Build an {@link Builder} from an {@link ApiClientBuilderProvider} + * + * @param provider {@link ApiClientBuilderProvider} to instantiate the {@link ApiClientBuilder} to build a {@link ApiClient}. + * @return builder to build an {@link ApiClient} and execute client requests. + */ + public static Builder builder(ApiClientBuilderProvider provider) { + return new Builder(provider); + } + + /** + * The HttpClient Fluent API builder. + */ + public static class Builder { + private ApiClientBuilderProvider provider; + private final Map headers = new HashMap<>(); + private final Map cookies = new HashMap<>(); + private final Map formParams = new HashMap<>(); + private final List queryParams = new ArrayList<>(); + private String basePath = ""; + private String path = ""; + private Object body; + private String accept = ""; + private String contentType = ""; + private byte[] keyStore = null; + private String keyStorePassword = ""; + private byte[] trustStore = null; + private String trustStorePassword = ""; + + protected Builder(ApiClientBuilderProvider provider) { + this.provider = provider; + } + + /** + * Add base path of the web resource target. + * @param basePath a base path of the web resource target. + * @return the updated builder. + */ + public Builder basePath(String basePath) { + this.basePath = basePath; + return this; + } + + /** + * Add the sub-path of the HTTP URL. + * @param path The sub-path of the HTTP URL. + * @return the updated builder. + */ + public Builder path(String path) { + this.path = path; + return this; + } + + /** + * Add an arbitrary header. + * @param key the name of the header. + * @param value the value of the header. + * @return the updated builder. + */ + public Builder header(String key, String value) { + this.headers.put(key, value); + return this; + } + + /** + * Add a cookie to be set. + * + * @param key the name of the cookie. + * @param value the value of the cookie. + * @return the updated builder. + */ + public Builder cookie(String key, String value) { + this.cookies.put(key, value); + return this; + } + + /** + * Add the query parameter. + * + * @param key the name of the parameter. + * @param value the value of the parameter. + * @return the updated builder. + */ + public Builder queryParam(String key, String value) { + this.queryParams.add(new Pair(key, value)); + return this; + } + + /** + * Add the form parameter. + * + * @param key the name of the parameter. + * @param value the value of the parameter. + * @return the updated builder. + */ + public Builder formParams(String key, Object value) { + this.formParams.put(key, value); + return this; + } + + /** + * Add the request body object. + * + * @param body the body of the request. + * @return the updated builder. + */ + public Builder body(Object body) { + this.body = body; + return this; + } + + /** + * Add the accepted response media type. + * + * @param accept accepted response media type. + * @return the updated builder. + */ + public Builder accept(String accept) { + this.accept = accept; + return this; + } + + /** + * Add the request's Content-Type header. + * + * @param contentType the request's Content-Type header. + * @return the updated builder. + */ + public Builder contentType(String contentType) { + this.contentType = contentType; + return this; + } + + /** + * Add the Java key store to the Http client. + * + * @param keyStore the Java key store. + * @param keyStorePassword the key store password. + * @return the updated builder. + */ + public Builder keyStore(byte[] keyStore, String keyStorePassword) { + this.keyStore = keyStore; + this.keyStorePassword = keyStorePassword; + return this; + } + + /** + * Add the Java trust store to the Http client. + * + * @param trustStore the Java trust store. + * @param trustStorePassword the trust store password. + * @return the updated builder. + */ + public Builder trustStore(byte[] trustStore, String trustStorePassword) { + this.trustStore = trustStore; + this.trustStorePassword = trustStorePassword; + return this; + } + + /** + * Build a request and execute it using an arbitrary request method name. + * + * @param method request method name. + * @param type the {@link TypeReference} object representing a generic Java type the response should convert to. + * @param generic response type. + * @return Response entity + * @throws ApiException if there are problems with the Api client request. + */ + public T method(String method, TypeReference type) throws ApiException { + ApiClientBuilder builder = provider.newInstance(); + builder.withBasePath(this.basePath); + + if (this.keyStore != null) { + builder.withKeyStore(this.keyStore, this.keyStorePassword); + } + if (this.trustStore != null) { + builder.withTrustStore(this.trustStore, this.trustStorePassword); + } + + if (contentType.equals("")) { + contentType = "application/json"; + } + ApiClient apiClient = builder.build(); + ApiResponse apiResponse = apiClient + .invokeAPI(this.path, method, this.queryParams, this.body, this.headers, this.cookies, this.formParams, + this.accept, this.contentType, new String[] {}, type); + return apiResponse.getData(); + } + + /** + * Build a get request and execute it. + * + * @param type the {@link TypeReference} object representing a generic Java type the response should convert to. + * @param generic response type. + * @return Response entity. + * @throws ApiException if there are problems with the Api client request. + */ + public T get(TypeReference type) throws ApiException { + return this.method("GET", type); + } + + /** + * Build a post request and execute it. + * + * @param type the {@link TypeReference} object representing a generic Java type the response should convert to. + * @param generic response type. + * @return Response entity. + * @throws ApiException if there are problems with the Api client request. + */ + public T post(TypeReference type) throws ApiException { + return this.method("POST", type); + } + + /** + * Build a delete request and execute it. + * + * @param type the {@link TypeReference} object representing a generic Java type the response should convert to. + * @param generic response type. + * @return Response entity. + * @throws ApiException if there are problems with the Api client request. + */ + public T delete(TypeReference type) throws ApiException { + return this.method("DELETE", type); + } + } +} diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/JSON.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/JSON.java similarity index 67% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/JSON.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/JSON.java index c35ead80b..c7c312978 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/JSON.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/JSON.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; public final class JSON { // required by code generated with OpenAPI Gradle plugin diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/Pair.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/Pair.java similarity index 94% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/Pair.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/Pair.java index 31bf94b4d..a2f4aea3a 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/Pair.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/Pair.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker; +package com.symphony.bdk.http.api; import lombok.Getter; import org.apiguardian.api.API; diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/util/ApiUtils.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/util/ApiUtils.java similarity index 94% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/util/ApiUtils.java rename to symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/util/ApiUtils.java index 7941ea786..13b5cdc7c 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-api/src/main/java/com/symphony/bdk/core/api/invoker/util/ApiUtils.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/util/ApiUtils.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker.util; +package com.symphony.bdk.http.api.util; import org.apiguardian.api.API; diff --git a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/util/TypeReference.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/util/TypeReference.java new file mode 100644 index 000000000..764bea7f2 --- /dev/null +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/util/TypeReference.java @@ -0,0 +1,32 @@ +package com.symphony.bdk.http.api.util; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +/** + * Represents a response entity type reference {@code T}. + * Supports in-line instantiation of objects that represent generic types with + * actual type parameters. An object that represents any parameterized type may + * be obtained by sub-classing {@code GenericClass}. + * + * @param the type reference parameter. + */ +public abstract class TypeReference { + + private final Type type; + + public TypeReference() { + this.type = ((ParameterizedType)getClass() + .getGenericSuperclass()) + .getActualTypeArguments()[0]; + } + + /** + * Get type represented by the type reference instance. + * + * @return {@link Type} represented by the type reference instance. + */ + public Type getType() { + return this.type; + } +} diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/build.gradle b/symphony-bdk-http/symphony-bdk-http-jersey2/build.gradle similarity index 89% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/build.gradle rename to symphony-bdk-http/symphony-bdk-http-jersey2/build.gradle index b6d4c4328..5b69b64e9 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/build.gradle +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/build.gradle @@ -1,7 +1,7 @@ -description = 'Symphony Java BDK Core Invoker Jersey2' +description = 'Symphony Java BDK Core Http Jersey2' dependencies { - implementation project(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-api') + implementation project(':symphony-bdk-http:symphony-bdk-http-api') implementation 'org.apiguardian:apiguardian-api' implementation 'io.jsonwebtoken:jjwt' diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/pom.xml b/symphony-bdk-http/symphony-bdk-http-jersey2/pom.xml similarity index 94% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/pom.xml rename to symphony-bdk-http/symphony-bdk-http-jersey2/pom.xml index 32ad471fe..a2096b9b2 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/pom.xml +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - symphony-bdk-core-invokers + symphony-bdk-http com.symphony.platformsolutions 1.2.0-SNAPSHOT - symphony-bdk-core-invoker-jersey2 - Symphony Java BDK Core Invoker Jersey2 + symphony-bdk-http-jersey2 + Symphony Java BDK Core Http Jersey2 Symphony Java BDK Core Invoker Jersey2 Module @@ -29,7 +29,7 @@ com.symphony.platformsolutions - symphony-bdk-core-invoker-api + symphony-bdk-http-api diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientBuilderJersey2.java b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientBuilderJersey2.java similarity index 95% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientBuilderJersey2.java rename to symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientBuilderJersey2.java index 4499e805c..c90d9fa6e 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientBuilderJersey2.java +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientBuilderJersey2.java @@ -1,9 +1,10 @@ -package com.symphony.bdk.core.api.invoker.jersey2; +package com.symphony.bdk.http.jersey2; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiClientBuilder; +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; -import com.symphony.bdk.core.api.invoker.util.ApiUtils; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiClientBuilder; +import com.symphony.bdk.http.api.util.ApiUtils; import org.apiguardian.api.API; import org.glassfish.jersey.SslConfigurator; @@ -13,13 +14,12 @@ import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.media.multipart.MultiPartFeature; -import javax.net.ssl.SSLContext; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; import java.util.HashMap; import java.util.Map; -import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; +import javax.net.ssl.SSLContext; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; /** * Specific implementation of {@link ApiClientBuilder} which creates a new instance of an {@link ApiClientJersey2}. diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientBuilderProviderJersey2.java b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientBuilderProviderJersey2.java similarity index 76% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientBuilderProviderJersey2.java rename to symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientBuilderProviderJersey2.java index 7fcdac517..ac464a618 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientBuilderProviderJersey2.java +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientBuilderProviderJersey2.java @@ -1,7 +1,7 @@ -package com.symphony.bdk.core.api.invoker.jersey2; +package com.symphony.bdk.http.jersey2; -import com.symphony.bdk.core.api.invoker.ApiClientBuilder; -import com.symphony.bdk.core.api.invoker.ApiClientBuilderProvider; +import com.symphony.bdk.http.api.ApiClientBuilder; +import com.symphony.bdk.http.api.ApiClientBuilderProvider; import org.apiguardian.api.API; diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientJersey2.java b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientJersey2.java similarity index 96% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientJersey2.java rename to symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientJersey2.java index 5f88da879..91ced5ffc 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/ApiClientJersey2.java +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientJersey2.java @@ -1,9 +1,11 @@ -package com.symphony.bdk.core.api.invoker.jersey2; +package com.symphony.bdk.http.jersey2; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.ApiException; -import com.symphony.bdk.core.api.invoker.ApiResponse; -import com.symphony.bdk.core.api.invoker.Pair; +import com.symphony.bdk.http.api.ApiClient; +import com.symphony.bdk.http.api.ApiException; +import com.symphony.bdk.http.api.ApiResponse; +import com.symphony.bdk.http.api.Pair; + +import com.symphony.bdk.http.api.util.TypeReference; import org.apiguardian.api.API; import org.glassfish.jersey.media.multipart.FormDataBodyPart; @@ -69,7 +71,7 @@ public ApiResponse invokeAPI( final String accept, final String contentType, final String[] authNames, - final GenericType returnType + final TypeReference returnType ) throws ApiException { // Not using `.target(this.basePath).path(path)` below, @@ -138,13 +140,18 @@ public ApiResponse invokeAPI( int statusCode = response.getStatusInfo().getStatusCode(); Map> responseHeaders = buildResponseHeaders(response); + GenericType genericReturnType = null; + if (returnType != null) { + genericReturnType = new GenericType<>(returnType.getType()); + } + if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) { return new ApiResponse<>(statusCode, responseHeaders); } else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) { - if (returnType == null) { + if (genericReturnType == null) { return new ApiResponse<>(statusCode, responseHeaders); } else { - return new ApiResponse<>(statusCode, responseHeaders, deserialize(response, returnType)); + return new ApiResponse<>(statusCode, responseHeaders, deserialize(response, genericReturnType)); } } else { String message = "error"; diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/JSON.java b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/JSON.java similarity index 96% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/JSON.java rename to symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/JSON.java index 3f02a1306..cc3c16412 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/JSON.java +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/JSON.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker.jersey2; +package com.symphony.bdk.http.jersey2; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; diff --git a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/RFC3339DateFormat.java b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/RFC3339DateFormat.java similarity index 91% rename from symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/RFC3339DateFormat.java rename to symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/RFC3339DateFormat.java index 501c4b91f..7087784bd 100644 --- a/symphony-bdk-core-invokers/symphony-bdk-core-invoker-jersey2/src/main/java/com/symphony/bdk/core/api/invoker/jersey2/RFC3339DateFormat.java +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/RFC3339DateFormat.java @@ -1,4 +1,4 @@ -package com.symphony.bdk.core.api.invoker.jersey2; +package com.symphony.bdk.http.jersey2; import com.fasterxml.jackson.databind.util.ISO8601DateFormat; import com.fasterxml.jackson.databind.util.ISO8601Utils; @@ -17,4 +17,4 @@ public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fie toAppendTo.append(value); return toAppendTo; } -} \ No newline at end of file +} diff --git a/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/resources/META-INF/services/com.symphony.bdk.http.api.ApiClientBuilderProvider b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/resources/META-INF/services/com.symphony.bdk.http.api.ApiClientBuilderProvider new file mode 100644 index 000000000..cfced99f0 --- /dev/null +++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/resources/META-INF/services/com.symphony.bdk.http.api.ApiClientBuilderProvider @@ -0,0 +1 @@ +com.symphony.bdk.http.jersey2.ApiClientBuilderProviderJersey2 diff --git a/symphony-bdk-spring/bdk-core-starter/build.gradle b/symphony-bdk-spring/bdk-core-starter/build.gradle index def48db59..68263f0f6 100644 --- a/symphony-bdk-spring/bdk-core-starter/build.gradle +++ b/symphony-bdk-spring/bdk-core-starter/build.gradle @@ -23,13 +23,13 @@ jacocoTestCoverageVerification { dependencies { api project(':symphony-bdk-core') - - api project(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-api') - implementation project(':symphony-bdk-core-invokers:symphony-bdk-core-invoker-jersey2') + api project(':symphony-bdk-http:symphony-bdk-http-api') + implementation project(':symphony-bdk-http:symphony-bdk-http-jersey2') api project(':symphony-bdk-template:symphony-bdk-template-api') implementation project(':symphony-bdk-template:symphony-bdk-template-freemarker') + compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' diff --git a/symphony-bdk-spring/bdk-core-starter/pom.xml b/symphony-bdk-spring/bdk-core-starter/pom.xml index a0e10e187..8b9d1dffa 100644 --- a/symphony-bdk-spring/bdk-core-starter/pom.xml +++ b/symphony-bdk-spring/bdk-core-starter/pom.xml @@ -35,7 +35,11 @@ com.symphony.platformsolutions - symphony-bdk-core-invoker-jersey2 + symphony-bdk-http-jersey2 + + + com.symphony.platformsolutions + symphony-bdk-template-freemarker com.symphony.platformsolutions diff --git a/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkApiClientsConfig.java b/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkApiClientsConfig.java index 9fd7897ab..e5d31329a 100644 --- a/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkApiClientsConfig.java +++ b/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkApiClientsConfig.java @@ -1,6 +1,6 @@ package com.symphony.bdk.spring.config; -import com.symphony.bdk.core.api.invoker.ApiClient; +import com.symphony.bdk.http.api.ApiClient; import com.symphony.bdk.gen.api.AppEntitlementApi; import com.symphony.bdk.gen.api.ApplicationApi; import com.symphony.bdk.gen.api.AttachmentsApi; @@ -37,7 +37,7 @@ * Injection of all available raw-APIs generated from the official Symphony Swagger specifications. * *

    - * Please note that each raw-API requires a particular {@link com.symphony.bdk.core.api.invoker.ApiClient} as unique + * Please note that each raw-API requires a particular {@link ApiClient} as unique * constructor parameter, depending on which component it targets: *

      *
    • Pod
    • diff --git a/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java b/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java index 23521904d..2404dd25e 100644 --- a/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java +++ b/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java @@ -1,7 +1,7 @@ package com.symphony.bdk.spring.config; -import com.symphony.bdk.core.api.invoker.ApiClient; -import com.symphony.bdk.core.api.invoker.jersey2.ApiClientBuilderProviderJersey2; +import com.symphony.bdk.http.jersey2.ApiClientBuilderProviderJersey2; +import com.symphony.bdk.http.api.ApiClient; import com.symphony.bdk.core.auth.AuthSession; import com.symphony.bdk.core.auth.AuthenticatorFactory; import com.symphony.bdk.core.auth.exception.AuthInitializationException; diff --git a/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/service/DatafeedAsyncLauncherService.java b/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/service/DatafeedAsyncLauncherService.java index 956e210c5..cc3b0f92c 100644 --- a/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/service/DatafeedAsyncLauncherService.java +++ b/symphony-bdk-spring/bdk-core-starter/src/main/java/com/symphony/bdk/spring/service/DatafeedAsyncLauncherService.java @@ -1,6 +1,6 @@ package com.symphony.bdk.spring.service; -import com.symphony.bdk.core.api.invoker.ApiException; +import com.symphony.bdk.http.api.ApiException; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.service.datafeed.DatafeedService; import com.symphony.bdk.core.service.datafeed.RealTimeEventListener; diff --git a/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java b/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java index a207a0aa8..7ee8bcef6 100644 --- a/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java +++ b/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java @@ -1,10 +1,10 @@ package com.symphony.bdk.spring; -import com.symphony.bdk.core.api.invoker.ApiClient; import com.symphony.bdk.core.client.ApiClientFactory; import com.symphony.bdk.core.config.model.BdkConfig; import com.symphony.bdk.core.test.MockApiClient; import com.symphony.bdk.gen.api.model.UserV2; +import com.symphony.bdk.http.api.ApiClient; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.SneakyThrows; diff --git a/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java b/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java index 0b6462e10..605f39ed7 100644 --- a/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java +++ b/symphony-bdk-spring/bdk-core-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java @@ -5,11 +5,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.symphony.bdk.core.api.invoker.ApiClient; import com.symphony.bdk.core.auth.AuthenticatorFactory; import com.symphony.bdk.core.auth.BotAuthenticator; import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException; import com.symphony.bdk.core.client.ApiClientFactory; +import com.symphony.bdk.http.api.ApiClient; import com.symphony.bdk.spring.SymphonyBdkCoreProperties; import org.junit.jupiter.api.Test; diff --git a/templates/api.mustache b/templates/api.mustache index 2c303bd86..7448ded7c 100644 --- a/templates/api.mustache +++ b/templates/api.mustache @@ -4,8 +4,7 @@ import {{invokerPackage}}.ApiException; import {{invokerPackage}}.ApiClient; import {{invokerPackage}}.ApiResponse; import {{invokerPackage}}.Pair; - -import javax.ws.rs.core.GenericType; // TODO remove this +import {{invokerPackage}}.util.TypeReference; {{#imports}} import {{import}}; @@ -150,7 +149,7 @@ public class {{classname}} { String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; {{#returnType}} - GenericType<{{{returnType}}}> localVarReturnType = new GenericType<{{{returnType}}}>() {}; + TypeReference<{{{returnType}}}> localVarReturnType = new TypeReference<{{{returnType}}}>() {}; {{/returnType}} return apiClient.invokeAPI(localVarPath, "{{httpMethod}}", localVarQueryParams, localVarPostBody, @@ -247,4 +246,4 @@ public class {{classname}} { {{/vendorExtensions.x-group-parameters}} {{/operation}} } -{{/operations}} \ No newline at end of file +{{/operations}}