Search in sources :

Example 1 with HttpPipelineBuilder

use of com.azure.core.http.HttpPipelineBuilder in project mssql-jdbc by Microsoft.

the class KeyVaultHttpPipelineBuilder method buildPipeline.

/**
 * Builds the HTTP pipeline with all the necessary HTTP policies included in the pipeline.
 *
 * @return A fully built HTTP pipeline including the default HTTP client.
 * @throws SQLServerException If the {@link KeyVaultCustomCredentialPolicy} policy cannot be added to the pipeline.
 */
HttpPipeline buildPipeline() throws SQLServerException {
    // Closest to API goes first, closest to wire goes last.
    final List<HttpPipelinePolicy> policies = new ArrayList<>();
    HttpPolicyProviders.addBeforeRetryPolicies(policies);
    policies.add(retryPolicy);
    policies.add(new KeyVaultCustomCredentialPolicy(credential));
    policies.addAll(this.policies);
    HttpPolicyProviders.addAfterRetryPolicies(policies);
    policies.add(new HttpLoggingPolicy(httpLogOptions));
    return new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])).build();
}
Also used : HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) ArrayList(java.util.ArrayList) HttpLoggingPolicy(com.azure.core.http.policy.HttpLoggingPolicy)

Example 2 with HttpPipelineBuilder

use of com.azure.core.http.HttpPipelineBuilder in project ApplicationInsights-Java by microsoft.

the class QuickPulseDataFetcherTests method endpointChangesWithRedirectHeaderAndGetNewPingInterval.

@Test
void endpointChangesWithRedirectHeaderAndGetNewPingInterval() {
    Map<String, String> headers = new HashMap<>();
    headers.put("x-ms-qps-service-polling-interval-hint", "1000");
    headers.put("x-ms-qps-service-endpoint-redirect", "https://new.endpoint.com");
    headers.put("x-ms-qps-subscribed", "true");
    HttpHeaders httpHeaders = new HttpHeaders(headers);
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey("fake-key");
    HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> Mono.just(new MockHttpResponse(request, 200, httpHeaders))).build();
    QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(httpPipeline, telemetryClient, "machine1", "instance1", "qpid123");
    QuickPulseHeaderInfo quickPulseHeaderInfo = quickPulsePingSender.ping(null);
    assertThat(QuickPulseStatus.QP_IS_ON).isEqualTo(quickPulseHeaderInfo.getQuickPulseStatus());
    assertThat(1000).isEqualTo(quickPulseHeaderInfo.getQpsServicePollingInterval());
    assertThat("https://new.endpoint.com").isEqualTo(quickPulseHeaderInfo.getQpsServiceEndpointRedirect());
}
Also used : Test(org.junit.jupiter.api.Test) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) URI(java.net.URI) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) HttpHeaders(com.azure.core.http.HttpHeaders) HashMap(java.util.HashMap) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 3 with HttpPipelineBuilder

use of com.azure.core.http.HttpPipelineBuilder in project ApplicationInsights-Java by microsoft.

the class IntegrationTests method setup.

