Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP-3032: Revamping of the API Invoker #234

Merged
merged 10 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target/
build/
.gradle/
!gradle/wrapper/gradle-wrapper.jar
out/

.DS_Store
settings.xml
Expand Down
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<modules>
<module>symphony-bdk-bom</module>
<module>symphony-bdk-core</module>
<module>symphony-bdk-core-invokers</module>
<module>symphony-bdk-http</module>
<module>symphony-bdk-examples</module>
<module>symphony-bdk-spring</module>
<module>symphony-bdk-template</module>
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions symphony-bdk-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
</dependency>
<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-core-invoker-api</artifactId>
<artifactId>symphony-bdk-http-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-core-invoker-jersey2</artifactId>
<artifactId>symphony-bdk-http-jersey2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down

This file was deleted.

13 changes: 7 additions & 6 deletions symphony-bdk-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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 : "",
Expand Down
6 changes: 3 additions & 3 deletions symphony-bdk-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-core-invoker-api</artifactId>
<artifactId>symphony-bdk-http-api</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -159,7 +159,7 @@
</dependency>
<dependency>
<groupId>com.symphony.platformsolutions</groupId>
<artifactId>symphony-bdk-core-invoker-jersey2</artifactId>
<artifactId>symphony-bdk-http-jersey2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -188,7 +188,7 @@
<generateSupportingFiles>false</generateSupportingFiles>
<apiPackage>${codegen.base.package}</apiPackage>
<modelPackage>${codegen.base.package}.model</modelPackage>
<invokerPackage>com.symphony.bdk.core.api.invoker</invokerPackage>
<invokerPackage>com.symphony.bdk.http.api</invokerPackage>
<templateDirectory>${maven.multiModuleProjectDirectory}/templates</templateDirectory>
<configOptions>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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<ApiClientBuilderProvider> apiClientServiceLoader =
ServiceLoader.load(ApiClientBuilderProvider.class);

final List<ApiClientBuilderProvider> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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:
* <ul>
* <li>trying to build a Client with certificate but path and password have not been properly configured</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading