diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/AuthException.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/AuthException.java new file mode 100644 index 0000000..7e64b69 --- /dev/null +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/AuthException.java @@ -0,0 +1,66 @@ +/** + * AuthException.java + * Created at 2016-03-01 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.core.exception; + +/** + *
+ * ClassName: AuthException + *
+ *+ * Description: 认证异常 + *
+ *+ * Author: wangkang + *
+ *+ * Date: 2016年3月23日 + *
+ */ +public class AuthException extends RuntimeException { + + /** + *+ * Field serialVersionUID: 序列号 + *
+ */ + private static final long serialVersionUID = 1L; + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + */ + public AuthException(String message) { + super(message); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param cause 堆栈 + */ + public AuthException(Throwable cause) { + super(cause); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + * @param cause 堆栈 + */ + public AuthException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorCode.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorCode.java new file mode 100644 index 0000000..b10157b --- /dev/null +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorCode.java @@ -0,0 +1,69 @@ +/** + * ErrorCode.java + * Created at 2016-09-27 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.core.exception; + +/** + * 描述 : 错误代码枚举 + * + * @author wangkang + * + */ +public enum ErrorCode { + /** + * 描述 : 系统内部错误 + */ + ERROR("system internal error"), + /** + * 描述 : http服务错误 + */ + HTTP_SERVER_ERROR("http server error"), + /** + * 描述 : 参数校验错误 + */ + PARAMETER_VALID_ERROR("parameter check error"), + /** + * 描述 : 资源不存在 + */ + NO_RESOURCE_FOUND("resource does not exist"), + /** + * 描述 : 认证错误 + */ + AUTH_ERROR("auth error"), + /** + * 描述 : 权限错误 + */ + PERMISSION_ERROR("Permission error"); + + /** + *+ * Field value: 参数值 + *
+ */ + private String value = null; + + /** + *+ * Description: 构造函数 + *
+ * + * @param value 构造函数 + */ + private ErrorCode(String value) { + this.value = value; + } + + /** + *+ * Description: 放回int值 + *
+ * + * @return value 放回int值 + */ + public String value() { + return this.value; + } +} diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorMessage.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorMessage.java new file mode 100644 index 0000000..5215b65 --- /dev/null +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/ErrorMessage.java @@ -0,0 +1,277 @@ +/** + * ErrorMessage.java + * Created at 2016-09-27 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.core.exception; + +import java.io.Serializable; +import java.util.Date; + +/** + * 描述 : 错误信息 + * + * @author wangkang + * + */ +public class ErrorMessage implements Serializable { + /** + * 描述 : id + */ + private static final long serialVersionUID = 1L; + + /** + * 描述 : 错误ID + */ + private String id; + + /** + * 描述 : http状态 + */ + private int httpStatus; + + /** + * 描述 : 错误代码 + */ + private String errorCode; + + /** + * 描述 : 错误描述 + */ + private String errorMsg; + + /** + * 描述 : 错误发生时间 + */ + private Date errorDate; + + /** + * 描述 : 异常类名 + */ + private String exceptionType; + + /** + * 描述 : 异常信息 + */ + private String exceptionMessage; + + /** + * 描述 : 详细异常堆栈信息 + */ + private String exceptionStackTrace; + + /** + * 描述 : 资源部不在错误信息 + */ + private NoResourceFoundMessage noResourceFoundMessage; + + /** + * 描述 : 参数校验错误信息 + */ + private ParameterValidErrorMessage parameterValidErrorMessage; + + /** + * 描述 : http服务错误 + */ + private HttpServerErrorMessage httpServerErrorMessage; + + /** + * 描述 : 获取httpServerErrorMessage + * + * @return the httpServerErrorMessage + */ + public HttpServerErrorMessage getHttpServerErrorMessage() { + return httpServerErrorMessage; + } + + /** + * 描述 : 设置httpServerErrorMessage + * + * @param httpServerErrorMessage the httpServerErrorMessage to set + */ + public void setHttpServerErrorMessage(HttpServerErrorMessage httpServerErrorMessage) { + this.httpServerErrorMessage = httpServerErrorMessage; + } + + /** + * 描述 : 获取noResourceFoundMessage + * + * @return the noResourceFoundMessage + */ + public NoResourceFoundMessage getNoResourceFoundMessage() { + return noResourceFoundMessage; + } + + /** + * 描述 : 设置noResourceFoundMessage + * + * @param noResourceFoundMessage the noResourceFoundMessage to set + */ + public void setNoResourceFoundMessage(NoResourceFoundMessage noResourceFoundMessage) { + this.noResourceFoundMessage = noResourceFoundMessage; + } + + /** + * 描述 : 获取parameterValidErrorMessage + * + * @return the parameterValidErrorMessage + */ + public ParameterValidErrorMessage getParameterValidErrorMessage() { + return parameterValidErrorMessage; + } + + /** + * 描述 : 设置parameterValidErrorMessage + * + * @param parameterValidErrorMessage the parameterValidErrorMessage to set + */ + public void setParameterValidErrorMessage(ParameterValidErrorMessage parameterValidErrorMessage) { + this.parameterValidErrorMessage = parameterValidErrorMessage; + } + + /** + * 描述 : 获取id + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * 描述 : 设置id + * + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * 描述 : 获取errorDate + * + * @return the errorDate + */ + public Date getErrorDate() { + return errorDate; + } + + /** + * 描述 : 设置errorDate + * + * @param errorDate the errorDate to set + */ + public void setErrorDate(Date errorDate) { + this.errorDate = errorDate; + } + + /** + * 描述 : 获取httpStatus + * + * @return the httpStatus + */ + public int getHttpStatus() { + return httpStatus; + } + + /** + * 描述 : 设置httpStatus + * + * @param httpStatus the httpStatus to set + */ + public void setHttpStatus(int httpStatus) { + this.httpStatus = httpStatus; + } + + /** + * 描述 : 获取errorCode + * + * @return the errorCode + */ + public String getErrorCode() { + return errorCode; + } + + /** + * 描述 : 设置errorCode + * + * @param errorCode the errorCode to set + */ + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + /** + * 描述 : 获取errorMsg + * + * @return the errorMsg + */ + public String getErrorMsg() { + return errorMsg; + } + + /** + * 描述 : 设置errorMsg + * + * @param errorMsg the errorMsg to set + */ + public void setErrorMsg(String errorMsg) { + this.errorMsg = errorMsg; + } + + /** + * 描述 : 获取exceptionType + * + * @return the exceptionType + */ + public String getExceptionType() { + return exceptionType; + } + + /** + * 描述 : 设置exceptionType + * + * @param exceptionType the exceptionType to set + */ + public void setExceptionType(String exceptionType) { + this.exceptionType = exceptionType; + } + + /** + * 描述 : 获取exceptionMessage + * + * @return the exceptionMessage + */ + public String getExceptionMessage() { + return exceptionMessage; + } + + /** + * 描述 : 设置exceptionMessage + * + * @param exceptionMessage the exceptionMessage to set + */ + public void setExceptionMessage(String exceptionMessage) { + this.exceptionMessage = exceptionMessage; + } + + /** + * 描述 : 获取exceptionStackTrace + * + * @return the exceptionStackTrace + */ + public String getExceptionStackTrace() { + return exceptionStackTrace; + } + + /** + * 描述 : 设置exceptionStackTrace + * + * @param exceptionStackTrace the exceptionStackTrace to set + */ + public void setExceptionStackTrace(String exceptionStackTrace) { + this.exceptionStackTrace = exceptionStackTrace; + } + +} diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/HttpServerErrorMessage.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/HttpServerErrorMessage.java new file mode 100644 index 0000000..fa960d9 --- /dev/null +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/HttpServerErrorMessage.java @@ -0,0 +1,183 @@ +/** + * HttpServerErrorMessage.java + * Created at 2016-11-05 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.core.exception; + +import java.io.IOException; +import java.io.Serializable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.web.client.HttpServerErrorException; + +import com.egridcloud.udf.core.RestResponse; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * 描述 : HttpServerErrorMessage + * + * @author wangkang + * + */ +public class HttpServerErrorMessage implements Serializable { + + /** + * 描述 : 日志 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(HttpServerErrorMessage.class); + + /** + * 描述 : ID + */ + private static final long serialVersionUID = 1L; + + /** + * 描述 : rawStatusCode + */ + private int rawStatusCode; + + /** + * 描述 : statusText + */ + private String statusText; + + /** + * 描述 : responseBody + */ + private RestResponse+ * ClassName: PermissionException + *
+ *+ * Description: 权限异常 + *
+ *+ * Author: wangkang + *
+ *+ * Date: 2016年3月23日 + *
+ */ +public class PermissionException extends RuntimeException { + + /** + *+ * Field serialVersionUID: 序列号 + *
+ */ + private static final long serialVersionUID = 1L; + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + */ + public PermissionException(String message) { + super(message); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param cause 堆栈 + */ + public PermissionException(Throwable cause) { + super(cause); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + * @param cause 堆栈 + */ + public PermissionException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/SystemException.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/SystemException.java new file mode 100644 index 0000000..8172119 --- /dev/null +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/SystemException.java @@ -0,0 +1,64 @@ +/** + * SystemException.java + * Created at 2016-03-01 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.core.exception; + +/** + *+ * ClassName: SystemException + *
+ *+ * Description: 系统异常 + *
+ *+ * Author: wangkang + *
+ *+ * Date: 2016年3月23日 + *
+ */ +public class SystemException extends Exception { + + /** + * 描述 : id + */ + private static final long serialVersionUID = 1L; + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + */ + public SystemException(String message) { + super(message); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param cause 堆栈 + */ + public SystemException(Throwable cause) { + super(cause); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + * @param cause 堆栈 + */ + public SystemException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/SystemRuntimeException.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/SystemRuntimeException.java new file mode 100644 index 0000000..951d824 --- /dev/null +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/SystemRuntimeException.java @@ -0,0 +1,66 @@ +/** + * SystemRuntimeException.java + * Created at 2016-03-01 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.core.exception; + +/** + *+ * ClassName: SystemRuntimeException + *
+ *+ * Description: 系统运行时异常 + *
+ *+ * Author: wangkang + *
+ *+ * Date: 2016年3月23日 + *
+ */ +public class SystemRuntimeException extends RuntimeException { + + /** + *+ * Field serialVersionUID: 序列号 + *
+ */ + private static final long serialVersionUID = 1L; + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + */ + public SystemRuntimeException(String message) { + super(message); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param cause 堆栈 + */ + public SystemRuntimeException(Throwable cause) { + super(cause); + } + + /** + *+ * Description: 构造函数 + *
+ * + * @param message 异常信息 + * @param cause 堆栈 + */ + public SystemRuntimeException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/handle/ExceptionMapping.java b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/handle/ExceptionMapping.java new file mode 100644 index 0000000..cfead5a --- /dev/null +++ b/udf-starter-core/src/main/java/com/egridcloud/udf/core/exception/handle/ExceptionMapping.java @@ -0,0 +1,272 @@ +/** + * ExceptionMapping.java + * Created at 2016-09-20 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.core.exception.handle; + +import java.util.Date; +import java.util.UUID; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.servlet.NoHandlerFoundException; + +import com.egridcloud.udf.core.ApplicationConfig; +import com.egridcloud.udf.core.RestResponse; +import com.egridcloud.udf.core.exception.AuthException; +import com.egridcloud.udf.core.exception.ErrorCode; +import com.egridcloud.udf.core.exception.ErrorMessage; +import com.egridcloud.udf.core.exception.HttpServerErrorMessage; +import com.egridcloud.udf.core.exception.NoResourceFoundMessage; +import com.egridcloud.udf.core.exception.ParameterValidErrorMessage; +import com.egridcloud.udf.core.exception.ParameterValidException; +import com.egridcloud.udf.core.exception.PermissionException; +import com.egridcloud.udf.core.exception.SystemException; +import com.egridcloud.udf.core.exception.SystemRuntimeException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * 描述 : 全局异常处理 + * + * @author wangkang + * + */ +@ControllerAdvice +public class ExceptionMapping { + + /** + * 描述 : 日志 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionMapping.class); + + /** + * 描述 : 系统配置 + */ + @Autowired + private ApplicationConfig applicationConfig; + + /** + * 描述 : json解析器 + */ + @Autowired + private ObjectMapper xssObjectMapper; + + /** + * 描述 : 构造函数 + * + */ + public ExceptionMapping() { + LOGGER.info("ExceptionMapping initialize"); + } + + /** + * 描述 : 捕获PermissionException异常(权限异常) + * + * @param permissionException 异常 + * @return 错误信息 + */ + @ExceptionHandler(value = PermissionException.class) + @ResponseStatus(HttpStatus.FORBIDDEN) + @ResponseBody + public RestResponse