Skip to content

Commit 624a8e4

Browse files
authoredSep 6, 2024
Update Core V3 API to support RFC7807 formatted errors (problems) (#5124)
* Start work on supporting rfc7807 errors in REST API v3 * Completed the separation of exception mappers for the different APIs (core v3, core v2, ccompat) * Switch from Error to ProblemDetails in Core v3 API + update all tests * updated the UI to support the new problem format * Code formatting
1 parent 43f19d5 commit 624a8e4

File tree

82 files changed

+1162
-807
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1162
-807
lines changed
 

‎app/src/main/java/io/apicurio/registry/metrics/health/liveness/LivenessUtil.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package io.apicurio.registry.metrics.health.liveness;
22

33
import io.apicurio.common.apps.config.Info;
4-
import io.apicurio.registry.services.http.RegistryExceptionMapperService;
4+
import io.apicurio.registry.services.http.HttpStatusCodeMap;
55
import jakarta.enterprise.context.ApplicationScoped;
66
import jakarta.inject.Inject;
77
import org.eclipse.microprofile.config.inject.ConfigProperty;
88
import org.slf4j.Logger;
99

1010
import java.util.List;
1111
import java.util.Optional;
12-
import java.util.Set;
1312

1413
@ApplicationScoped
1514
public class LivenessUtil {
1615

1716
@Inject
1817
Logger log;
1918

19+
@Inject
20+
HttpStatusCodeMap codeMap;
21+
2022
@Inject
2123
@ConfigProperty(name = "apicurio.liveness.errors.ignored")
2224
@Info(category = "health", description = "Ignored liveness errors", availableSince = "1.2.3.Final")
@@ -31,8 +33,7 @@ public boolean isIgnoreError(Throwable ex) {
3133
}
3234

3335
private boolean isIgnored(Throwable ex) {
34-
Set<Class<? extends Exception>> ignoredClasses = RegistryExceptionMapperService.getIgnored();
35-
if (ignoredClasses.contains(ex.getClass())) {
36+
if (codeMap.isIgnored(ex.getClass())) {
3637
return true;
3738
}
3839
return this.ignored.isPresent() && this.ignored.get().contains(ex.getClass().getName());
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package io.apicurio.registry.rest;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
53
import io.apicurio.registry.services.DisabledApisMatcherService;
6-
import io.apicurio.registry.services.http.ErrorHttpResponse;
7-
import io.apicurio.registry.services.http.RegistryExceptionMapperService;
84
import jakarta.enterprise.context.ApplicationScoped;
95
import jakarta.inject.Inject;
10-
import jakarta.servlet.*;
6+
import jakarta.servlet.Filter;
7+
import jakarta.servlet.FilterChain;
8+
import jakarta.servlet.ServletException;
9+
import jakarta.servlet.ServletRequest;
10+
import jakarta.servlet.ServletResponse;
1111
import jakarta.servlet.http.HttpServletRequest;
1212
import jakarta.servlet.http.HttpServletResponse;
13-
import jakarta.ws.rs.core.MediaType;
14-
import org.slf4j.Logger;
1513

1614
import java.io.IOException;
1715

@@ -24,18 +22,9 @@
2422
*/
2523
@ApplicationScoped
2624
public class RegistryApplicationServletFilter implements Filter {
27-
28-
private ObjectMapper mapper;
29-
30-
@Inject
31-
Logger log;
32-
3325
@Inject
3426
DisabledApisMatcherService disabledApisMatcherService;
3527

36-
@Inject
37-
RegistryExceptionMapperService exceptionMapper;
38-
3928
/**
4029
* @see jakarta.servlet.Filter#doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse,
4130
* jakarta.servlet.FilterChain)
@@ -62,23 +51,4 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
6251
chain.doFilter(request, response);
6352
}
6453

65-
private void mapException(ServletResponse response, Throwable throwable) throws IOException {
66-
67-
ErrorHttpResponse res = exceptionMapper.mapException(throwable);
68-
HttpServletResponse httpResponse = (HttpServletResponse) response;
69-
httpResponse.reset();
70-
httpResponse.setStatus(res.getStatus());
71-
httpResponse.setContentType(MediaType.APPLICATION_JSON);
72-
73-
getMapper().writeValue(httpResponse.getOutputStream(), res.getError());
74-
}
75-
76-
private synchronized ObjectMapper getMapper() {
77-
if (mapper == null) {
78-
mapper = new ObjectMapper();
79-
mapper.setSerializationInclusion(Include.NON_NULL);
80-
}
81-
return mapper;
82-
}
83-
8454
}

0 commit comments

Comments
 (0)