use of com.azure.core.http.HttpRequest in project terra-cloud-resource-lib by DataBiosphere.
the class AzureResponseLogger method logResponse.
@Override
public Mono<HttpResponse> logResponse(ClientLogger clientLogger, HttpResponseLoggingContext loggingOptions) {
final HttpResponse response = loggingOptions.getHttpResponse();
final HttpRequest request = response.getRequest();
// Always add request method and request URL
JsonObject requestDataJson = new JsonObject();
requestDataJson.addProperty("requestMethod", request.getHttpMethod().toString());
requestDataJson.addProperty("requestUrl", request.getUrl().toString());
// Optionally add rich request data if provided in the logging context
Optional<ResourceManagerRequestData> requestData = Optional.ofNullable(loggingOptions.getContext()).flatMap(c -> c.getData(CLOUD_RESOURCE_REQUEST_DATA_KEY)).map(o -> (ResourceManagerRequestData) o);
requestData.ifPresent(d -> requestDataJson.add("requestBody", d.serialize()));
// verbose.
if (logger.isDebugEnabled()) {
logBody(request.getHeaders(), request.getBody(), s -> requestDataJson.addProperty("rawRequestBody", s));
logBody(response.getHeaders(), response.buffer().getBody(), s -> requestDataJson.addProperty("rawResponseBody", s));
}
// Build OperationData object.
OperationData operationData = OperationData.builder().setDuration(Optional.ofNullable(loggingOptions.getResponseDuration()).orElse(Duration.ZERO)).setTryCount(OptionalInt.of(loggingOptions.getTryCount())).setExecutionException(Optional.empty()).setHttpStatusCode(OptionalInt.of(response.getStatusCode())).setCloudOperation(requestData.map(ResourceManagerRequestData::cloudOperation).orElse(ResourceManagerOperation.AZURE_RESOURCE_MANAGER_UNKNOWN_OPERATION)).setRequestData(requestDataJson).build();
// Invoke OperationAnnotator to record the operation.
operationAnnotator.recordOperation(operationData);
return Mono.justOrEmpty(response);
}
use of com.azure.core.http.HttpRequest in project camel-quarkus by apache.
the class DeadlockTests method attemptToDeadlock.
@Test
public void attemptToDeadlock() {
HttpClient httpClient = new VertxHttpClientProvider().createInstance();
String endpoint = server.baseUrl() + GET_ENDPOINT;
for (int i = 0; i < 100; i++) {
StepVerifier.create(httpClient.send(new HttpRequest(HttpMethod.GET, endpoint)).flatMap(response -> FluxUtil.collectBytesInByteBufferStream(response.getBody()).zipWith(Mono.just(response.getStatusCode())))).assertNext(responseTuple -> {
Assertions.assertEquals(200, responseTuple.getT2());
Assertions.assertArrayEquals(expectedGetBytes, responseTuple.getT1());
}).verifyComplete();
}
}
use of com.azure.core.http.HttpRequest in project camel-quarkus by apache.
the class VertxHttpClientBuilderTests method buildWithConnectionOptions.
@Test
public void buildWithConnectionOptions() {
WebClientOptions options = new WebClientOptions();
HttpClient client = new VertxHttpClientBuilder(vertx).webClientOptions(options).connectTimeout(Duration.ofSeconds(10)).idleTimeout(Duration.ofSeconds(20)).readIdleTimeout(Duration.ofSeconds(30)).writeIdleTimeout(Duration.ofSeconds(40)).build();
try {
StepVerifier.create(client.send(new HttpRequest(HttpMethod.GET, defaultUrl))).assertNext(response -> assertEquals(200, response.getStatusCode())).verifyComplete();
assertEquals(10000, options.getConnectTimeout());
assertEquals(20, options.getIdleTimeout());
assertEquals(30, options.getReadIdleTimeout());
assertEquals(40, options.getWriteIdleTimeout());
} finally {
((VertxHttpClient) client).close();
}
}
use of com.azure.core.http.HttpRequest in project camel-quarkus by apache.
the class VertxHttpClientBuilderTests method buildWithDefaultConnectionOptions.
@Test
public void buildWithDefaultConnectionOptions() {
WebClientOptions options = new WebClientOptions();
HttpClient client = new VertxHttpClientBuilder(vertx).webClientOptions(options).build();
try {
StepVerifier.create(client.send(new HttpRequest(HttpMethod.GET, defaultUrl))).assertNext(response -> assertEquals(200, response.getStatusCode())).verifyComplete();
assertEquals(10000, options.getConnectTimeout());
assertEquals(60, options.getIdleTimeout());
assertEquals(60, options.getReadIdleTimeout());
assertEquals(60, options.getWriteIdleTimeout());
} finally {
((VertxHttpClient) client).close();
}
}
use of com.azure.core.http.HttpRequest in project camel-quarkus by apache.
the class VertxHttpClientTests method testRequestBodyIsErrorShouldPropagateToResponse.
@Test
public void testRequestBodyIsErrorShouldPropagateToResponse() {
HttpClient client = new VertxHttpClientProvider().createInstance();
HttpRequest request = new HttpRequest(HttpMethod.POST, url(server, "/shortPost")).setHeader("Content-Length", "123").setBody(Flux.error(new RuntimeException("boo")));
StepVerifier.create(client.send(request)).expectErrorMessage("boo").verify();
}
Aggregations