forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rest Client - support injection for @RegisterClientHeaders
- resolves quarkusio#9301
- Loading branch information
Showing
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ient/deployment/src/test/java/io/quarkus/restclient/registerclientheaders/EchoClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.restclient.registerclientheaders; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@Path("/echo") | ||
@RegisterRestClient | ||
@RegisterClientHeaders(MyHeadersFactory.class) | ||
public interface EchoClient { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
String echo(@QueryParam("message") String message); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...nt/deployment/src/test/java/io/quarkus/restclient/registerclientheaders/EchoResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.restclient.registerclientheaders; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.HeaderParam; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@Path("/echo") | ||
public class EchoResource { | ||
|
||
@RestClient | ||
EchoClient client; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
public String echo(@QueryParam("message") String message, @HeaderParam("foo") String foo) { | ||
return message + foo; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...eployment/src/test/java/io/quarkus/restclient/registerclientheaders/MyHeadersFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.restclient.registerclientheaders; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
|
||
import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory; | ||
|
||
@Singleton | ||
public class MyHeadersFactory implements ClientHeadersFactory { | ||
|
||
@Inject | ||
BeanManager beanManager; | ||
|
||
@Override | ||
public MultivaluedMap<String, String> update(MultivaluedMap<String, String> incomingHeaders, | ||
MultivaluedMap<String, String> clientOutgoingHeaders) { | ||
assertNotNull(beanManager); | ||
incomingHeaders.add("foo", "bar"); | ||
return incomingHeaders; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
.../src/test/java/io/quarkus/restclient/registerclientheaders/RegisterClientHeadersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.quarkus.restclient.registerclientheaders; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class RegisterClientHeadersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(EchoResource.class, EchoClient.class, MyHeadersFactory.class) | ||
.addAsResource( | ||
new StringAsset("io.quarkus.restclient.registerclientheaders.EchoClient/mp-rest/url=${test.url}"), | ||
"application.properties")); | ||
|
||
@RestClient | ||
EchoClient client; | ||
|
||
@Test | ||
public void testProvider() { | ||
assertEquals("ping:bar", client.echo("ping:")); | ||
} | ||
|
||
} |