Skip to content

Commit 07a6e28

Browse files
authored
Bypass ProblemClientResponseFilter on MicroProfile REST Client (#109)
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.
1 parent ff4b0c8 commit 07a6e28

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

belgif-rest-problem-java-ee/src/main/java/io/github/belgif/rest/problem/jaxrs/client/ProblemClientResponseFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public ProblemClientResponseFilter(ObjectMapper objectMapper) {
4242

4343
@Override
4444
public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException {
45+
if (request.getProperty("org.eclipse.microprofile.rest.client.invokedMethod") != null) {
46+
// Use io.github.belgif.rest.problem.jaxrs.client.ProblemResponseExceptionMapper on MicroProfile REST Client
47+
return;
48+
}
4549
if (ProblemMediaType.INSTANCE.isCompatible(response.getMediaType()) || (response.getStatus() >= 400
4650
&& MediaType.APPLICATION_JSON_TYPE.isCompatible(response.getMediaType()))) {
4751
Problem problem = objectMapper.readValue(response.getEntityStream(), Problem.class);

belgif-rest-problem-java-ee/src/test/java/io/github/belgif/rest/problem/jaxrs/client/ProblemClientResponseFilterTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.ByteArrayInputStream;
77
import java.io.InputStream;
8+
import java.lang.reflect.Method;
89
import java.net.URI;
910
import java.nio.charset.StandardCharsets;
1011

@@ -97,4 +98,13 @@ void differentMediaType() {
9798
() -> filter.filter(requestContext, responseContext));
9899
}
99100

101+
@Test
102+
void microProfile() {
103+
when(requestContext.getProperty("org.eclipse.microprofile.rest.client.invokedMethod"))
104+
.thenReturn(mock(Method.class));
105+
assertThatNoException().isThrownBy(
106+
() -> filter.filter(requestContext, responseContext));
107+
verifyNoMoreInteractions(requestContext, responseContext);
108+
}
109+
100110
}

0 commit comments

Comments
 (0)