summaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2022-10-05 09:55:45 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2022-10-05 09:55:45 +0200
commite632cf8afa27bdedf8b2044c430cd604ab7d4987 (patch)
tree85cf35932109fd858e09f4bf1a0a5d0724057697 /aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
parent20ea11d8067c57fe47d9bdc64663b8cc8a5742ca (diff)
Run the formatter for the traversal service
When building the traversal service with mvn install, the spotless and formatter plugins are invoked to verify the formatting. This results in 40000 lines of format violations that are printed out to the console. By invoking mvn formatter:format spotless:apply process-sources this number can be reduced to 2000 lines of format violations. Issue-ID: AAI-3543 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> Change-Id: Id0011b3e0a626369c79fd0656cd44455347b7fde
Diffstat (limited to 'aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java')
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java140
1 files changed, 69 insertions, 71 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java b/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
index 452815e..d6d2f5e 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/ExceptionHandler.java
@@ -8,7 +8,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,6 +19,10 @@
*/
package org.onap.aai.rest;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.sun.istack.SAXParseException2;
+
import java.util.ArrayList;
import java.util.List;
@@ -33,9 +37,6 @@ import javax.ws.rs.ext.Provider;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.logging.ErrorLogHelper;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.sun.istack.SAXParseException2;
/**
* The Class ExceptionHandler.
@@ -43,84 +44,81 @@ import com.sun.istack.SAXParseException2;
@Provider
public class ExceptionHandler implements ExceptionMapper<Exception> {
- private static final String AAI_4007 = "AAI_4007";
+ private static final String AAI_4007 = "AAI_4007";
@Context
private HttpServletRequest request;
-
+
@Context
private HttpHeaders headers;
-
+
@Override
public Response toResponse(Exception exception) {
- Response response = null;
- ArrayList<String> templateVars = new ArrayList<>();
+ Response response = null;
+ ArrayList<String> templateVars = new ArrayList<>();
- //the general case is that cxf will give us a WebApplicationException
- //with a linked exception
- if (exception instanceof WebApplicationException) {
- WebApplicationException e = (WebApplicationException) exception;
- if (e.getCause() instanceof SAXParseException2) {
- templateVars.add("UnmarshalException");
- AAIException ex = new AAIException(AAI_4007, exception);
- response = Response
- .status(400)
- .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
- .build();
+ // the general case is that cxf will give us a WebApplicationException
+ // with a linked exception
+ if (exception instanceof WebApplicationException) {
+ WebApplicationException e = (WebApplicationException) exception;
+ if (e.getCause() instanceof SAXParseException2) {
+ templateVars.add("UnmarshalException");
+ AAIException ex = new AAIException(AAI_4007, exception);
+ response = Response.status(400).entity(ErrorLogHelper
+ .getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
+ .build();
- }
- } else if (exception instanceof JsonParseException) {
- //jackson does it differently so we get the direct JsonParseException
- templateVars.add("JsonParseException");
- AAIException ex = new AAIException(AAI_4007, exception);
- response = Response
- .status(400)
- .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
- .build();
+ }
+ } else if (exception instanceof JsonParseException) {
+ // jackson does it differently so we get the direct JsonParseException
+ templateVars.add("JsonParseException");
+ AAIException ex = new AAIException(AAI_4007, exception);
+ response = Response
+ .status(400).entity(ErrorLogHelper
+ .getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
+ .build();
} else if (exception instanceof JsonMappingException) {
- //jackson does it differently so we get the direct JsonParseException
- templateVars.add("JsonMappingException");
- AAIException ex = new AAIException(AAI_4007, exception);
- response = Response
- .status(400)
- .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
- .build();
- }
-
- // it didn't get set above, we wrap a general fault here
- if (response == null) {
-
- Exception actual_e = exception;
- if (exception instanceof WebApplicationException) {
- WebApplicationException e = (WebApplicationException) exception;
- response = e.getResponse();
- } else {
- templateVars.add(request.getMethod());
- templateVars.add("unknown");
- AAIException ex = new AAIException("AAI_4000", actual_e);
- List<MediaType> mediaTypes = headers.getAcceptableMediaTypes();
- int setError = 0;
+ // jackson does it differently so we get the direct JsonParseException
+ templateVars.add("JsonMappingException");
+ AAIException ex = new AAIException(AAI_4007, exception);
+ response = Response
+ .status(400).entity(ErrorLogHelper
+ .getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
+ .build();
+ }
+
+ // it didn't get set above, we wrap a general fault here
+ if (response == null) {
+
+ Exception actual_e = exception;
+ if (exception instanceof WebApplicationException) {
+ WebApplicationException e = (WebApplicationException) exception;
+ response = e.getResponse();
+ } else {
+ templateVars.add(request.getMethod());
+ templateVars.add("unknown");
+ AAIException ex = new AAIException("AAI_4000", actual_e);
+ List<MediaType> mediaTypes = headers.getAcceptableMediaTypes();
+ int setError = 0;
- for (MediaType mediaType : mediaTypes) {
- if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)) {
- response = Response
- .status(400)
- .type(MediaType.APPLICATION_XML_TYPE)
- .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
- .build();
- setError = 1;
- }
- }
- if (setError == 0) {
- response = Response
- .status(400)
- .type(MediaType.APPLICATION_JSON_TYPE)
- .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
- .build();
- }
- }
- }
- return response;
+ for (MediaType mediaType : mediaTypes) {
+ if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)) {
+ response = Response.status(400).type(MediaType.APPLICATION_XML_TYPE)
+ .entity(ErrorLogHelper.getRESTAPIErrorResponse(
+ headers.getAcceptableMediaTypes(), ex, templateVars))
+ .build();
+ setError = 1;
+ }
+ }
+ if (setError == 0) {
+ response = Response.status(400).type(MediaType.APPLICATION_JSON_TYPE)
+ .entity(ErrorLogHelper.getRESTAPIErrorResponse(
+ headers.getAcceptableMediaTypes(), ex, templateVars))
+ .build();
+ }
+ }
+ }
+ return response;
}
}