diff --git a/rest-client-vertx/src/main/java/io/apicurio/rest/client/VertxHttpClient.java b/rest-client-vertx/src/main/java/io/apicurio/rest/client/VertxHttpClient.java index 00d501a..8d9e4dc 100644 --- a/rest-client-vertx/src/main/java/io/apicurio/rest/client/VertxHttpClient.java +++ b/rest-client-vertx/src/main/java/io/apicurio/rest/client/VertxHttpClient.java @@ -10,6 +10,7 @@ import io.apicurio.rest.client.util.IoUtil; import io.apicurio.rest.client.util.UriUtil; import io.vertx.core.Context; +import io.vertx.core.MultiMap; import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpMethod; @@ -49,14 +50,13 @@ public VertxHttpClient(Vertx vertx, String basePath, Map options } private static void processConfiguration(Map configs) { - Map requestHeaders = configs.entrySet().stream() .filter(map -> map.getKey().startsWith(ApicurioClientConfig.APICURIO_REQUEST_HEADERS_PREFIX)) .collect(Collectors.toMap(map -> map.getKey() .replace(ApicurioClientConfig.APICURIO_REQUEST_HEADERS_PREFIX, ""), map -> map.getValue().toString())); if (!requestHeaders.isEmpty()) { - requestHeaders.forEach(DEFAULT_HEADERS::put); + DEFAULT_HEADERS.putAll(requestHeaders); } } @@ -71,7 +71,7 @@ public T sendRequest(Request request) { requestOptions.setHost(uri.getHost()); requestOptions.setURI(uri.getPath()); - requestOptions.setPort(uri.getPort()); + requestOptions.setAbsoluteURI(uri.toString()); DEFAULT_HEADERS.forEach(requestOptions::addHeader); @@ -89,18 +89,20 @@ public T sendRequest(Request request) { CompletableFuture resultHolder; + final String uriString = uri.toString(); + switch (request.getOperation()) { case GET: - resultHolder = executeGet(request, requestOptions); + resultHolder = executeGet(request, requestOptions.getHeaders(), uriString); break; case PUT: - resultHolder = executePut(request, requestOptions); + resultHolder = executePut(request, requestOptions.getHeaders(), uriString); break; case POST: - resultHolder = executePost(request, requestOptions); + resultHolder = executePost(request, requestOptions.getHeaders(), uriString); break; case DELETE: - resultHolder = executeDelete(request, requestOptions); + resultHolder = executeDelete(request, requestOptions.getHeaders(), uriString); break; default: throw new IllegalStateException("Operation not allowed"); @@ -109,24 +111,25 @@ public T sendRequest(Request request) { return ConcurrentUtil.result(resultHolder); } - private CompletableFuture executeGet(Request request, RequestOptions requestOptions) { - return sendRequestWithoutPayload(HttpMethod.GET, request, requestOptions); + private CompletableFuture executeGet(Request request, MultiMap requestHeaders, String absoluteUri) { + return sendRequestWithoutPayload(HttpMethod.GET, request, requestHeaders, absoluteUri); } - private CompletableFuture executeDelete(Request request, RequestOptions requestOptions) { - return sendRequestWithoutPayload(HttpMethod.DELETE, request, requestOptions); + private CompletableFuture executeDelete(Request request, MultiMap requestHeaders, String absoluteUri) { + return sendRequestWithoutPayload(HttpMethod.DELETE, request, requestHeaders, absoluteUri); } - private CompletableFuture executePost(Request request, RequestOptions requestOptions) { - return sendRequestWithPayload(HttpMethod.POST, request, requestOptions); + private CompletableFuture executePost(Request request, MultiMap requestHeaders, String absoluteUri) { + return sendRequestWithPayload(HttpMethod.POST, request, requestHeaders, absoluteUri); } - private CompletableFuture executePut(Request request, RequestOptions requestOptions) { - return sendRequestWithPayload(HttpMethod.PUT, request, requestOptions); + private CompletableFuture executePut(Request request, MultiMap requestHeaders, String absoluteUri) { + return sendRequestWithPayload(HttpMethod.PUT, request, requestHeaders, absoluteUri); } - private CompletableFuture sendRequestWithoutPayload(HttpMethod httpMethod, Request request, RequestOptions requestOptions) { - final HttpRequest httpClientRequest = webClient.request(httpMethod, requestOptions); + private CompletableFuture sendRequestWithoutPayload(HttpMethod httpMethod, Request request, MultiMap requestHeaders, String absoluteUri) { + final HttpRequest httpClientRequest = webClient.requestAbs(httpMethod, absoluteUri); + httpClientRequest.putHeaders(requestHeaders); //Iterate over query params list so we can add multiple query params with the same key request.getQueryParams().forEach((key, paramList) -> paramList @@ -138,8 +141,9 @@ private CompletableFuture sendRequestWithoutPayload(HttpMethod httpMethod return resultHolder; } - private CompletableFuture sendRequestWithPayload(HttpMethod httpMethod, Request request, RequestOptions requestOptions) { - final HttpRequest httpClientRequest = webClient.request(httpMethod, requestOptions); + private CompletableFuture sendRequestWithPayload(HttpMethod httpMethod, Request request, MultiMap requestHeaders, String absoluteUri) { + final HttpRequest httpClientRequest = webClient.requestAbs(httpMethod, absoluteUri); + httpClientRequest.putHeaders(requestHeaders); final CompletableFuture resultHolder = new CompletableFuture(); //Iterate over query params list so we can add multiple query params with the same key diff --git a/rest-client-vertx/src/test/java/io/apicurio/rest/client/auth/KeycloakTestResource.java b/rest-client-vertx/src/test/java/io/apicurio/rest/client/auth/KeycloakTestResource.java index 06a60e3..625c7b0 100644 --- a/rest-client-vertx/src/test/java/io/apicurio/rest/client/auth/KeycloakTestResource.java +++ b/rest-client-vertx/src/test/java/io/apicurio/rest/client/auth/KeycloakTestResource.java @@ -26,7 +26,7 @@ public void start() { } public String getAuthServerUrl() { - return container.getAuthServerUrl() + "/realms/" + "registry/" + TOKEN_ENDPOINT ; + return container.getAuthServerUrl() + "/realms/" + "registry/" + TOKEN_ENDPOINT; } private void createTestUser() {