Search in sources :

Example 11 with HttpRequest

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));
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) URI(java.net.URI)

Example 12 with HttpRequest

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));
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) URI(java.net.URI)

Example 13 with HttpRequest

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());
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpHeaders(com.azure.core.http.HttpHeaders) HttpClient(org.apache.http.client.HttpClient) HttpResponse(com.azure.core.http.HttpResponse) HttpMethod(com.azure.core.http.HttpMethod) URL(java.net.URL) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with HttpRequest

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));
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) HttpClient(com.azure.core.http.HttpClient) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Example 15 with HttpRequest

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));
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) HttpHeaders(com.azure.core.http.HttpHeaders) HttpHeader(com.azure.core.http.HttpHeader) HttpClient(com.azure.core.http.HttpClient) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

HttpRequest (com.azure.core.http.HttpRequest)31 Test (org.junit.jupiter.api.Test)13 HttpMethod (com.azure.core.http.HttpMethod)9 HttpResponse (com.azure.core.http.HttpResponse)9 HttpClient (com.azure.core.http.HttpClient)8 URI (java.net.URI)8 URL (java.net.URL)8 HttpHeaders (com.azure.core.http.HttpHeaders)7 IOException (java.io.IOException)7 Mono (reactor.core.publisher.Mono)7 Date (java.util.Date)6 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)5 StandardCharsets (java.nio.charset.StandardCharsets)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpPipeline (com.azure.core.http.HttpPipeline)3 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)3 WireMock (com.github.tomakehurst.wiremock.client.WireMock)3 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)3 Duration (java.time.Duration)3 HashMap (java.util.HashMap)3