use of com.azure.android.core.http.policy.HttpLogOptions in project azure-sdk-for-android by Azure.
the class RestProxyTests method bytesUploadTest.
@Test
public void bytesUploadTest() throws Exception {
byte[] reqContent = "The quick brown fox jumps over the lazy dog".getBytes();
final HttpClient httpClient = createHttpClient();
// Scenario: Log the body so that body buffering/replay behavior is exercised.
//
// Order in which policies applied will be the order in which they added to builder
//
final HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient).policies(new PortPolicy(getWireMockPort(), true), new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))).build();
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
RestProxy.create(BytesUploadService.class, httpPipeline, SERIALIZER).put(reqContent, reqContent.length, new Callback<Response<HttpBinJSON>>() {
@Override
public void onSuccess(Response<HttpBinJSON> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "bytesUploadTest");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
assertEquals("The quick brown fox jumps over the lazy dog", response.getValue().data());
}
}
use of com.azure.android.core.http.policy.HttpLogOptions 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.HttpLogOptions 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