diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/ComputedHeader.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/ComputedHeader.java new file mode 100644 index 0000000000000..3a796b6a0988d --- /dev/null +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/ComputedHeader.java @@ -0,0 +1,9 @@ +package io.quarkus.rest.client.reactive.registerclientheaders; + +public final class ComputedHeader { + + public static String get() { + return "From " + ComputedHeader.class.getName(); + } + +} diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/MultipleHeadersBindingClient.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/MultipleHeadersBindingClient.java new file mode 100644 index 0000000000000..7a4e8012169dd --- /dev/null +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/MultipleHeadersBindingClient.java @@ -0,0 +1,20 @@ +package io.quarkus.rest.client.reactive.registerclientheaders; + +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; + +import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam; +import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@RegisterRestClient +@RegisterClientHeaders(MyHeadersFactory.class) +@ClientHeaderParam(name = "my-header", value = "constant-header-value") +@ClientHeaderParam(name = "computed-header", value = "{io.quarkus.rest.client.reactive.registerclientheaders.ComputedHeader.get}") +public interface MultipleHeadersBindingClient { + @GET + @Path("/describe-request") + @ClientHeaderParam(name = "header-from-properties", value = "${header.value}") + RequestData call(@HeaderParam("jaxrs-style-header") String headerValue); +} diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/MyHeadersFactory.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/MyHeadersFactory.java index 8572362e62d2e..79068e1a0695f 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/MyHeadersFactory.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/MyHeadersFactory.java @@ -19,8 +19,8 @@ public class MyHeadersFactory implements ClientHeadersFactory { public MultivaluedMap update(MultivaluedMap incomingHeaders, MultivaluedMap clientOutgoingHeaders) { assertNotNull(beanManager); - incomingHeaders.add("foo", "bar"); - return incomingHeaders; + clientOutgoingHeaders.add("foo", "bar"); + return clientOutgoingHeaders; } } diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/RegisterClientHeadersTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/RegisterClientHeadersTest.java index 670e5213d8f3c..7d9488644b613 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/RegisterClientHeadersTest.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/registerclientheaders/RegisterClientHeadersTest.java @@ -1,9 +1,13 @@ package io.quarkus.rest.client.reactive.registerclientheaders; import static io.quarkus.rest.client.reactive.RestClientTestUtil.setUrlForClass; +import static io.quarkus.rest.client.reactive.registerclientheaders.HeaderSettingClient.HEADER; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.List; +import java.util.Map; + import org.eclipse.microprofile.rest.client.inject.RestClient; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; @@ -26,8 +30,9 @@ public class RegisterClientHeadersTest { setUrlForClass(HeaderSettingClient.class) + setUrlForClass(HeaderPassingClient.class) + setUrlForClass(HeaderNoPassingClient.class) + - "org.eclipse.microprofile.rest.client.propagateHeaders=" - + HeaderSettingClient.HEADER), + setUrlForClass(MultipleHeadersBindingClient.class) + + "org.eclipse.microprofile.rest.client.propagateHeaders=" + HEADER + "\n" + + "header.value=from property file"), "application.properties"); }); @@ -37,6 +42,9 @@ public class RegisterClientHeadersTest { @RestClient HeaderSettingClient headerSettingClient; + @RestClient + MultipleHeadersBindingClient multipleHeadersBindingClient; + @Test public void shouldUseHeadersFactory() { assertEquals("ping:bar", client.echo("ping:")); @@ -47,14 +55,30 @@ public void shouldUseHeadersFactory() { public void shouldPassIncomingHeaders() { String headerValue = "my-header-value"; RequestData requestData = headerSettingClient.setHeaderValue(headerValue); - assertThat(requestData.getHeaders().get(HeaderSettingClient.HEADER).get(0)).isEqualTo(headerValue); + assertThat(requestData.getHeaders().get(HEADER).get(0)).isEqualTo(headerValue); } @Test public void shouldNotPassIncomingHeaders() { String headerValue = "my-header-value"; RequestData requestData = headerSettingClient.setHeaderValueNoPassing(headerValue); - assertThat(requestData.getHeaders().get(HeaderSettingClient.HEADER)).isNull(); + assertThat(requestData.getHeaders().get(HEADER)).isNull(); + } + + @Test + public void shouldSetHeadersFromMultipleBindings() { + String headerValue = "my-header-value"; + Map> headers = multipleHeadersBindingClient.call(headerValue).getHeaders(); + // Verify: @RegisterClientHeaders(MyHeadersFactory.class) + assertThat(headers.get("foo")).containsExactly("bar"); + // Verify: @ClientHeaderParam(name = "my-header", value = "constant-header-value") + assertThat(headers.get("my-header")).containsExactly("constant-header-value"); + // Verify: @ClientHeaderParam(name = "computed-header", value = "{...ComputedHeader.get}") + assertThat(headers.get("computed-header")).containsExactly("From " + ComputedHeader.class.getName()); + // Verify: @ClientHeaderParam(name = "header-from-properties", value = "${header.value}") + assertThat(headers.get("header-from-properties")).containsExactly("from property file"); + // Verify: @HeaderParam("jaxrs-style-header") + assertThat(headers.get("jaxrs-style-header")).containsExactly(headerValue); } } diff --git a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientRequestFilter.java b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientRequestFilter.java index 3a6c26f8405ed..89982a4c8caaa 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientRequestFilter.java +++ b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientRequestFilter.java @@ -10,7 +10,6 @@ import javax.ws.rs.core.MultivaluedMap; import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory; -import org.eclipse.microprofile.rest.client.ext.DefaultClientHeadersFactoryImpl; import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter; @@ -55,12 +54,9 @@ public void filter(ResteasyReactiveClientRequestContext requestContext) { } } - if (clientHeadersFactory instanceof DefaultClientHeadersFactoryImpl) { - // When using the default factory, pass the proposed outgoing headers onto the request context. - // Propagation with the default factory will then overwrite any values if required. - for (Map.Entry> headerEntry : headers.entrySet()) { - requestContext.getHeaders().put(headerEntry.getKey(), castToListOfObjects(headerEntry.getValue())); - } + // Propagation with the default factory will then overwrite any values if required. + for (Map.Entry> headerEntry : headers.entrySet()) { + requestContext.getHeaders().put(headerEntry.getKey(), castToListOfObjects(headerEntry.getValue())); } if (clientHeadersFactory != null) { @@ -82,10 +78,6 @@ public void filter(ResteasyReactiveClientRequestContext requestContext) { requestContext.getHeaders().put(headerEntry.getKey(), castToListOfObjects(headerEntry.getValue())); } } - } else { - for (Map.Entry> headerEntry : headers.entrySet()) { - requestContext.getHeaders().put(headerEntry.getKey(), castToListOfObjects(headerEntry.getValue())); - } } }