Search in sources :

Example 1 with HttpLoggingPolicy

use of com.azure.android.core.http.policy.HttpLoggingPolicy 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());
    }
}
Also used : HttpPipelineBuilder(com.azure.android.core.http.HttpPipelineBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) Response(com.azure.android.core.rest.Response) StreamResponse(com.azure.android.core.rest.StreamResponse) HttpPipeline(com.azure.android.core.http.HttpPipeline) HttpClient(com.azure.android.core.http.HttpClient) PortPolicy(com.azure.android.core.http.policy.PortPolicy) HttpLogOptions(com.azure.android.core.http.policy.HttpLogOptions) HttpLoggingPolicy(com.azure.android.core.http.policy.HttpLoggingPolicy) HttpBinJSON(com.azure.android.core.test.implementation.entities.HttpBinJSON) Test(org.junit.jupiter.api.Test)

Example 2 with HttpLoggingPolicy

use of com.azure.android.core.http.policy.HttpLoggingPolicy 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));
}
Also used : UserAgentPolicy(com.azure.android.core.http.policy.UserAgentPolicy) CookiePolicy(com.azure.android.core.http.policy.CookiePolicy) HttpLoggingPolicy(com.azure.android.core.http.policy.HttpLoggingPolicy)

Example 3 with HttpLoggingPolicy

use of com.azure.android.core.http.policy.HttpLoggingPolicy 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;
}
Also used : HttpPipelinePolicy(com.azure.android.core.http.HttpPipelinePolicy) UserAgentPolicy(com.azure.android.core.http.policy.UserAgentPolicy) HttpPipeline(com.azure.android.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.android.core.http.HttpPipelineBuilder) ArrayList(java.util.ArrayList) CookiePolicy(com.azure.android.core.http.policy.CookiePolicy) HttpLogOptions(com.azure.android.core.http.policy.HttpLogOptions) HttpLoggingPolicy(com.azure.android.core.http.policy.HttpLoggingPolicy)

Example 4 with HttpLoggingPolicy

use of com.azure.android.core.http.policy.HttpLoggingPolicy 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));
}
Also used : UserAgentPolicy(com.azure.android.core.http.policy.UserAgentPolicy) CookiePolicy(com.azure.android.core.http.policy.CookiePolicy) HttpLoggingPolicy(com.azure.android.core.http.policy.HttpLoggingPolicy)

Aggregations

HttpLoggingPolicy (com.azure.android.core.http.policy.HttpLoggingPolicy)4 CookiePolicy (com.azure.android.core.http.policy.CookiePolicy)3 UserAgentPolicy (com.azure.android.core.http.policy.UserAgentPolicy)3 HttpPipeline (com.azure.android.core.http.HttpPipeline)2 HttpPipelineBuilder (com.azure.android.core.http.HttpPipelineBuilder)2 HttpLogOptions (com.azure.android.core.http.policy.HttpLogOptions)2 HttpClient (com.azure.android.core.http.HttpClient)1 HttpPipelinePolicy (com.azure.android.core.http.HttpPipelinePolicy)1 PortPolicy (com.azure.android.core.http.policy.PortPolicy)1 Response (com.azure.android.core.rest.Response)1 StreamResponse (com.azure.android.core.rest.StreamResponse)1 HttpBinJSON (com.azure.android.core.test.implementation.entities.HttpBinJSON)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1