Skip to content

Commit

Permalink
Bypass ProblemClientResponseFilter on MicroProfile REST Client (#109)
Browse files Browse the repository at this point in the history
Fixes #31.

Bypass ProblemClientResponseFilter on MicroProfile REST Client (by
checking for

[org.eclipse.microprofile.rest.client.invokedMethod](https://download.eclipse.org/microprofile/microprofile-rest-client-4.0/microprofile-rest-client-spec-4.0.html#_clientrequestfilter)
property), so the MicroProfile-specific ProblemResponseExceptionMapper
can be used instead.
  • Loading branch information
jpraet authored Sep 30, 2024
1 parent ff4b0c8 commit 07a6e28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public ProblemClientResponseFilter(ObjectMapper objectMapper) {

@Override
public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException {
if (request.getProperty("org.eclipse.microprofile.rest.client.invokedMethod") != null) {
// Use io.github.belgif.rest.problem.jaxrs.client.ProblemResponseExceptionMapper on MicroProfile REST Client
return;
}
if (ProblemMediaType.INSTANCE.isCompatible(response.getMediaType()) || (response.getStatus() >= 400
&& MediaType.APPLICATION_JSON_TYPE.isCompatible(response.getMediaType()))) {
Problem problem = objectMapper.readValue(response.getEntityStream(), Problem.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.nio.charset.StandardCharsets;

Expand Down Expand Up @@ -97,4 +98,13 @@ void differentMediaType() {
() -> filter.filter(requestContext, responseContext));
}

@Test
void microProfile() {
when(requestContext.getProperty("org.eclipse.microprofile.rest.client.invokedMethod"))
.thenReturn(mock(Method.class));
assertThatNoException().isThrownBy(
() -> filter.filter(requestContext, responseContext));
verifyNoMoreInteractions(requestContext, responseContext);
}

}

0 comments on commit 07a6e28

Please sign in to comment.