Search in sources :

Example 6 with HttpPipelinePolicy

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

the class AzureFunctionsResourceManager method getClient.

public static AzureFunctionsResourceManager getClient(@Nonnull WebAppBase functionApp, @Nonnull IFunctionAppBase appService) {
    // com/azure/resourcemanager/appservice/implementation/KuduClient.java
    if (!(functionApp instanceof FunctionApp || functionApp instanceof FunctionDeploymentSlot)) {
        throw new AzureToolkitRuntimeException("Functions resource manager only applies to Azure Functions");
    }
    final List<HttpPipelinePolicy> policies = Utils.getPolicyFromPipeline(functionApp.manager().httpPipeline(), policy -> !(policy instanceof AuthenticationPolicy || policy instanceof ProviderRegistrationPolicy || policy instanceof AuxiliaryAuthenticationPolicy));
    policies.add(new AddHeadersPolicy(new HttpHeaders(Collections.singletonMap("x-functions-key", appService.getMasterKey()))));
    final HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])).httpClient(functionApp.manager().httpPipeline().getHttpClient()).build();
    final FunctionsService functionsService = RestProxy.create(FunctionsService.class, httpPipeline, SerializerFactory.createDefaultManagementSerializerAdapter());
    return new AzureFunctionsResourceManager(functionsService, appService);
}
Also used : HttpHeaders(com.azure.core.http.HttpHeaders) 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) FunctionApp(com.azure.resourcemanager.appservice.models.FunctionApp) HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) FunctionDeploymentSlot(com.azure.resourcemanager.appservice.models.FunctionDeploymentSlot) AuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy) AuxiliaryAuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy) HttpPipeline(com.azure.core.http.HttpPipeline) AddHeadersPolicy(com.azure.core.http.policy.AddHeadersPolicy)

Example 7 with HttpPipelinePolicy

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

the class TelemetryChannelTest method getTelemetryChannel.

private TelemetryChannel getTelemetryChannel() throws MalformedURLException {
    List<HttpPipelinePolicy> policies = new ArrayList<>();
    policies.add(new RedirectPolicy(Cache.bounded(5)));
    HttpPipelineBuilder pipelineBuilder = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])).httpClient(recordingHttpClient);
    LocalFileCache localFileCache = new LocalFileCache(tempFolder);
    StatsbeatModule mockedStatsModule = Mockito.mock(StatsbeatModule.class);
    when(mockedStatsModule.getNetworkStatsbeat()).thenReturn(Mockito.mock(NetworkStatsbeat.class));
    return new TelemetryChannel(pipelineBuilder.build(), new URL(END_POINT_URL), new LocalFileWriter(localFileCache, tempFolder, null), mockedStatsModule, false);
}
Also used : HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) RedirectPolicy(com.microsoft.applicationinsights.agent.internal.httpclient.RedirectPolicy) LocalFileCache(com.microsoft.applicationinsights.agent.internal.localstorage.LocalFileCache) NetworkStatsbeat(com.microsoft.applicationinsights.agent.internal.statsbeat.NetworkStatsbeat) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) LocalFileWriter(com.microsoft.applicationinsights.agent.internal.localstorage.LocalFileWriter) StatsbeatModule(com.microsoft.applicationinsights.agent.internal.statsbeat.StatsbeatModule) ArrayList(java.util.ArrayList) URL(java.net.URL)

Aggregations

HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)7 HttpPipelinePolicy (com.azure.core.http.policy.HttpPipelinePolicy)7 ArrayList (java.util.ArrayList)5 HttpLoggingPolicy (com.azure.core.http.policy.HttpLoggingPolicy)3 HttpPipeline (com.azure.core.http.HttpPipeline)2 AuthenticationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy)2 AuxiliaryAuthenticationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy)2 ProviderRegistrationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy)2 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)2 HttpClient (com.azure.core.http.HttpClient)1 HttpHeaders (com.azure.core.http.HttpHeaders)1 AddHeadersPolicy (com.azure.core.http.policy.AddHeadersPolicy)1 HttpLogOptions (com.azure.core.http.policy.HttpLogOptions)1 FunctionApp (com.azure.resourcemanager.appservice.models.FunctionApp)1 FunctionDeploymentSlot (com.azure.resourcemanager.appservice.models.FunctionDeploymentSlot)1 KuduAuthenticationPolicy (com.azure.resourcemanager.appservice.models.KuduAuthenticationPolicy)1 RedirectPolicy (com.microsoft.applicationinsights.agent.internal.httpclient.RedirectPolicy)1 LocalFileCache (com.microsoft.applicationinsights.agent.internal.localstorage.LocalFileCache)1 LocalFileWriter (com.microsoft.applicationinsights.agent.internal.localstorage.LocalFileWriter)1 NetworkStatsbeat (com.microsoft.applicationinsights.agent.internal.statsbeat.NetworkStatsbeat)1