Search in sources :

Example 1 with AzureCommunicationChatServiceImpl

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();
}
Also used : AzureCommunicationChatServiceImplBuilder(com.azure.android.communication.chat.implementation.AzureCommunicationChatServiceImplBuilder) AzureCommunicationChatServiceImpl(com.azure.android.communication.chat.implementation.AzureCommunicationChatServiceImpl) VERSION_NAME(com.azure.android.communication.chat.BuildConfig.VERSION_NAME) RetryPolicy(com.azure.android.core.http.policy.RetryPolicy) ServiceClientBuilder(com.azure.android.core.rest.annotation.ServiceClientBuilder) UserAgentPolicy(com.azure.android.core.http.policy.UserAgentPolicy) CompletableFuture(java9.util.concurrent.CompletableFuture) ClientLogger(com.azure.android.core.logging.ClientLogger) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) LIBRARY_PACKAGE_NAME(com.azure.android.communication.chat.BuildConfig.LIBRARY_PACKAGE_NAME) HttpPipelineBuilder(com.azure.android.core.http.HttpPipelineBuilder) HttpLoggingPolicy(com.azure.android.core.http.policy.HttpLoggingPolicy) List(java.util.List) HttpLogOptions(com.azure.android.core.http.policy.HttpLogOptions) HttpPipelinePolicy(com.azure.android.core.http.HttpPipelinePolicy) HttpPipeline(com.azure.android.core.http.HttpPipeline) CookiePolicy(com.azure.android.core.http.policy.CookiePolicy) CommunicationTokenCredential(com.azure.android.communication.common.CommunicationTokenCredential) HttpClient(com.azure.android.core.http.HttpClient) HttpRequest(com.azure.android.core.http.HttpRequest) CommunicationAccessToken(com.azure.android.communication.common.CommunicationAccessToken) CommunicationAccessToken(com.azure.android.communication.common.CommunicationAccessToken) HttpRequest(com.azure.android.core.http.HttpRequest) HttpPipelinePolicy(com.azure.android.core.http.HttpPipelinePolicy) CompletableFuture(java9.util.concurrent.CompletableFuture) AzureCommunicationChatServiceImplBuilder(com.azure.android.communication.chat.implementation.AzureCommunicationChatServiceImplBuilder) HttpPipeline(com.azure.android.core.http.HttpPipeline) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

LIBRARY_PACKAGE_NAME (com.azure.android.communication.chat.BuildConfig.LIBRARY_PACKAGE_NAME)1 VERSION_NAME (com.azure.android.communication.chat.BuildConfig.VERSION_NAME)1 AzureCommunicationChatServiceImpl (com.azure.android.communication.chat.implementation.AzureCommunicationChatServiceImpl)1 AzureCommunicationChatServiceImplBuilder (com.azure.android.communication.chat.implementation.AzureCommunicationChatServiceImplBuilder)1 CommunicationAccessToken (com.azure.android.communication.common.CommunicationAccessToken)1 CommunicationTokenCredential (com.azure.android.communication.common.CommunicationTokenCredential)1 HttpClient (com.azure.android.core.http.HttpClient)1 HttpPipeline (com.azure.android.core.http.HttpPipeline)1 HttpPipelineBuilder (com.azure.android.core.http.HttpPipelineBuilder)1 HttpPipelinePolicy (com.azure.android.core.http.HttpPipelinePolicy)1 HttpRequest (com.azure.android.core.http.HttpRequest)1 CookiePolicy (com.azure.android.core.http.policy.CookiePolicy)1 HttpLogOptions (com.azure.android.core.http.policy.HttpLogOptions)1 HttpLoggingPolicy (com.azure.android.core.http.policy.HttpLoggingPolicy)1 RetryPolicy (com.azure.android.core.http.policy.RetryPolicy)1 UserAgentPolicy (com.azure.android.core.http.policy.UserAgentPolicy)1 ClientLogger (com.azure.android.core.logging.ClientLogger)1 ServiceClientBuilder (com.azure.android.core.rest.annotation.ServiceClientBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1