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.
Never propagate a WebApplicationException from the client
If a call fails on the server it should be treated as an internal server error, it should not be propagating the response back to the original request. Fixes quarkusio#19488
- Loading branch information
1 parent
b480e3a
commit 6674bd5
Showing
8 changed files
with
235 additions
and
3 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
110 changes: 110 additions & 0 deletions
110
...st/java/io/quarkus/rest/client/reactive/jackson/test/BadRequestNotPropagatedTestCase.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,110 @@ | ||
package io.quarkus.rest.client.reactive.jackson.test; | ||
|
||
import java.net.URL; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
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.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
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; | ||
|
||
/** | ||
* Tests that a 400 response from jackson on the client is not propagated to the server as a 400, | ||
* but is instead reported as an internal server error | ||
*/ | ||
public class BadRequestNotPropagatedTestCase { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); | ||
|
||
@TestHTTPResource | ||
URL url; | ||
|
||
private Client client; | ||
|
||
@BeforeEach | ||
public void before() { | ||
client = ClientBuilder.newBuilder().build(); | ||
} | ||
|
||
@AfterEach | ||
public void after() { | ||
client.close(); | ||
} | ||
|
||
@Test | ||
public void testBadRequest() { | ||
Response data = client.target(url.toExternalForm() + "/bad-server").request().get(); | ||
Assertions.assertEquals(500, data.getStatus()); | ||
} | ||
|
||
@Path("/bad") | ||
public static class Bad { | ||
|
||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@GET | ||
public JsonObject get(List<JsonObject> o) { | ||
return o.get(0); | ||
} | ||
} | ||
|
||
@Path("/bad") | ||
@RegisterRestClient(baseUri = "http://localhost:8081") | ||
public interface BadClient { | ||
|
||
@Produces(MediaType.APPLICATION_JSON) | ||
@GET | ||
JsonObject get(String json); | ||
} | ||
|
||
static class JsonObject { | ||
String name; | ||
} | ||
|
||
@Path("/bad-server") | ||
public static class BadServer { | ||
|
||
@Inject | ||
@RestClient | ||
BadClient badClient; | ||
|
||
@GET | ||
public JsonObject get() { | ||
try { | ||
return badClient.get("{name:foo}"); | ||
} catch (WebApplicationException e) { | ||
if (e.getResponse().getStatus() != 400) { | ||
//this is a bit odd, but we are trying to test that a 400 from jackson won't cause a 400 | ||
//response from the server part | ||
//returning this will cause a 204 response and fail the test, as if the original exception is | ||
//not 400 then something has gone wrong | ||
return null; | ||
} | ||
throw e; | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
...mmon/runtime/src/main/java/org/jboss/resteasy/reactive/ClientWebApplicationException.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,72 @@ | ||
package org.jboss.resteasy.reactive; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
|
||
public class ClientWebApplicationException extends WebApplicationException implements ResteasyReactiveClientProblem { | ||
|
||
public ClientWebApplicationException() { | ||
super(); | ||
} | ||
|
||
public ClientWebApplicationException(String message) { | ||
super(message); | ||
} | ||
|
||
public ClientWebApplicationException(Response response) { | ||
super(response); | ||
} | ||
|
||
public ClientWebApplicationException(String message, Response response) { | ||
super(message, response); | ||
} | ||
|
||
public ClientWebApplicationException(int status) { | ||
super(status); | ||
} | ||
|
||
public ClientWebApplicationException(String message, int status) { | ||
super(message, status); | ||
} | ||
|
||
public ClientWebApplicationException(Response.Status status) { | ||
super(status); | ||
} | ||
|
||
public ClientWebApplicationException(String message, Response.Status status) { | ||
super(message, status); | ||
} | ||
|
||
public ClientWebApplicationException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ClientWebApplicationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ClientWebApplicationException(Throwable cause, Response response) { | ||
super(cause, response); | ||
} | ||
|
||
public ClientWebApplicationException(String message, Throwable cause, Response response) { | ||
super(message, cause, response); | ||
} | ||
|
||
public ClientWebApplicationException(Throwable cause, int status) { | ||
super(cause, status); | ||
} | ||
|
||
public ClientWebApplicationException(String message, Throwable cause, int status) { | ||
super(message, cause, status); | ||
} | ||
|
||
public ClientWebApplicationException(Throwable cause, Response.Status status) throws IllegalArgumentException { | ||
super(cause, status); | ||
} | ||
|
||
public ClientWebApplicationException(String message, Throwable cause, Response.Status status) | ||
throws IllegalArgumentException { | ||
super(message, cause, status); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...mmon/runtime/src/main/java/org/jboss/resteasy/reactive/ResteasyReactiveClientProblem.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,10 @@ | ||
package org.jboss.resteasy.reactive; | ||
|
||
/** | ||
* Marker interface that is used to indicate that an exception was generated by the client. | ||
* | ||
* This stops the server treating it as a WebApplicationException, so that client errors are not | ||
* interpreted as server responses. | ||
*/ | ||
public interface ResteasyReactiveClientProblem { | ||
} |
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