Search in sources :

Example 6 with HttpPipelineBuilder

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

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

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

the class LazyHttpClient method newHttpPipeLine.

// pass non-null ikeyRedirectCache if you want to use ikey-specific redirect policy
public static HttpPipeline newHttpPipeLine(@Nullable Configuration.AadAuthentication aadConfiguration, @Nullable Cache<String, String> ikeyRedirectCache) {
    List<HttpPipelinePolicy> policies = new ArrayList<>();
    // Redirect policy to handle v2.1/track redirects (and other redirects too, e.g. profiler)
    policies.add(new RedirectPolicy(ikeyRedirectCache));
    if (aadConfiguration != null && aadConfiguration.enabled) {
        policies.add(getAuthenticationPolicy(aadConfiguration));
    }
    // Add Logging Policy. Can be enabled using AZURE_LOG_LEVEL.
    // TODO set the logging level based on self diagnostic log level set by user
    policies.add(new HttpLoggingPolicy(new HttpLogOptions()));
    HttpPipelineBuilder pipelineBuilder = new HttpPipelineBuilder().httpClient(INSTANCE);
    pipelineBuilder.policies(policies.toArray(new HttpPipelinePolicy[0]));
    return pipelineBuilder.build();
}
Also used : HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) ArrayList(java.util.ArrayList) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions) HttpLoggingPolicy(com.azure.core.http.policy.HttpLoggingPolicy)

Example 9 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 10 with HttpPipelineBuilder

use of com.azure.core.http.HttpPipelineBuilder 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

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