diff options
author | Pavel Paroulek <pavel.paroulek@orange.com> | 2018-10-24 23:49:57 +0200 |
---|---|---|
committer | Pavel Paroulek <pavel.paroulek@orange.com> | 2018-10-24 23:49:57 +0200 |
commit | 35d58583ad3caaa5b87d1edfc895bc7b97e555e3 (patch) | |
tree | 5f4554f824afcdf4596ba57c6207be0dab1593ac | |
parent | 8a5357874f1826b35f51330fb143c64cbbc24178 (diff) |
Changing formatting of error response.
Response object can be modified only once.
Change-Id: I753b01ca6e8bfd63c09a4d91f76216341a865160
Issue-ID: AAI-32
Signed-off-by: Pavel Paroulek <pavel.paroulek@orange.com>
3 files changed, 5 insertions, 7 deletions
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(); } } |