-
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 #19498 from michalszynkiewicz/rest-client-reactive…
…-exception-mapper-once Rest Client Reactive: don't retrigger client response filters when they fail
- Loading branch information
Showing
8 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...ment/src/test/java/io/quarkus/rest/client/reactive/error/ResponseExceptionMapperTest.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,70 @@ | ||
package io.quarkus.rest.client.reactive.error; | ||
|
||
import static io.quarkus.rest.client.reactive.RestClientTestUtil.setUrlForClass; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
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 ResponseExceptionMapperTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Client.class, Resource.class, MyExceptionMapper.class).addAsResource( | ||
new StringAsset(setUrlForClass(Client.class)), | ||
"application.properties")); | ||
public static final String ERROR_MESSAGE = "The entity was not found"; | ||
|
||
@RestClient | ||
Client client; | ||
|
||
@Test | ||
void shouldInvokeExceptionMapperOnce() { | ||
assertThrows(RuntimeException.class, client::get); | ||
assertThat(MyExceptionMapper.executionCount.get()).isEqualTo(1); | ||
} | ||
|
||
@Path("/error") | ||
public static class Resource { | ||
@GET | ||
public Response returnError() { | ||
return Response.status(404).entity(ERROR_MESSAGE).build(); | ||
} | ||
} | ||
|
||
@Path("/error") | ||
@RegisterRestClient | ||
public interface Client { | ||
@GET | ||
String get(); | ||
} | ||
|
||
@Provider | ||
public static class MyExceptionMapper implements ResponseExceptionMapper<Exception> { | ||
|
||
private static final AtomicInteger executionCount = new AtomicInteger(); | ||
|
||
@Override | ||
public Exception toThrowable(Response response) { | ||
executionCount.incrementAndGet(); | ||
return new RuntimeException("My exception"); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...e/src/main/java/org/jboss/resteasy/reactive/client/handlers/PreResponseFilterHandler.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,15 @@ | ||
package org.jboss.resteasy.reactive.client.handlers; | ||
|
||
import org.jboss.resteasy.reactive.client.impl.RestClientRequestContext; | ||
import org.jboss.resteasy.reactive.client.spi.ClientRestHandler; | ||
|
||
/** | ||
* This Handler is invoked before ClientResponseFilters handler. It changes the abort handler chain | ||
* to a one without the ClientResponseFilterRestHandler's so that the filters are not retriggered in case of failure | ||
*/ | ||
public class PreResponseFilterHandler implements ClientRestHandler { | ||
@Override | ||
public void handle(RestClientRequestContext requestContext) throws Exception { | ||
requestContext.setAbortHandlerChain(requestContext.getAbortHandlerChainWithoutResponseFilters()); | ||
} | ||
} |
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
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