From 33fe8be432f025bb50fa79fa14888f835cbd2dee Mon Sep 17 00:00:00 2001 From: ParkSeongMin Date: Thu, 22 Oct 2015 02:03:44 +0000 Subject: [PATCH] =?UTF-8?q?=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D=20?= =?UTF-8?q?=EC=8B=9C=20nexacro=20platform=EC=9C=BC=EB=A1=9C=20stack=20trac?= =?UTF-8?q?e=20=EC=A0=84=EC=86=A1=EC=97=AC=EB=B6=80=20=EC=98=B5=EC=85=98?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/nexacro/spring/NexacroException.java | 55 +++++++++++++++--- ...a => NexacroMappingExceptionResolver.java} | 56 ++++++++++++++++--- .../NexacroMethodArgumentResolver.java | 4 +- 3 files changed, 95 insertions(+), 20 deletions(-) rename src/main/java/com/nexacro/spring/resolve/{NexcroMappingExceptionResolver.java => NexacroMappingExceptionResolver.java} (59%) diff --git a/src/main/java/com/nexacro/spring/NexacroException.java b/src/main/java/com/nexacro/spring/NexacroException.java index 05346a8..92da5a8 100644 --- a/src/main/java/com/nexacro/spring/NexacroException.java +++ b/src/main/java/com/nexacro/spring/NexacroException.java @@ -3,9 +3,8 @@ package com.nexacro.spring; /** * *

Nexacro 예외를 의미하는 Exception이다. + * 추가적으로 설정되는 에러코드(errorCode) 에러메시지(errorMsg)는 nexacro platform으로 전송되는 데이터이다. * - * @ClassName : NexacroException.java - * @Description : 클래스 설명을 기술합니다. * @author Park SeongMin * @since 2015. 7. 30. * @version 1.0 @@ -38,8 +37,7 @@ public class NexacroException extends Exception { /** * 메시지를 가지는 생성자이다. * - * @param message - * 메시지 + * @param message 메시지 */ public NexacroException(String message) { this(message, null); @@ -48,28 +46,67 @@ public class NexacroException extends Exception { /** * 메시지와 원천(cause) 예외를 가지는 생성자이다. * - * @param message - * 메시지 - * @param cause - * 원천 예외 + * @param message 메시지 + * @param cause 원천 예외 */ public NexacroException(String message, Throwable cause) { super(message, cause); - this.errorMsg = message; + } + + /** + * 메시지와 에러코드, 에러메시지를 가지는 생성자이다. + * + * @param message 메시지 + * @param errorCode 에러코드 + * @param errorMsg 에러메시지 + */ + public NexacroException(String message, int errorCode, String errorMsg) { + this(message, null, errorCode, errorMsg); + } + + /** + * 메시지와 원천(cause), 에러코드, 에러메시지 예외를 가지는 생성자이다. + * + * @param message 메시지 + * @param cause 원천 예외 + * @param errorCode 에러코드 + * @param errorMsg 에러메시지 + */ + public NexacroException(String message, Throwable cause, int errorCode, String errorMsg) { + super(message, cause); + setErrorCode(errorCode); + setErrorMsg(errorMsg); } + /** + * 설정 된 에러코드를 반환한다. + * @return errorCode + */ public int getErrorCode() { return errorCode; } + /** + * 에러코드를 설정한다. + * + * @param errorCode 에러코드 + */ public void setErrorCode(int errorCode) { this.errorCode = errorCode; } + /** + * 설정 된 에러메시지를 반환한다. + * @return errorMsg + */ public String getErrorMsg() { return errorMsg; } + /** + * 에러메시지를 설정한다. + * @param errorMsg 에러메시지 + */ public void setErrorMsg(String errorMsg) { this.errorMsg = errorMsg; } diff --git a/src/main/java/com/nexacro/spring/resolve/NexcroMappingExceptionResolver.java b/src/main/java/com/nexacro/spring/resolve/NexacroMappingExceptionResolver.java similarity index 59% rename from src/main/java/com/nexacro/spring/resolve/NexcroMappingExceptionResolver.java rename to src/main/java/com/nexacro/spring/resolve/NexacroMappingExceptionResolver.java index 2d7059b..f8a5214 100644 --- a/src/main/java/com/nexacro/spring/resolve/NexcroMappingExceptionResolver.java +++ b/src/main/java/com/nexacro/spring/resolve/NexacroMappingExceptionResolver.java @@ -14,9 +14,13 @@ import com.nexacro.spring.util.NexacroUtil; import com.nexacro.spring.view.NexacroModelAndView; import com.nexacro.spring.view.NexacroView; -public class NexcroMappingExceptionResolver extends AbstractHandlerExceptionResolver { +public class NexacroMappingExceptionResolver extends AbstractHandlerExceptionResolver { - private final Logger logger = LoggerFactory.getLogger(NexcroMappingExceptionResolver.class); + private final Logger logger = LoggerFactory.getLogger(NexacroMappingExceptionResolver.class); + + private String defaultErrorMsg = NexacroException.DEFAULT_MESSAGE; + private boolean shouldSendStackTrace = false; + private boolean shouldLogStackTrace = false; private View view; @@ -32,7 +36,19 @@ public class NexcroMappingExceptionResolver extends AbstractHandlerExceptionReso this.view = view; } - public NexcroMappingExceptionResolver() { + public void setDefaultErrorMsg(String defaultErrorMsg) { + this.defaultErrorMsg = defaultErrorMsg; + } + + public void setShouldSendStackTrace(boolean shouldSendStackTrace) { + this.shouldSendStackTrace = shouldSendStackTrace; + } + + public void setShouldLogStackTrace(boolean shouldLogStackTrace) { + this.shouldLogStackTrace = shouldLogStackTrace; + } + + public NexacroMappingExceptionResolver() { } @Override @@ -50,12 +66,12 @@ public class NexcroMappingExceptionResolver extends AbstractHandlerExceptionReso if(ex instanceof NexacroException){ // NexacroConvertException NexacroException nexaExp = (NexacroException) ex; mav.setErrorCode(nexaExp.getErrorCode()); - mav.setErrorMsg(nexaExp.getErrorMsg() != null? nexaExp.getErrorMsg(): nexaExp.toString()); + mav.setErrorMsg(getExceptionMessage(ex)); } else { // PlatformException.. mav.setErrorCode(NexacroException.DEFAULT_ERROR_CODE); //Undefined error Code // mav.setErrorMsg(NexacroException.DEFAULT_MESSAGE); - mav.setErrorMsg(ex.toString()); + mav.setErrorMsg(getExceptionMessage(ex)); } return mav; @@ -66,12 +82,34 @@ public class NexcroMappingExceptionResolver extends AbstractHandlerExceptionReso private void prepareResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { - if (this.logger.isDebugEnabled()) { - this.logger.debug("Resolving exception from handler [" + handler + "]: " + ex); - } - logException(ex, request); + + if(this.shouldLogStackTrace) { + logger.error(ex.getMessage(), ex); + } } + private String getExceptionMessage(Exception e) { + + if(this.shouldSendStackTrace) { + + String message = e.getMessage(); + + if(e instanceof NexacroException) { + String errorMsg = ((NexacroException) e).getErrorMsg(); + if(errorMsg != null) { + message = "errorMsg="+ errorMsg +", stackMessage=" +message; + } + } + + return message; + + } else { + return this.defaultErrorMsg; + } + + } + + } diff --git a/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java b/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java index cb9db55..e682cfb 100644 --- a/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java +++ b/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java @@ -239,7 +239,7 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol DataSet dataSet = nexacroCachedData.getPlatformData().getDataSet(dsName); if(dataSet == null) { if(logger.isDebugEnabled()) { - logger.debug(dsName + " is null."); + logger.debug("@ParamDataSet '" + dsName + "' argument is null."); } return null; } @@ -291,7 +291,7 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol Variable variable = nexacroCachedData.getPlatformData().getVariable(varName); if(variable == null) { if(logger.isDebugEnabled()) { - logger.debug(varName + " is null."); + logger.debug("@ParamVariable '" + varName + "' argument is null."); } return null; //throw new IllegalArgumentException("invalid @ParamVariable. ex)@ParamVariable(name=\"variableName\") Object var");