-
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.
Browse files
Browse the repository at this point in the history
Fix use of multiple @ClientXXX annotations in REST Client Reactive
- Loading branch information
Showing
2 changed files
with
142 additions
and
42 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
83 changes: 83 additions & 0 deletions
83
...st/java/io/quarkus/rest/client/reactive/redirect/MultipleProvidersFromAnnotationTest.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,83 @@ | ||
package io.quarkus.rest.client.reactive.redirect; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.net.URI; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.rest.client.reactive.ClientExceptionMapper; | ||
import io.quarkus.rest.client.reactive.ClientRedirectHandler; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
|
||
public class MultipleProvidersFromAnnotationTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, Resource.class)); | ||
|
||
@Test | ||
void test() { | ||
Client client = RestClientBuilder.newBuilder() | ||
.baseUri(uri) | ||
.followRedirects(true) | ||
.build(Client.class); | ||
assertThatThrownBy(() -> client.call(2)).hasMessage("dummy"); | ||
} | ||
|
||
@TestHTTPResource | ||
URI uri; | ||
|
||
@Path("test") | ||
public interface Client { | ||
|
||
@GET | ||
void call(@QueryParam("redirects") Integer numberOfRedirects); | ||
|
||
@ClientRedirectHandler | ||
static URI redirectFor3xx(Response response) { | ||
int status = response.getStatus(); | ||
if (status > 300 && response.getStatus() < 400) { | ||
return response.getLocation(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@ClientExceptionMapper | ||
static RuntimeException toException(Response response) { | ||
if (response.getStatus() == 999) { | ||
throw new RuntimeException("dummy") { | ||
@Override | ||
public synchronized Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
}; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
@Path("test") | ||
public static class Resource { | ||
|
||
@GET | ||
public Response redirectedResponse(@QueryParam("redirects") Integer number) { | ||
if (number == null || 0 == number) { | ||
return Response.status(999).build(); | ||
} else { | ||
return Response.status(Response.Status.FOUND).location(URI.create("/test?redirects=" + (number - 1))) | ||
.build(); | ||
} | ||
} | ||
} | ||
} |