Search in sources :

Example 1 with HttpPipeline

use of com.azure.core.http.HttpPipeline 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 2 with HttpPipeline

use of com.azure.core.http.HttpPipeline 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 3 with HttpPipeline

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

the class ProfilerFrontendClientV2Test method uploadHitsCorrectUrl.

@Test
void uploadHitsCorrectUrl() throws IOException {
    AtomicReference<HttpRequest> requestHolder = new AtomicReference<>();
    HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> {
        requestHolder.set(request);
        return Mono.just(mockResponse(request));
    }).build();
    ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URL("http://a-host"), "a-instrumentation-key", httpPipeline);
    UUID id = UUID.randomUUID();
    BlobAccessPass pass = profilerFrontendClientV2.getUploadAccess(id).block();
    HttpRequest request = requestHolder.get();
    String url = request.getUrl().toString();
    assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.POST);
    assertThat(url.contains("/api/apps/a-instrumentation-key/artifactkinds/profile/artifacts/" + id)).isTrue();
    assertThat(url.contains("action=gettoken")).isTrue();
    assertThat(pass.getUriWithSasToken()).isEqualTo("http://localhost:99999");
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) ArtifactAcceptedResponse(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse) BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) URL(java.net.URL) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) IOException(java.io.IOException) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) UUID(java.util.UUID) Instant(java.time.Instant) AtomicReference(java.util.concurrent.atomic.AtomicReference) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) HttpRequest(com.azure.core.http.HttpRequest) HttpMethod(com.azure.core.http.HttpMethod) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) UUID(java.util.UUID) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 4 with HttpPipeline

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

the class ProfilerFrontendClientV2Test method settingsPullHitsCorrectUrl.

@Test
void settingsPullHitsCorrectUrl() throws IOException {
    AtomicReference<HttpRequest> requestHolder = new AtomicReference<>();
    HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> {
        requestHolder.set(request);
        return Mono.just(mockResponse(request, 200, "some-settings"));
    }).build();
    ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URL("http://a-host"), "a-instrumentation-key", httpPipeline);
    Date now = Date.from(Instant.now());
    String settings = profilerFrontendClientV2.getSettings(now).block();
    HttpRequest request = requestHolder.get();
    String url = request.getUrl().toString();
    assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.GET);
    assertThat(url.contains("a-instrumentation-key")).isTrue();
    assertThat(url.contains("/api/profileragent/v4/settings")).isTrue();
    assertThat(settings).isEqualTo("some-settings");
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) ArtifactAcceptedResponse(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse) BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) URL(java.net.URL) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) IOException(java.io.IOException) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) UUID(java.util.UUID) Instant(java.time.Instant) AtomicReference(java.util.concurrent.atomic.AtomicReference) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) HttpRequest(com.azure.core.http.HttpRequest) HttpMethod(com.azure.core.http.HttpMethod) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) URL(java.net.URL) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with HttpPipeline

use of com.azure.core.http.HttpPipeline in project azure-maven-plugins by microsoft.

the class AppServiceKuduManager method getClient.

public static AppServiceKuduManager getClient(@Nonnull WebAppBase webAppBase, @Nonnull IAppService appService) {
    // com/azure/resourcemanager/appservice/implementation/KuduClient.java
    if (webAppBase.defaultHostname() == null) {
        throw new AzureToolkitRuntimeException("Cannot initialize kudu client before web app is created");
    }
    String host = webAppBase.defaultHostname().toLowerCase(Locale.ROOT).replace("http://", "").replace("https://", "");
    String[] parts = host.split("\\.", 2);
    host = parts[0] + ".scm." + parts[1];
    host = "https://" + host;
    final List<HttpPipelinePolicy> policies = Utils.getPolicyFromPipeline(webAppBase.manager().httpPipeline(), policy -> !(policy instanceof AuthenticationPolicy || policy instanceof ProviderRegistrationPolicy || policy instanceof AuxiliaryAuthenticationPolicy));
    policies.add(new KuduAuthenticationPolicy(webAppBase));
    final HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])).httpClient(webAppBase.manager().httpPipeline().getHttpClient()).build();
    final KuduService kuduService = RestProxy.create(KuduService.class, httpPipeline, SerializerFactory.createDefaultManagementSerializerAdapter());
    return new AppServiceKuduManager(host, kuduService, appService);
}
Also used : AuxiliaryAuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) ProviderRegistrationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) AuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy) AuxiliaryAuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy) KuduAuthenticationPolicy(com.azure.resourcemanager.appservice.models.KuduAuthenticationPolicy) HttpPipeline(com.azure.core.http.HttpPipeline) KuduAuthenticationPolicy(com.azure.resourcemanager.appservice.models.KuduAuthenticationPolicy)

Aggregations

HttpPipeline (com.azure.core.http.HttpPipeline)8 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)7 HttpHeaders (com.azure.core.http.HttpHeaders)6 HashMap (java.util.HashMap)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Test (org.junit.jupiter.api.Test)5 Mono (reactor.core.publisher.Mono)5 HttpMethod (com.azure.core.http.HttpMethod)3 HttpRequest (com.azure.core.http.HttpRequest)3 ProfilerFrontendClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2)3 ArtifactAcceptedResponse (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse)3 BlobAccessPass (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass)3 IOException (java.io.IOException)3 URL (java.net.URL)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Instant (java.time.Instant)3 Date (java.util.Date)3 UUID (java.util.UUID)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 HttpPipelinePolicy (com.azure.core.http.policy.HttpPipelinePolicy)2