use of com.azure.core.http.HttpRequest in project vividus by vividus-framework.
the class ResponseCapturingHttpPipelinePolicyTests method shouldCaptureResponseData.
@SuppressWarnings("unchecked")
@Test
void shouldCaptureResponseData() throws MalformedURLException {
HttpResponse response = mock(HttpResponse.class);
Mono<HttpResponse> mono = mock(Mono.class);
Mono<String> body = Mono.just(BODY);
when(response.getBodyAsString()).thenReturn(body);
HttpHeaders headers = mock(HttpHeaders.class);
when(response.getHeaders()).thenReturn(headers);
Map<String, String> headersMap = Map.of("header", "value");
when(headers.toMap()).thenReturn(headersMap);
HttpRequest request = mock(HttpRequest.class);
URL url = URI.create(URL).toURL();
when(request.getUrl()).thenReturn(url).thenReturn(URI.create("https://google.com").toURL());
when(response.getRequest()).thenReturn(request);
when(response.getStatusCode()).thenReturn(SC_OK);
when(mono.doOnSuccess(argThat(c -> {
c.accept(response);
return true;
}))).thenReturn(mono);
when(next.process()).thenReturn(mono);
underTest.process(context, next);
underTest.process(context, next);
Map<String, Object> captured = underTest.getResponses();
Assertions.assertAll(() -> assertEquals(headersMap, captured.get("headers")), () -> assertEquals(body, captured.get(BODY)), () -> assertEquals(SC_OK, captured.get("status-code")), () -> assertEquals(URL, captured.get("url")));
}
use of com.azure.core.http.HttpRequest in project camel-quarkus by apache.
the class VertxHttpClientTests method testRequestBodyEndsInErrorShouldPropagateToResponse.
@Test
public void testRequestBodyEndsInErrorShouldPropagateToResponse() {
HttpClient client = new VertxHttpClientProvider().createInstance();
String contentChunk = "abcdefgh";
int repetitions = 1000;
HttpRequest request = new HttpRequest(HttpMethod.POST, url(server, "/shortPost")).setHeader("Content-Length", String.valueOf(contentChunk.length() * (repetitions + 1))).setBody(Flux.just(contentChunk).repeat(repetitions).map(s -> ByteBuffer.wrap(s.getBytes(StandardCharsets.UTF_8))).concatWith(Flux.error(new RuntimeException("boo"))));
StepVerifier.create(client.send(request)).expectErrorMessage("boo").verify(Duration.ofSeconds(10));
}
use of com.azure.core.http.HttpRequest in project camel-quarkus by apache.
the class VertxHttpClientTests method validateHeadersReturnAsIs.
@Test
public void validateHeadersReturnAsIs() {
HttpClient client = new VertxHttpClientProvider().createInstance();
final String singleValueHeaderName = "singleValue";
final String singleValueHeaderValue = "value";
final String multiValueHeaderName = "Multi-value";
final List<String> multiValueHeaderValue = Arrays.asList("value1", "value2");
HttpHeaders headers = new HttpHeaders().set(singleValueHeaderName, singleValueHeaderValue).set(multiValueHeaderName, multiValueHeaderValue);
StepVerifier.create(client.send(new HttpRequest(HttpMethod.GET, url(server, RETURN_HEADERS_AS_IS_PATH), headers, Flux.empty()))).assertNext(response -> {
Assertions.assertEquals(200, response.getStatusCode());
HttpHeaders responseHeaders = response.getHeaders();
HttpHeader singleValueHeader = responseHeaders.get(singleValueHeaderName);
assertEquals(singleValueHeaderName, singleValueHeader.getName());
assertEquals(singleValueHeaderValue, singleValueHeader.getValue());
HttpHeader multiValueHeader = responseHeaders.get("Multi-value");
assertEquals(multiValueHeaderName, multiValueHeader.getName());
}).expectComplete().verify(Duration.ofSeconds(10));
}
use of com.azure.core.http.HttpRequest in project ApplicationInsights-Java by microsoft.
the class QuickPulseDataSender method run.
@Override
public void run() {
while (true) {
HttpRequest post;
try {
post = sendQueue.take();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
if (quickPulseHeaderInfo.getQuickPulseStatus() != QuickPulseStatus.QP_IS_ON) {
continue;
}
long sendTime = System.nanoTime();
try (HttpResponse response = httpPipeline.send(post).block()) {
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
throw new AssertionError("http response mono returned empty");
}
// response body is not consumed below
LazyHttpClient.consumeResponseBody(response);
if (networkHelper.isSuccess(response)) {
QuickPulseHeaderInfo quickPulseHeaderInfo = networkHelper.getQuickPulseHeaderInfo(response);
switch(quickPulseHeaderInfo.getQuickPulseStatus()) {
case QP_IS_OFF:
case QP_IS_ON:
lastValidTransmission = sendTime;
this.quickPulseHeaderInfo = quickPulseHeaderInfo;
break;
case ERROR:
onPostError(sendTime);
break;
}
}
}
}
}
use of com.azure.core.http.HttpRequest in project ApplicationInsights-Java by microsoft.
the class QuickPulseNetworkHelper method buildRequest.
public HttpRequest buildRequest(Date currentDate, String address) {
long ticks = currentDate.getTime() * 10000 + TICKS_AT_EPOCH;
HttpRequest request = new HttpRequest(HttpMethod.POST, address);
request.setHeader(HEADER_TRANSMISSION_TIME, String.valueOf(ticks));
return request;
}
Aggregations