use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class LowkeyVaultManagementClientImpl method listVaults.
@Override
public List<VaultModel> listVaults() {
final URI uri = UriUtil.uriBuilderForPath(vaultUrl, MANAGEMENT_VAULT_PATH);
final HttpRequest request = new HttpRequest(HttpMethod.GET, uri.toString()).setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
return sendAndProcess(request, r -> r.getResponseObject(VAULT_MODEL_LIST_TYPE_REF));
}
use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class LowkeyVaultManagementClientImpl method listDeletedVaults.
@Override
public List<VaultModel> listDeletedVaults() {
final URI uri = UriUtil.uriBuilderForPath(vaultUrl, MANAGEMENT_VAULT_DELETED_PATH);
final HttpRequest request = new HttpRequest(HttpMethod.GET, uri.toString()).setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
return sendAndProcess(request, r -> r.getResponseObject(VAULT_MODEL_LIST_TYPE_REF));
}
use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class ApacheHttpClientTest method testConstructorShouldConvertValuesWhenCalled.
@ParameterizedTest
@MethodSource("validProvider")
void testConstructorShouldConvertValuesWhenCalled(final String body, final Function<URI, URI> hostOverrideFunction, final String expectedHost) throws IOException {
// given
final HttpMethod method = HttpMethod.POST;
final URL url = new URL("https://localhost");
final HttpHeaders headers = new HttpHeaders(Map.of(HEADER_1, HEADER_VALUE_1, HEADER_2, HEADER_VALUE_2));
final HttpClient client = mock(HttpClient.class);
final HttpRequest azureRequest;
if (body != null) {
azureRequest = new HttpRequest(method, url, headers, Flux.defer(() -> Flux.just(ByteBuffer.wrap(body.getBytes(StandardCharsets.UTF_8)))));
} else {
azureRequest = new HttpRequest(method, url, headers, null);
}
final org.apache.http.HttpResponse response = ApacheHttpResponseTest.responseMock();
final ArgumentCaptor<HttpUriRequest> captor = ArgumentCaptor.forClass(HttpUriRequest.class);
when(client.execute(captor.capture())).thenReturn(response);
final ApacheHttpClient underTest = new ApacheHttpClient(client, hostOverrideFunction);
// when
final HttpResponse actual = underTest.send(azureRequest).block();
// then
Assertions.assertNotNull(actual);
ApacheHttpResponseTest.verifyResponse((ApacheHttpResponse) actual);
Assertions.assertEquals(expectedHost, captor.getValue().getURI().getHost());
}
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));
}
Aggregations