use of com.azure.android.core.http.policy.UserAgentPolicy in project azure-sdk-for-android by Azure.
the class ChatThreadClientBuilder method applyRequiredPolicies.
private void applyRequiredPolicies(List<HttpPipelinePolicy> policies, HttpPipelinePolicy authorizationPolicy) {
policies.add(new UserAgentPolicy(null, LIBRARY_PACKAGE_NAME, VERSION_NAME));
policies.add(retryPolicy == null ? RetryPolicy.withExponentialBackoff() : retryPolicy);
policies.add(new CookiePolicy());
policies.add(authorizationPolicy);
policies.add(new HttpLoggingPolicy(this.logOptions));
}
use of com.azure.android.core.http.policy.UserAgentPolicy in project azure-sdk-for-android by Azure.
the class AzureCommunicationChatServiceImplBuilder method createHttpPipeline.
private HttpPipeline createHttpPipeline() {
if (httpLogOptions == null) {
httpLogOptions = new HttpLogOptions();
}
List<HttpPipelinePolicy> policies = new ArrayList<>();
String clientName = properties.get(SDK_NAME);
if (clientName == null) {
clientName = "UnknownName";
}
String clientVersion = properties.get(SDK_VERSION);
if (clientVersion == null) {
clientVersion = "UnknownVersion";
}
policies.add(new UserAgentPolicy(null, clientName, clientVersion));
policies.add(retryPolicy == null ? RetryPolicy.withExponentialBackoff() : retryPolicy);
policies.add(new CookiePolicy());
policies.addAll(this.pipelinePolicies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])).httpClient(httpClient).build();
return httpPipeline;
}
use of com.azure.android.core.http.policy.UserAgentPolicy in project azure-sdk-for-android by Azure.
the class ChatClientBuilder method buildAsyncClient.
/**
* Create asynchronous client applying CommunicationTokenCredential, UserAgentPolicy,
* RetryPolicy, and CookiePolicy.
* Additional HttpPolicies specified by additionalPolicies will be applied after them
*
* @throws NullPointerException if endpoint or CommunicationTokenCredential is not set.
* @return A {@link ChatAsyncClient} instance.
*/
public ChatAsyncClient buildAsyncClient() {
if (this.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 new ChatAsyncClient(clientBuilder.buildClient(), this.communicationTokenCredential);
}
use of com.azure.android.core.http.policy.UserAgentPolicy in project azure-sdk-for-android by Azure.
the class ChatClientBuilder method applyRequiredPolicies.
private void applyRequiredPolicies(List<HttpPipelinePolicy> policies, HttpPipelinePolicy authorizationPolicy) {
policies.add(new UserAgentPolicy(null, LIBRARY_PACKAGE_NAME, VERSION_NAME));
policies.add(retryPolicy == null ? RetryPolicy.withExponentialBackoff() : retryPolicy);
policies.add(new CookiePolicy());
policies.add(authorizationPolicy);
policies.add(new HttpLoggingPolicy(this.logOptions));
}
use of com.azure.android.core.http.policy.UserAgentPolicy in project azure-sdk-for-android by Azure.
the class MainActivity method createChatAsyncClient.
public void createChatAsyncClient() {
try {
chatAsyncClient = new ChatClientBuilder().endpoint(endpoint).credential(new CommunicationTokenCredential(firstUserAccessToken)).addPolicy(new UserAgentPolicy(APPLICATION_ID, SDK_NAME, sdkVersion)).httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS).addAllowedHeaderName("MS-CV")).buildAsyncClient();
Log.d(TAG, "Created ChatAsyncClient");
} catch (Exception e) {
Log.e("ChatAsyncClient creation failed", Objects.requireNonNull(e.getMessage()));
}
}
Aggregations