forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rest Client Reactive - MicroProfile 2.0 features
fixes quarkusio#15970
- Loading branch information
1 parent
316942e
commit 571fa92
Showing
27 changed files
with
662 additions
and
342 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
10 changes: 9 additions & 1 deletion
10
...t/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/beanparam/QueryParamItem.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 |
---|---|---|
@@ -1,15 +1,23 @@ | ||
package io.quarkus.jaxrs.client.reactive.deployment.beanparam; | ||
|
||
import org.jboss.jandex.Type; | ||
|
||
public class QueryParamItem extends Item { | ||
|
||
private final String name; | ||
private final Type valueType; | ||
|
||
public QueryParamItem(String name, ValueExtractor extractor) { | ||
public QueryParamItem(String name, ValueExtractor extractor, Type valueType) { | ||
super(ItemType.QUERY_PARAM, extractor); | ||
this.name = name; | ||
this.valueType = valueType; | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
public Type getValueType() { | ||
return valueType; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...eactive/runtime/src/main/java/io/quarkus/jaxrs/client/reactive/runtime/ToObjectArray.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.jaxrs.client.reactive.runtime; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* used by query param handling mechanism, in generated code | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ToObjectArray { | ||
|
||
public static Object[] collection(Collection<?> collection) { | ||
return collection.toArray(); | ||
} | ||
|
||
public static Object[] value(Object value) { | ||
return new Object[] { value }; | ||
} | ||
|
||
private ToObjectArray() { | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...ctive/deployment/src/test/java/io/quarkus/rest/client/reactive/redirect/RedirectTest.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,50 @@ | ||
package io.quarkus.rest.client.reactive.redirect; | ||
|
||
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.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class RedirectTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(RedirectingResourceClient.class, RedirectingResource.class)); | ||
|
||
@TestHTTPResource | ||
URI uri; | ||
|
||
@Test | ||
void shouldRedirect3Times_whenMax4() { | ||
RedirectingResourceClient client = RestClientBuilder.newBuilder() | ||
.baseUri(uri) | ||
.followRedirects(true) | ||
.property(QuarkusRestClientProperties.MAX_REDIRECTS, 4) | ||
.build(RedirectingResourceClient.class); | ||
Response call = client.call(3); | ||
assertThat(call.getStatus()).isEqualTo(200); | ||
} | ||
|
||
@Test | ||
void shouldNotRedirect3Times_whenMax2() { | ||
RedirectingResourceClient client = RestClientBuilder.newBuilder() | ||
.baseUri(uri) | ||
.followRedirects(true) | ||
.property(QuarkusRestClientProperties.MAX_REDIRECTS, 2) | ||
.build(RedirectingResourceClient.class); | ||
assertThat(client.call(3).getStatus()).isEqualTo(307); | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...eployment/src/test/java/io/quarkus/rest/client/reactive/redirect/RedirectingResource.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.redirect; | ||
|
||
import java.net.URI; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/redirect") | ||
public class RedirectingResource { | ||
|
||
@GET | ||
public Response redirectedResponse(@QueryParam("redirects") Integer number) { | ||
if (number == null || 0 == number) { | ||
return Response.ok().build(); | ||
} else { | ||
return Response.temporaryRedirect(URI.create("/redirect?redirects=" + (number - 1))).build(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ent/src/test/java/io/quarkus/rest/client/reactive/redirect/RedirectingResourceClient.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,12 @@ | ||
package io.quarkus.rest.client.reactive.redirect; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/redirect") | ||
public interface RedirectingResourceClient { | ||
@GET | ||
Response call(@QueryParam("redirects") Integer numberOfRedirects); | ||
} |
18 changes: 18 additions & 0 deletions
18
...st-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/BeanGrabber.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,18 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InstanceHandle; | ||
|
||
@SuppressWarnings("unused") | ||
public class BeanGrabber { | ||
public static <T> T getBeanIfDefined(Class<T> beanClass) { | ||
InstanceHandle<T> instance = Arc.container().instance(beanClass); | ||
if (instance.isAvailable()) { | ||
return instance.get(); | ||
} | ||
return null; | ||
} | ||
|
||
private BeanGrabber() { | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...in/java/io/quarkus/rest/client/reactive/DefaultMicroprofileRestClientExceptionMapper.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,27 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper; | ||
|
||
public class DefaultMicroprofileRestClientExceptionMapper implements ResponseExceptionMapper { | ||
|
||
public Throwable toThrowable(Response response) { | ||
try { | ||
response.bufferEntity(); | ||
} catch (Exception var3) { | ||
} | ||
|
||
return new WebApplicationException("Unknown error, status code " + response.getStatus(), response); | ||
} | ||
|
||
public boolean handles(int status, MultivaluedMap headers) { | ||
return status >= 400; | ||
} | ||
|
||
public int getPriority() { | ||
return Integer.MAX_VALUE; | ||
} | ||
} |
Oops, something went wrong.