1、项目名称改为galaxy,并将项目代码中有关gk的目录改为galaxy;
2、接口返回参数中添加追踪状态码traceCode,用于查看服务处理日志,方便调试与定故障定位; 3、添加项目调试模式(isDebug参数),调用maat通用接口时,调式携带提交内容,生产过程为空;
This commit is contained in:
@@ -41,6 +41,7 @@ public class ServicesRequestLog implements Serializable {
|
||||
private Integer businessCode;
|
||||
private String exceptionInfo;
|
||||
private String serverIp;
|
||||
private String traceCode;
|
||||
|
||||
/**
|
||||
* serverIp
|
||||
@@ -216,5 +217,11 @@ public class ServicesRequestLog implements Serializable {
|
||||
public void setExceptionInfo(String exceptionInfo) {
|
||||
this.exceptionInfo = exceptionInfo;
|
||||
}
|
||||
public String getTraceCode() {
|
||||
return traceCode;
|
||||
}
|
||||
public void setTraceCode(String traceCode) {
|
||||
this.traceCode = traceCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class DefaultRestErrorConverter implements RestConverter<Map> {
|
||||
errorMap.put(RestConstants.REST_SERVICE_REASON, re.getBusinessCode()
|
||||
.getErrorReason());
|
||||
errorMap.put(RestConstants.REST_SERVICE_MSG, re.getMsg());
|
||||
errorMap.put(RestConstants.TRACE_CODE, re.getTraceCode());
|
||||
errorMap.put(RestConstants.REST_SERVICE_URI, re.getFromUri());
|
||||
|
||||
if(re.getActiveSys() != null){
|
||||
@@ -32,7 +33,7 @@ public class DefaultRestErrorConverter implements RestConverter<Map> {
|
||||
if(re.getLogSource() != null){
|
||||
errorMap.put(RestConstants.REST_SERVICE_LOG_SOURCE, re.getLogSource());
|
||||
}
|
||||
|
||||
|
||||
return errorMap;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ public class DefaultRestErrorResolver implements RestErrorResolver,InitializingB
|
||||
}else {
|
||||
error.setFromUri("unknow url");
|
||||
}
|
||||
error.setTraceCode(((RestServiceException) ex).getTraceCode());
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,9 @@ public class DefaultRestSuccessConverter implements RestConverter<Map> {
|
||||
successMap.put(RestConstants.REST_SERVICE_REASON, re.getBusinessCode()
|
||||
.getErrorReason());
|
||||
successMap.put(RestConstants.REST_SERVICE_MSG, re.getMsg());
|
||||
successMap.put(RestConstants.TRACE_CODE, re.getTraceCode());
|
||||
successMap.put(RestConstants.REST_SERVICE_URI, re.getFromUri());
|
||||
|
||||
|
||||
return successMap;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ public class RestConstants {
|
||||
|
||||
public static final String REST_SERVICE_LOG_SOURCE = "logSource";
|
||||
|
||||
public static final String TRACE_CODE = "traceCode";
|
||||
|
||||
//暂时4个
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,11 +50,16 @@ public class RestResult {
|
||||
*/
|
||||
private String logSource;
|
||||
|
||||
/**
|
||||
* 追踪状态码
|
||||
*/
|
||||
private String traceCode;
|
||||
|
||||
public RestResult(){
|
||||
|
||||
}
|
||||
|
||||
public RestResult(HttpStatus status, RestBusinessCode businessCode, String msg,String fromUri,String activeSys,String fromSign) {
|
||||
public RestResult(HttpStatus status, RestBusinessCode businessCode, String msg,String fromUri,String activeSys,String fromSign,String traceCode) {
|
||||
super();
|
||||
this.status = status;
|
||||
this.businessCode = businessCode;
|
||||
@@ -62,6 +67,7 @@ public class RestResult {
|
||||
this.fromUri = fromUri;
|
||||
this.activeSys=activeSys;
|
||||
this.logSource=logSource;
|
||||
this.traceCode=traceCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +158,14 @@ public class RestResult {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getTraceCode() {
|
||||
return traceCode;
|
||||
}
|
||||
|
||||
public void setTraceCode(String traceCode) {
|
||||
this.traceCode = traceCode;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new StringBuilder().append("HttpStatus:").append(getStatus().value())
|
||||
.append(" errorcode:")
|
||||
|
||||
@@ -12,6 +12,7 @@ public class RestServiceException extends RuntimeException{
|
||||
|
||||
private String activeSys;
|
||||
|
||||
private String traceCode;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -29,6 +30,7 @@ public class RestServiceException extends RuntimeException{
|
||||
public RestServiceException(SaveRequestLogThread thread,long time,String message) {
|
||||
super(message);
|
||||
this.errorCode = 998; //未知错误
|
||||
this.traceCode = thread.getTraceCode();
|
||||
thread.setConsumerTime(time);
|
||||
thread.setBusinessCode(this.getErrorCode());
|
||||
if(StringUtils.isEmpty(thread.getExceptionInfo()))
|
||||
@@ -43,6 +45,7 @@ public class RestServiceException extends RuntimeException{
|
||||
public RestServiceException(SaveRequestLogThread thread,long time,String message,int errorCode) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
this.traceCode = thread.getTraceCode();
|
||||
thread.setConsumerTime(time);
|
||||
thread.setBusinessCode(this.getErrorCode());
|
||||
if(StringUtils.isEmpty(thread.getExceptionInfo()))
|
||||
@@ -71,6 +74,13 @@ public class RestServiceException extends RuntimeException{
|
||||
public void setActiveSys(String activeSys) {
|
||||
this.activeSys = activeSys;
|
||||
}
|
||||
|
||||
|
||||
public String getTraceCode() {
|
||||
return traceCode;
|
||||
}
|
||||
|
||||
public void setTraceCode(String traceCode) {
|
||||
this.traceCode = traceCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class SwaggerConfig {
|
||||
"V1.0",
|
||||
"doufenghu@iie.ac.cn",
|
||||
"My Apps API Licence Type",
|
||||
"http://127.0.0.1:8080/gk/swagger/");
|
||||
"http://127.0.0.1:8080/galaxy/swagger/");
|
||||
return apiInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +143,11 @@ public final class Constants {
|
||||
* 是否开启业务校验
|
||||
*/
|
||||
public static final boolean SERVICE_VALIDATE = Configurations.getBooleanProperty("serviceValidate", true);
|
||||
|
||||
/**
|
||||
* 是否开启Debug模式
|
||||
*/
|
||||
public static final boolean IS_DEBUG = Configurations.getBooleanProperty("isDebug", true);
|
||||
/**
|
||||
* 日志本地存储时间
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package com.nis.web.controller;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -42,7 +43,7 @@ import com.nis.web.service.ServicesRequestLogService;
|
||||
*/
|
||||
public class BaseRestController {
|
||||
protected final Logger logger = Logger.getLogger(this.getClass());
|
||||
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHssSSS");
|
||||
/**
|
||||
*
|
||||
* @Title: serviceResponse
|
||||
@@ -81,6 +82,7 @@ public class BaseRestController {
|
||||
}
|
||||
restResult.setFromUri(request.getRequestURI());
|
||||
restResult.setMsg(msg);
|
||||
restResult.setTraceCode(thread.getTraceCode());
|
||||
thread.setConsumerTime(time);
|
||||
thread.setBusinessCode(restResult.getBusinessCode().getValue());
|
||||
new Thread(thread).start();
|
||||
@@ -127,6 +129,7 @@ public class BaseRestController {
|
||||
restResult.setFromUri(request.getRequestURI());
|
||||
restResult.setData(data);
|
||||
restResult.setMsg(msg);
|
||||
restResult.setTraceCode(thread.getTraceCode());
|
||||
thread.setConsumerTime(time);
|
||||
thread.setBusinessCode(restResult.getBusinessCode().getValue());
|
||||
new Thread(thread).start();
|
||||
@@ -208,6 +211,7 @@ public class BaseRestController {
|
||||
restResult.setFromUri(request.getRequestURI());
|
||||
restResult.setData(data);
|
||||
restResult.setMsg(msg);
|
||||
restResult.setTraceCode(thread.getTraceCode());
|
||||
thread.setConsumerTime(time);
|
||||
thread.setExceptionInfo(msg);
|
||||
thread.setBusinessCode(restResult.getBusinessCode().getValue());
|
||||
@@ -238,6 +242,7 @@ public class BaseRestController {
|
||||
restResult.setMsg(msg);
|
||||
restResult.setActiveSys(activeSys);
|
||||
restResult.setLogSource(logSource);
|
||||
restResult.setTraceCode(thread.getTraceCode());
|
||||
thread.setConsumerTime(time);
|
||||
thread.setBusinessCode(restResult.getBusinessCode().getValue());
|
||||
new Thread(thread).start();
|
||||
@@ -257,6 +262,7 @@ public class BaseRestController {
|
||||
if (re.getLogSource() != null) {
|
||||
successMap.put(RestConstants.REST_SERVICE_LOG_SOURCE, re.getLogSource());
|
||||
}
|
||||
successMap.put(RestConstants.TRACE_CODE, re.getTraceCode());
|
||||
successMap.put(RestConstants.REST_SERVICE_DATA, re.getData());
|
||||
logger.info("结果集处理结束----" + System.currentTimeMillis());
|
||||
return successMap;
|
||||
@@ -352,6 +358,7 @@ public class BaseRestController {
|
||||
SaveRequestLogThread thread = SaveRequestLogThread.getNewSaveRequestLogThread(request);
|
||||
thread.setService(service);
|
||||
thread.setOpAction(opAction);
|
||||
thread.setTraceCode(sdf.format(new Date())+(Math.round((Math.random()*9+1)*10000)+""));
|
||||
if (data != null && ConfigCommonSource.class.isAssignableFrom(data.getClass())) {
|
||||
ConfigCommonSource source = (ConfigCommonSource) data;
|
||||
thread.setOperator(source.getOperator());
|
||||
|
||||
@@ -118,7 +118,7 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
}
|
||||
|
||||
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
|
||||
"编译配置数据插入成功" + sb.toString(), configSource);
|
||||
"编译配置数据插入成功" + sb.toString(), Constants.IS_DEBUG?configSource:null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.PUT)
|
||||
@@ -183,7 +183,7 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
|
||||
"编译配置修改成功" + sb.toString(), configSource);
|
||||
"编译配置修改成功" + sb.toString(), Constants.IS_DEBUG?configSource:null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/configModifySources", method = RequestMethod.PUT)
|
||||
@@ -303,7 +303,7 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
}
|
||||
|
||||
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
|
||||
"修改编译配置数据成功" + sb.toString(), configSource);
|
||||
"修改编译配置数据成功" + sb.toString(), Constants.IS_DEBUG?configSource:null);
|
||||
}
|
||||
|
||||
private void validateConfigSource(SaveRequestLogThread thread, long start, ConfigSource configSource) {
|
||||
|
||||
@@ -318,7 +318,7 @@ public class ConfigTestController extends BaseRestController {
|
||||
System.out.println(id);
|
||||
try {
|
||||
// String url =
|
||||
// "http://127.0.0.1:8888/gk/service/cfg/v1/configSources";
|
||||
// "http://127.0.0.1:8888/galaxy/service/cfg/v1/configSources";
|
||||
String url = Configurations.getStringProperty("httpUrl", "");
|
||||
ConfigSourceTest configSource = new ConfigSourceTest();
|
||||
configSource.setOpTime(new Date());
|
||||
@@ -392,7 +392,7 @@ public class ConfigTestController extends BaseRestController {
|
||||
JsonConfig jsonConfig = new JsonConfig();
|
||||
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
|
||||
// String url =
|
||||
// "http://127.0.0.1:8888/gk/service/cfg/v1/configSources";
|
||||
// "http://127.0.0.1:8888/galaxy/service/cfg/v1/configSources";
|
||||
String url = Configurations.getStringProperty("httpUrl", "");
|
||||
JSONArray jsonArray = JSONArray.fromObject(configSource, jsonConfig);
|
||||
String jsonStr = jsonArray.getString(0);
|
||||
@@ -533,7 +533,7 @@ public class ConfigTestController extends BaseRestController {
|
||||
String result = "";
|
||||
try {
|
||||
String urlNameString = url + "?" + param;
|
||||
urlNameString = "http://127.0.0.1:8888/gk/service/log/v1/dfStatLogDailySources?pageNo=1&pageSize=2";
|
||||
urlNameString = "http://127.0.0.1:8888/galaxy/service/log/v1/dfStatLogDailySources?pageNo=1&pageSize=2";
|
||||
URL realUrl = new URL(urlNameString);
|
||||
// 打开和URL之间的连接
|
||||
URLConnection conn = realUrl.openConnection();
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
<result column="BUSINESS_CODE" jdbcType="INTEGER" property="businessCode" />
|
||||
<result column="EXCEPTION_INFO" jdbcType="VARCHAR" property="exceptionInfo" />
|
||||
<result column="SERVER_IP" jdbcType="VARCHAR" property="serverIp" />
|
||||
<result column="TRACE_CODE" jdbcType="VARCHAR" property="traceCode" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
ID, OPERATOR, VERSION, OPACTION,OPTIME, REQUEST_CONTENT,
|
||||
REQUEST_TIME,REQUEST_IP,
|
||||
CONSUMER_TIME,BUSINESS_CODE,EXCEPTION_INFO,SERVER_IP
|
||||
CONSUMER_TIME,BUSINESS_CODE,EXCEPTION_INFO,SERVER_IP,TRACE_CODE
|
||||
</sql>
|
||||
<select id="getAllLog" parameterType="com.nis.domain.restful.ServicesRequestLogBean"
|
||||
resultMap="ServicesRequestLogMap">
|
||||
@@ -123,6 +124,9 @@
|
||||
<if test="serverIp != null">
|
||||
SERVER_IP,
|
||||
</if>
|
||||
<if test="traceCode != null">
|
||||
TRACE_CODE,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
SEQ_SERVICES_REQUEST_LOG.Nextval,
|
||||
@@ -159,6 +163,9 @@
|
||||
<if test="serverIp != null">
|
||||
#{serverIp,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="traceCode != null">
|
||||
#{traceCode,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -41,6 +41,7 @@ public class SaveRequestLogThread implements Runnable {
|
||||
private long consumerTime;
|
||||
private int businessCode;
|
||||
private String exceptionInfo;
|
||||
private String traceCode;
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@@ -52,7 +53,7 @@ public class SaveRequestLogThread implements Runnable {
|
||||
CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_C);//开启数据源C
|
||||
// TODO Auto-generated method stub
|
||||
if(service!=null){
|
||||
service.saveRequestLog(remoteAddr,requestURI,queryString,contextPath, operator, version, opAction, opTime, content, requestTime, consumerTime,businessCode,exceptionInfo);
|
||||
service.saveRequestLog(remoteAddr,requestURI,queryString,contextPath, operator, version, opAction, opTime, content, requestTime, consumerTime,businessCode,exceptionInfo,traceCode);
|
||||
}else{
|
||||
logger.error("service 为空!");
|
||||
}
|
||||
@@ -362,4 +363,11 @@ public class SaveRequestLogThread implements Runnable {
|
||||
public void setExceptionInfo(String exceptionInfo) {
|
||||
this.exceptionInfo = exceptionInfo;
|
||||
}
|
||||
public String getTraceCode() {
|
||||
return traceCode;
|
||||
}
|
||||
public void setTraceCode(String traceCode) {
|
||||
this.traceCode = traceCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ServicesRequestLogService {
|
||||
*/
|
||||
public void saveRequestLog(String requestAddr, String requestURI, String queryString, String contextPath,
|
||||
String operator, String version, int opAction, Date opTime, Object content, Date requestTime,
|
||||
long consumerTime, int businessCode, String exceptionInfo) {
|
||||
long consumerTime, int businessCode, String exceptionInfo,String traceCode) {
|
||||
logger.info("开始记录日志---");
|
||||
logger.info("请求IP---" + requestAddr);
|
||||
logger.info("请求路径---" + requestURI);
|
||||
@@ -107,6 +107,7 @@ public class ServicesRequestLogService {
|
||||
log.setConsumerTime(consumerTime);
|
||||
log.setBusinessCode(businessCode);
|
||||
log.setExceptionInfo(exceptionInfo);
|
||||
log.setTraceCode(traceCode);
|
||||
try {
|
||||
if(Constants.SERVCER_HOST!=null){
|
||||
log.setServerIp(Constants.SERVCER_HOST);
|
||||
|
||||
Reference in New Issue
Block a user