-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18957 from michalszynkiewicz/rest-client-reactive…
…-provider-support Rest Client Reactive: globally register providers annotated with @Provider
- Loading branch information
Showing
17 changed files
with
464 additions
and
16 deletions.
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
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
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
28 changes: 28 additions & 0 deletions
28
...tive/deployment/src/test/java/io/quarkus/rest/client/reactive/provider/GlobalFeature.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,28 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import javax.ws.rs.core.Feature; | ||
import javax.ws.rs.core.FeatureContext; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter; | ||
|
||
@Provider | ||
public class GlobalFeature implements Feature { | ||
|
||
public static boolean called; | ||
|
||
@Override | ||
public boolean configure(FeatureContext context) { | ||
context.register(FeatureInstalledFilter.class); | ||
return true; | ||
} | ||
|
||
public static class FeatureInstalledFilter implements ResteasyReactiveClientRequestFilter { | ||
|
||
@Override | ||
public void filter(ResteasyReactiveClientRequestContext requestContext) { | ||
called = true; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...eployment/src/test/java/io/quarkus/rest/client/reactive/provider/GlobalRequestFilter.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,21 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter; | ||
|
||
@Provider | ||
public class GlobalRequestFilter implements ResteasyReactiveClientRequestFilter { | ||
public static final int STATUS = 233; | ||
|
||
public static boolean abort = false; | ||
|
||
@Override | ||
public void filter(ResteasyReactiveClientRequestContext requestContext) { | ||
if (abort) { | ||
requestContext.abortWith(Response.status(STATUS).build()); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...java/io/quarkus/rest/client/reactive/provider/GlobalRequestFilterConstrainedToServer.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,17 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import javax.ws.rs.ConstrainedTo; | ||
import javax.ws.rs.RuntimeType; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter; | ||
|
||
@Provider | ||
@ConstrainedTo(RuntimeType.SERVER) | ||
public class GlobalRequestFilterConstrainedToServer implements ResteasyReactiveClientRequestFilter { | ||
@Override | ||
public void filter(ResteasyReactiveClientRequestContext requestContext) { | ||
throw new RuntimeException("Invoked filter that is constrained to server"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ployment/src/test/java/io/quarkus/rest/client/reactive/provider/GlobalResponseFilter.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,22 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import javax.annotation.Priority; | ||
import javax.ws.rs.client.ClientResponseContext; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientResponseFilter; | ||
|
||
@Provider | ||
@Priority(20) | ||
public class GlobalResponseFilter implements ResteasyReactiveClientResponseFilter { | ||
|
||
public static final int STATUS = 222; | ||
|
||
@Override | ||
public void filter(ResteasyReactiveClientRequestContext requestContext, ClientResponseContext responseContext) { | ||
if (responseContext.getStatus() != GlobalRequestFilter.STATUS) { | ||
responseContext.setStatus(STATUS); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...t/src/test/java/io/quarkus/rest/client/reactive/provider/GlobalResponseFilterLowPrio.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.rest.client.reactive.provider; | ||
|
||
import javax.annotation.Priority; | ||
import javax.ws.rs.client.ClientResponseContext; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientResponseFilter; | ||
|
||
@Priority(10) // lower prio here means executed later | ||
@Provider | ||
public class GlobalResponseFilterLowPrio implements ResteasyReactiveClientResponseFilter { | ||
|
||
public static final int STATUS = 244; | ||
public static boolean skip = false; | ||
|
||
@Override | ||
public void filter(ResteasyReactiveClientRequestContext requestContext, ClientResponseContext responseContext) { | ||
if (!skip) { | ||
responseContext.setStatus(STATUS); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...active/deployment/src/test/java/io/quarkus/rest/client/reactive/provider/HelloClient.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,19 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@Path("/hello") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@RegisterRestClient | ||
public interface HelloClient { | ||
@POST | ||
Response echo(String name); | ||
} |
21 changes: 21 additions & 0 deletions
21
...loyment/src/test/java/io/quarkus/rest/client/reactive/provider/HelloClientWithFilter.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,21 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@Path("/hello") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@RegisterProvider(ResponseFilterLowestPrio.class) | ||
@RegisterRestClient | ||
public interface HelloClientWithFilter { | ||
@POST | ||
Response echo(String name); | ||
} |
56 changes: 56 additions & 0 deletions
56
...test/java/io/quarkus/rest/client/reactive/provider/ProviderDisabledAutodiscoveryTest.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,56 @@ | ||
package io.quarkus.rest.client.reactive.provider; | ||
|
||
import static io.quarkus.rest.client.reactive.RestClientTestUtil.setUrlForClass; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URI; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
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.rest.client.reactive.HelloResource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class ProviderDisabledAutodiscoveryTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(HelloResource.class, HelloClient.class, GlobalRequestFilter.class, GlobalResponseFilter.class) | ||
.addAsResource( | ||
new StringAsset(setUrlForClass(HelloClient.class) | ||
+ "quarkus.rest-client-reactive.provider-autodiscovery=false"), | ||
"application.properties")); | ||
|
||
@RestClient | ||
HelloClient helloClient; | ||
|
||
@TestHTTPResource | ||
URI baseUri; | ||
|
||
@Test | ||
void shouldNotUseGlobalFilterForInjectedClient() { | ||
Response response = helloClient.echo("Michał"); | ||
assertThat(response.getStatus()).isEqualTo(200); | ||
} | ||
|
||
@Test | ||
void shouldNotUseGlobalFilterForBuiltClient() { | ||
Response response = helloClient().echo("Michał"); | ||
assertThat(response.getStatus()).isEqualTo(200); | ||
} | ||
|
||
private HelloClient helloClient() { | ||
return RestClientBuilder.newBuilder() | ||
.baseUri(baseUri) | ||
.build(HelloClient.class); | ||
} | ||
} |
Oops, something went wrong.