From b8e2faf476202b6ffe61bc3a9a37df1304881d40 Mon Sep 17 00:00:00 2001 From: Avi Ziv Date: Tue, 18 Jul 2017 19:45:38 +0300 Subject: [SDC] Onboarding 1710 rebase. Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535 Signed-off-by: Avi Ziv --- .../sdcrests/errors/DefaultExceptionMapper.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java index af77268599..e8a6c7e7db 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java @@ -22,8 +22,6 @@ package org.openecomp.sdcrests.errors; import org.codehaus.jackson.map.JsonMappingException; import org.hibernate.validator.internal.engine.path.PathImpl; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.json.JsonUtil; @@ -34,10 +32,10 @@ import org.openecomp.sdc.common.errors.ErrorCodeAndMessage; import org.openecomp.sdc.common.errors.GeneralErrorBuilder; import org.openecomp.sdc.common.errors.JsonMappingErrorBuilder; import org.openecomp.sdc.common.errors.ValidationErrorBuilder; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; -import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -50,8 +48,8 @@ import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; import javax.validation.Path; import javax.ws.rs.core.MediaType; -import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; public class DefaultExceptionMapper implements ExceptionMapper { private static final String ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE = @@ -78,8 +76,8 @@ public class DefaultExceptionMapper implements ExceptionMapper { try { writeStackTraceToFile(exception); - } catch (IOException e) { - e.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); } List contentTypes = new ArrayList<>(); contentTypes.add(MediaType.APPLICATION_JSON); @@ -174,15 +172,14 @@ public class DefaultExceptionMapper implements ExceptionMapper { private void writeStackTraceToFile(Exception exception) throws IOException { File file = new File("stack_trace.txt"); - OutputStream outputStream = new FileOutputStream(file); - - if(!file.exists()){ + if (!file.exists()) { file.createNewFile(); } - + OutputStream outputStream = new FileOutputStream(file); PrintWriter printWriter = new PrintWriter(file); exception.printStackTrace(printWriter); printWriter.close(); + outputStream.close(); } } -- cgit 1.2.3-korg