Replaced all tabs with spaces in java and pom.xml
[so.git] / mso-api-handlers / mso-api-handler-common / src / main / java / org / onap / so / apihandlerinfra / exceptions / ApiExceptionMapper.java
index 4c069d5..3b97763 100644 (file)
@@ -27,7 +27,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
-
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -37,15 +36,11 @@ import javax.ws.rs.ext.Provider;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
-
-
 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
 import org.onap.so.logger.ErrorCode;
 import org.onap.so.logger.MessageEnum;
-
 import org.onap.so.serviceinstancebeans.RequestError;
 import org.onap.so.serviceinstancebeans.ServiceException;
-
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -58,7 +53,7 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> {
 
     private static Logger logger = LoggerFactory.getLogger(ApiExceptionMapper.class);
 
-    
+
     private final JAXBContext context;
     private final Marshaller marshaller;
 
@@ -66,14 +61,15 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> {
     private HttpHeaders headers;
 
     public ApiExceptionMapper() {
-       try {
-                       context = JAXBContext.newInstance(RequestError.class);
-               marshaller = context.createMarshaller();
-               } catch (JAXBException e) {
-                       logger.debug("could not create JAXB marshaller");
-                       throw new IllegalStateException(e);
-               }
+        try {
+            context = JAXBContext.newInstance(RequestError.class);
+            marshaller = context.createMarshaller();
+        } catch (JAXBException e) {
+            logger.debug("could not create JAXB marshaller");
+            throw new IllegalStateException(e);
+        }
     }
+
     @Override
     public Response toResponse(ApiException exception) {
 
@@ -93,23 +89,24 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> {
         }
 
 
-        
+
         List<MediaType> typeList = Optional.ofNullable(headers.getAcceptableMediaTypes()).orElse(new ArrayList<>());
         List<String> typeListString = typeList.stream().map(item -> item.toString()).collect(Collectors.toList());
         MediaType type;
         if (typeListString.stream().anyMatch(item -> item.contains(MediaType.APPLICATION_XML))) {
-               type = MediaType.APPLICATION_XML_TYPE;
+            type = MediaType.APPLICATION_XML_TYPE;
         } else if (typeListString.stream().anyMatch(item -> typeListString.contains(MediaType.APPLICATION_JSON))) {
-               type = MediaType.APPLICATION_JSON_TYPE;
+            type = MediaType.APPLICATION_JSON_TYPE;
         } else {
-               type = MediaType.APPLICATION_JSON_TYPE;
+            type = MediaType.APPLICATION_JSON_TYPE;
         }
 
-        return buildServiceErrorResponse(errorText,messageId,variables, type);
+        return buildServiceErrorResponse(errorText, messageId, variables, type);
 
     }
 
-    protected String buildServiceErrorResponse(String errorText, String messageId, List<String> variables, MediaType type){
+    protected String buildServiceErrorResponse(String errorText, String messageId, List<String> variables,
+            MediaType type) {
         RequestError re = new RequestError();
         ServiceException se = new ServiceException();
         se.setMessageId(messageId);
@@ -123,21 +120,22 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> {
         String requestErrorStr;
 
         ObjectMapper mapper = createObjectMapper();
-       
+
         mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
         mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
         try {
-               if (MediaType.APPLICATION_JSON_TYPE.equals(type)) {
-                       requestErrorStr = mapper.writeValueAsString(re);
+            if (MediaType.APPLICATION_JSON_TYPE.equals(type)) {
+                requestErrorStr = mapper.writeValueAsString(re);
             } else {
-               StringWriter sw = new StringWriter();
-               this.getMarshaller().marshal(re, sw);
-               requestErrorStr = sw.toString();
+                StringWriter sw = new StringWriter();
+                this.getMarshaller().marshal(re, sw);
+                requestErrorStr = sw.toString();
             }
         } catch (JsonProcessingException | JAXBException e) {
-            String errorMsg = "Exception in buildServiceErrorResponse writing exceptionType to string " + e.getMessage();
+            String errorMsg =
+                    "Exception in buildServiceErrorResponse writing exceptionType to string " + e.getMessage();
             logger.error("{} {} {} {}", MessageEnum.GENERAL_EXCEPTION.toString(), "BuildServiceErrorResponse",
-                ErrorCode.DataError.getValue(), errorMsg, e);
+                    ErrorCode.DataError.getValue(), errorMsg, e);
             return errorMsg;
         }
 
@@ -145,19 +143,21 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> {
     }
 
     protected void writeErrorLog(Exception e, String errorText, ErrorLoggerInfo errorLogInfo) {
-        if( e!= null)
+        if (e != null)
             logger.error("Exception occurred", e);
-        if(errorLogInfo != null)
-            logger.error(errorLogInfo.getLoggerMessageType().toString(), errorLogInfo.getErrorSource(), errorLogInfo.getTargetEntity(), errorLogInfo.getTargetServiceName(), errorLogInfo.getErrorCode(), errorText);
-  
+        if (errorLogInfo != null)
+            logger.error(errorLogInfo.getLoggerMessageType().toString(), errorLogInfo.getErrorSource(),
+                    errorLogInfo.getTargetEntity(), errorLogInfo.getTargetServiceName(), errorLogInfo.getErrorCode(),
+                    errorText);
+
     }
 
-    public ObjectMapper createObjectMapper(){
+    public ObjectMapper createObjectMapper() {
         return new ObjectMapper();
     }
-    
+
     public Marshaller getMarshaller() {
-       return marshaller;
+        return marshaller;
     }
-    
+
 }