@BeforeEach
public void setup() throws Exception {
    HttpClient mockedClient = mock(HttpClient.class);
    if (testWithException) {
        when(mockedClient.send(any(HttpRequest.class), any(Context.class))).then(invocation -> Mono.error(() -> new Exception("this is expected to be logged by the operation logger")));
    } else {
        // 401, 403, 408, 429, 500, and 503 response codes result in storing to disk
        when(mockedClient.send(any(HttpRequest.class), any(Context.class))).then(invocation -> Mono.just(new MockHttpResponse(invocation.getArgument(0, HttpRequest.class), 500)));
    }
    HttpPipelineBuilder pipelineBuilder = new HttpPipelineBuilder().httpClient(mockedClient);
    localFileCache = new LocalFileCache(tempFolder);
    localFileLoader = new LocalFileLoader(localFileCache, tempFolder, null);
    StatsbeatModule statsbeatModule = Mockito.mock(StatsbeatModule.class);
    when(statsbeatModule.getNetworkStatsbeat()).thenReturn(Mockito.mock(NetworkStatsbeat.class));
    telemetryChannel = new TelemetryChannel(pipelineBuilder.build(), new URL("http://foo.bar"), new LocalFileWriter(localFileCache, tempFolder, null), statsbeatModule, false);
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) Context(com.azure.core.util.Context) NetworkStatsbeat(com.microsoft.applicationinsights.agent.internal.statsbeat.NetworkStatsbeat) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryChannel(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryChannel) URL(java.net.URL) HttpClient(com.azure.core.http.HttpClient) StatsbeatModule(com.microsoft.applicationinsights.agent.internal.statsbeat.StatsbeatModule) MockHttpResponse(com.azure.core.test.http.MockHttpResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with HttpPipelineBuilder

use of com.azure.core.http.HttpPipelineBuilder in project ApplicationInsights-Java by microsoft.

the class QuickPulsePingSenderTests method endpointChangesWithRedirectHeaderAndGetNewPingInterval.

@Test
void endpointChangesWithRedirectHeaderAndGetNewPingInterval() {
    Map<String, String> headers = new HashMap<>();
    headers.put("x-ms-qps-service-polling-interval-hint", "1000");
    headers.put("x-ms-qps-service-endpoint-redirect", "https://new.endpoint.com");
    headers.put("x-ms-qps-subscribed", "true");
    HttpHeaders httpHeaders = new HttpHeaders(headers);
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey("fake-ikey");
    HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> Mono.just(new MockHttpResponse(request, 200, httpHeaders))).build();
    QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(httpPipeline, telemetryClient, "machine1", "instance1", "qpid123");
    QuickPulseHeaderInfo quickPulseHeaderInfo = quickPulsePingSender.ping(null);
    assertThat(QuickPulseStatus.QP_IS_ON).isEqualTo(quickPulseHeaderInfo.getQuickPulseStatus());
    assertThat(1000).isEqualTo(quickPulseHeaderInfo.getQpsServicePollingInterval());
    assertThat("https://new.endpoint.com").isEqualTo(quickPulseHeaderInfo.getQpsServiceEndpointRedirect());
}
Also used : Test(org.junit.jupiter.api.Test) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) URI(java.net.URI) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) HttpHeaders(com.azure.core.http.HttpHeaders) HashMap(java.util.HashMap) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 5 with HttpPipelineBuilder

use of com.azure.core.http.HttpPipelineBuilder in project ApplicationInsights-Java by microsoft.

the class QuickPulseTestBase method getHttpPipeline.

HttpPipeline getHttpPipeline(HttpPipelinePolicy... policies) {
    HttpClient httpClient;
    if (getTestMode() == TestMode.RECORD || getTestMode() == TestMode.LIVE) {
        httpClient = HttpClient.createDefault();
    } else {
        httpClient = interceptorManager.getPlaybackClient();
    }
    List<HttpPipelinePolicy> allPolicies = new ArrayList<>();
    allPolicies.add(interceptorManager.getRecordPolicy());
    allPolicies.addAll(Arrays.asList(policies));
    return new HttpPipelineBuilder().httpClient(httpClient).policies(allPolicies.toArray(new HttpPipelinePolicy[0])).build();
}
Also used : HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) HttpClient(com.azure.core.http.HttpClient) ArrayList(java.util.ArrayList)

Aggregations

HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)15 HttpPipeline (com.azure.core.http.HttpPipeline)7 HttpPipelinePolicy (com.azure.core.http.policy.HttpPipelinePolicy)7 URL (java.net.URL)7 Test (org.junit.jupiter.api.Test)7 HttpHeaders (com.azure.core.http.HttpHeaders)6 HttpRequest (com.azure.core.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Mono (reactor.core.publisher.Mono)5 HttpClient (com.azure.core.http.HttpClient)4 NetworkStatsbeat (com.microsoft.applicationinsights.agent.internal.statsbeat.NetworkStatsbeat)4 StatsbeatModule (com.microsoft.applicationinsights.agent.internal.statsbeat.StatsbeatModule)4 IOException (java.io.IOException)4 HttpMethod (com.azure.core.http.HttpMethod)3 HttpLoggingPolicy (com.azure.core.http.policy.HttpLoggingPolicy)3 TelemetryChannel (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryChannel)3 ProfilerFrontendClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2)3 ArtifactAcceptedResponse (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse)3