diff options
author | Samuel Liard <samuel.liard@gmail.com> | 2021-07-19 17:42:22 +0200 |
---|---|---|
committer | Samuel Liard <samuel.liard@gmail.com> | 2021-07-19 17:42:22 +0200 |
commit | e623f779e146050c5b6824906b98e6eac59b6eb5 (patch) | |
tree | c69d2bbb5a3f8a14a7f5af237cdc1c6578e79bec /aai-aaf-auth/src | |
parent | 03e4a9c48f9fe3ce7ed2ff2d7808eb7e62cbc573 (diff) |
Fix one critical sonar issues
Issue-ID: AAI-3345
Signed-off-by: sliard <samuel.liard@gmail.com>
Change-Id: I6b647d56178686093aa1b652cd55e05a92ba501a
Diffstat (limited to 'aai-aaf-auth/src')
-rw-r--r-- | aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/ResponseFormatter.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/ResponseFormatter.java b/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/ResponseFormatter.java index d7c88e81..f5583b71 100644 --- a/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/ResponseFormatter.java +++ b/aai-aaf-auth/src/main/java/org/onap/aai/aaf/auth/ResponseFormatter.java @@ -33,6 +33,11 @@ import java.util.Collections; public class ResponseFormatter { private static final String ACCEPT_HEADER = "accept"; + private static final String CONTENT_TYPE_HEADER = "Content-Type"; + + private ResponseFormatter() { + throw new IllegalStateException("Utility class"); + } public static void errorResponse(HttpServletRequest request, HttpServletResponse response) throws IOException { errorResponse(new AAIException("AAI_3300"), request, response); @@ -44,10 +49,17 @@ public class ResponseFormatter { return; } - String accept = request.getHeader(ACCEPT_HEADER) == null ? MediaType.APPLICATION_XML : request.getHeader(ACCEPT_HEADER); + String accept = request.getHeader(ACCEPT_HEADER); + switch (accept != null ? accept : MediaType.APPLICATION_XML) { + case MediaType.APPLICATION_JSON: + response.setHeader(CONTENT_TYPE_HEADER, MediaType.APPLICATION_JSON); + break; + case MediaType.APPLICATION_XML: + default: + response.setHeader(CONTENT_TYPE_HEADER, MediaType.APPLICATION_XML); + } response.setStatus(exception.getErrorObject().getHTTPResponseCode().getStatusCode()); - response.setHeader("Content-Type", accept); response.resetBuffer(); String resp = ErrorLogHelper.getRESTAPIErrorResponse(Collections.singletonList(MediaType.valueOf(accept)), exception, new ArrayList<>()); |