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();
}
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());
}
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);
}
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());
}
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();
}
Aggregations