mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
新增监控日志
This commit is contained in:
@@ -41,6 +41,9 @@ public class ZuulConfig extends AlipayZuulConfiguration {
|
||||
//public class ZuulConfig extends EasyopenZuulConfiguration {
|
||||
// static {
|
||||
// new ManagerInitializer();
|
||||
// Map<String, String> appSecretMap = new HashMap<>();
|
||||
// appSecretMap.put("easyopen_test", "G9w0BAQEFAAOCAQ8AMIIBCgKCA");
|
||||
// ApiConfig.getInstance().addAppSecret(appSecretMap);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@@ -0,0 +1,68 @@
|
||||
package com.gitee.sop.gateway.controller;
|
||||
|
||||
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
|
||||
import com.gitee.sop.gatewaycommon.bean.ErrorEntity;
|
||||
import com.gitee.sop.gatewaycommon.manager.ServiceErrorManager;
|
||||
import com.gitee.sop.gatewaycommon.param.ApiParam;
|
||||
import com.gitee.sop.gatewaycommon.result.ApiResult;
|
||||
import com.gitee.sop.gatewaycommon.result.JsonResult;
|
||||
import com.gitee.sop.gatewaycommon.util.RequestUtil;
|
||||
import com.gitee.sop.gatewaycommon.validate.taobao.TaobaoSigner;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class ErrorLogController {
|
||||
|
||||
TaobaoSigner signer = new TaobaoSigner();
|
||||
|
||||
@Value("${zuul.secret}")
|
||||
private String secret;
|
||||
|
||||
@GetMapping("listErrors")
|
||||
public ApiResult listErrors(HttpServletRequest request) {
|
||||
try {
|
||||
this.check(request);
|
||||
ServiceErrorManager serviceErrorManager = ApiConfig.getInstance().getServiceErrorManager();
|
||||
Collection<ErrorEntity> allErrors = serviceErrorManager.listAllErrors();
|
||||
JsonResult apiResult = new JsonResult();
|
||||
apiResult.setData(allErrors);
|
||||
return apiResult;
|
||||
} catch (Exception e) {
|
||||
ApiResult apiResult = new ApiResult();
|
||||
apiResult.setCode("505050");
|
||||
apiResult.setMsg(e.getMessage());
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("clearErrors")
|
||||
public ApiResult clearErrors(HttpServletRequest request) {
|
||||
try {
|
||||
this.check(request);
|
||||
ServiceErrorManager serviceErrorManager = ApiConfig.getInstance().getServiceErrorManager();
|
||||
serviceErrorManager.clear();
|
||||
return new ApiResult();
|
||||
} catch (Exception e) {
|
||||
ApiResult apiResult = new ApiResult();
|
||||
apiResult.setCode("505050");
|
||||
apiResult.setMsg(e.getMessage());
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
|
||||
private void check(HttpServletRequest request) {
|
||||
Map<String, String> params = RequestUtil.convertRequestParamsToMap(request);
|
||||
ApiParam apiParam = ApiParam.build(params);
|
||||
signer.checkSign(apiParam, secret);
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.gitee.sop.gateway;
|
||||
package com.gitee.sop.gateway.controller;
|
||||
|
||||
import com.gitee.sop.gatewaycommon.bean.SopConstants;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
@@ -11,6 +11,8 @@ zuul:
|
||||
Servlet30WrapperFilter:
|
||||
pre:
|
||||
disable: true
|
||||
# 不用改,如果要改,建议全局替换修改
|
||||
secret: MZZOUSTua6LzApIWXCwEgbBmxSzpzC
|
||||
|
||||
# 注册中心,根据实际情况修改
|
||||
eureka:
|
||||
|
Reference in New Issue
Block a user