From 35d58583ad3caaa5b87d1edfc895bc7b97e555e3 Mon Sep 17 00:00:00 2001 From: Pavel Paroulek Date: Wed, 24 Oct 2018 23:49:57 +0200 Subject: Changing formatting of error response. Response object can be modified only once. Change-Id: I753b01ca6e8bfd63c09a4d91f76216341a865160 Issue-ID: AAI-32 Signed-off-by: Pavel Paroulek --- .../main/java/org/onap/aai/config/aaf/AafAuthorizationFilter.java | 4 +--- aai-resources/src/main/java/org/onap/aai/config/aaf/AafFilter.java | 2 +- .../src/main/java/org/onap/aai/config/aaf/ResponseFormatter.java | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'aai-resources/src/main') diff --git a/aai-resources/src/main/java/org/onap/aai/config/aaf/AafAuthorizationFilter.java b/aai-resources/src/main/java/org/onap/aai/config/aaf/AafAuthorizationFilter.java index 653fc51..2162e9b 100644 --- a/aai-resources/src/main/java/org/onap/aai/config/aaf/AafAuthorizationFilter.java +++ b/aai-resources/src/main/java/org/onap/aai/config/aaf/AafAuthorizationFilter.java @@ -32,8 +32,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import static org.onap.aai.config.aaf.ResponseFormatter.errorResponse; - /** * AAF authorization filter */ @@ -60,7 +58,7 @@ public class AafAuthorizationFilter extends OrderedRequestContextFilter { filterChain.doFilter(request, response); } if(!request.isUserInRole(permission)){ - errorResponse(request, response); + response.setStatus(403); }else{ filterChain.doFilter(request,response); } diff --git a/aai-resources/src/main/java/org/onap/aai/config/aaf/AafFilter.java b/aai-resources/src/main/java/org/onap/aai/config/aaf/AafFilter.java index f1aa7c1..08d9475 100644 --- a/aai-resources/src/main/java/org/onap/aai/config/aaf/AafFilter.java +++ b/aai-resources/src/main/java/org/onap/aai/config/aaf/AafFilter.java @@ -57,7 +57,7 @@ public class AafFilter extends OrderedRequestContextFilter { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { if(!request.getRequestURI().matches("^.*/util/echo$")){ cadiFilter.doFilter(request, response, filterChain); - if(response.getStatus() >=400 && response.getStatus() < 500){ + if(response.getStatus() == 401 && response.getStatus() == 403){ errorResponse(request, response); } } else { diff --git a/aai-resources/src/main/java/org/onap/aai/config/aaf/ResponseFormatter.java b/aai-resources/src/main/java/org/onap/aai/config/aaf/ResponseFormatter.java index 9e09827..ca09730 100644 --- a/aai-resources/src/main/java/org/onap/aai/config/aaf/ResponseFormatter.java +++ b/aai-resources/src/main/java/org/onap/aai/config/aaf/ResponseFormatter.java @@ -37,9 +37,9 @@ class ResponseFormatter { String accept = request.getHeader(ACCEPT_HEADER) == null ? MediaType.APPLICATION_XML : request.getHeader(ACCEPT_HEADER); AAIException aaie = new AAIException("AAI_3300"); response.setStatus(aaie.getErrorObject().getHTTPResponseCode().getStatusCode()); - response.getWriter().write(ErrorLogHelper.getRESTAPIErrorResponse(Collections.singletonList(MediaType.valueOf(accept)), aaie, new ArrayList<>())); - response.getWriter().flush(); - response.getWriter().close(); + response.resetBuffer(); + response.getOutputStream().print(ErrorLogHelper.getRESTAPIErrorResponse(Collections.singletonList(MediaType.valueOf(accept)), aaie, new ArrayList<>())); + response.flushBuffer(); } } -- cgit 1.2.3-korg