use of com.azure.android.communication.chat.implementation.AzureCommunicationChatServiceImpl in project azure-sdk-for-android by Azure.
the class ChatThreadClientBuilder method createInternalClient.
private AzureCommunicationChatServiceImpl createInternalClient() {
if (endpoint == null) {
throw logger.logExceptionAsError(new NullPointerException("'endpoint' is required."));
}
HttpPipeline pipeline;
if (this.httpPipeline != null) {
pipeline = this.httpPipeline;
} else {
if (this.communicationTokenCredential == null) {
throw logger.logExceptionAsError(new NullPointerException("CommunicationTokenCredential is required."));
}
HttpPipelinePolicy authorizationPolicy = chain -> {
final CompletableFuture<CommunicationAccessToken> tokenFuture = this.communicationTokenCredential.getToken();
final CommunicationAccessToken token;
try {
token = tokenFuture.get();
} catch (ExecutionException e) {
chain.completedError(e);
return;
} catch (InterruptedException e) {
chain.completedError(e);
return;
}
HttpRequest httpRequest = chain.getRequest();
httpRequest.getHeaders().put("Authorization", "Bearer " + token.getToken());
chain.processNextPolicy(httpRequest);
};
pipeline = createHttpPipeline(this.httpClient, authorizationPolicy, this.customPolicies);
}
AzureCommunicationChatServiceImplBuilder clientBuilder = new AzureCommunicationChatServiceImplBuilder().apiVersion((this.serviceVersion == null) ? ChatServiceVersion.getLatest().getVersion() : this.serviceVersion.getVersion()).endpoint(this.endpoint).pipeline(pipeline);
return clientBuilder.buildClient();
}
Aggregations