Skip to content

Commit 149d77b

Browse files
committed
Move response to a separate property.
1 parent b7ca5bb commit 149d77b

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/api/WebClientApplicationException.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,43 @@
2020
import org.jboss.resteasy.reactive.common.jaxrs.StatusTypeImpl;
2121

2222
/**
23-
* Subclass of {@link WebApplicationException} for use by clients.
23+
* Subclass of {@link WebApplicationException} for use by clients, which forbids setting a response that
24+
* would be used by the server.
25+
* FIXME: I'd rather this be disjoint from WebApplicationException, but changing the exception type could break existing
26+
* clients catching this exception.
2427
*/
2528
@SuppressWarnings("serial")
2629
public class WebClientApplicationException extends WebApplicationException implements ResteasyReactiveClientProblem {
2730

31+
/**
32+
* The response received by the client after making the request.
33+
* Saved in an alternate field to prevent it from being used by the server.
34+
*/
35+
private final transient Response clientResponse;
36+
2837
public WebClientApplicationException(int responseStatus) {
2938
this(responseStatus, (String) null);
3039
}
3140

3241
public WebClientApplicationException(int responseStatus, String responseReasonPhrase) {
3342
super("Server response is: " + responseStatus, null, new DummyResponse(responseStatus, responseReasonPhrase));
43+
this.clientResponse = getResponse();
44+
}
45+
46+
public WebClientApplicationException(Response clientResponse) {
47+
super("Server response is: " + clientResponse.getStatus(), new DummyResponse(clientResponse.getStatus(),
48+
clientResponse.getStatusInfo().getReasonPhrase()));
49+
this.clientResponse = clientResponse;
3450
}
3551

36-
public WebClientApplicationException(int responseStatus, Response response) {
37-
super("Server response is: " + responseStatus, response);
52+
public WebClientApplicationException(Throwable cause, Response clientResponse) {
53+
super("Server response is: " + clientResponse.getStatus(), cause, new DummyResponse(clientResponse.getStatus(),
54+
clientResponse.getStatusInfo().getReasonPhrase()));
55+
this.clientResponse = clientResponse;
3856
}
3957

40-
public WebClientApplicationException(int responseStatus, Throwable cause, Response response) {
41-
super("Server response is: " + responseStatus, cause, response);
58+
public Response getClientResponse() {
59+
return clientResponse;
4260
}
4361

4462
/**

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSetResponseEntityRestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void handle(RestClientRequestContext context) throws Exception {
2929
StatusType effectiveResponseStatus = determineEffectiveResponseStatus(context, requestContext);
3030
if (Response.Status.Family.familyOf(effectiveResponseStatus.getStatusCode()) != Response.Status.Family.SUCCESSFUL) {
3131
Response response = ClientResponseCompleteRestHandler.mapToResponse(context, effectiveResponseStatus, true);
32-
throw new WebClientApplicationException(effectiveResponseStatus.getStatusCode(), response);
32+
throw new WebClientApplicationException(response);
3333
}
3434
}
3535

independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/RestClientRequestContext.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.jboss.resteasy.reactive.ClientWebApplicationException;
3232
import org.jboss.resteasy.reactive.RestResponse;
3333
import org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties;
34+
import org.jboss.resteasy.reactive.client.api.WebClientApplicationException;
3435
import org.jboss.resteasy.reactive.client.impl.multipart.QuarkusMultipartForm;
3536
import org.jboss.resteasy.reactive.client.spi.ClientRestHandler;
3637
import org.jboss.resteasy.reactive.client.spi.MultipartResponseData;
@@ -199,10 +200,12 @@ protected Throwable unwrapException(Throwable t) {
199200
+ invokedMethod.getDeclaringClass().getName() + "#"
200201
+ invokedMethod.getName() + "'";
201202
}
203+
Response response = webApplicationException instanceof WebClientApplicationException wcae ? wcae.getClientResponse()
204+
: webApplicationException.getResponse();
202205
return new ClientWebApplicationException(message,
203206
webApplicationException instanceof ClientWebApplicationException ? webApplicationException.getCause()
204207
: webApplicationException,
205-
webApplicationException.getResponse());
208+
response);
206209
}
207210
return res;
208211
}

0 commit comments

Comments
 (0)