From 446b98ea7a29e82aff1f0f9a7b4dd241185a6395 Mon Sep 17 00:00:00 2001 From: tanghc Date: Thu, 29 Oct 2020 11:24:01 +0800 Subject: [PATCH 1/3] 4.0.3 --- doc/docs/files/10089_自定义校验token.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/docs/files/10089_自定义校验token.md b/doc/docs/files/10089_自定义校验token.md index c4840eba..c1c17901 100644 --- a/doc/docs/files/10089_自定义校验token.md +++ b/doc/docs/files/10089_自定义校验token.md @@ -29,7 +29,6 @@ public StoryResult token(StoryParam story, HttpServletRequest request) { 自己实现步骤: -- 在ZuulConfig类中重写`doAfter`方法 - 设置`ApiConfig中的tokenValidator属性` `TokenValidator`是一个函数式接口,可以直接使用Lambda表达式,示例代码如下: From 5e906bc4bae6093f5cd1d63f2818f56d00c252a6 Mon Sep 17 00:00:00 2001 From: tanghc Date: Thu, 29 Oct 2020 11:31:57 +0800 Subject: [PATCH 2/3] 4.0.3 --- doc/docs/files/10089_自定义校验token.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/docs/files/10089_自定义校验token.md b/doc/docs/files/10089_自定义校验token.md index c1c17901..6716ec55 100644 --- a/doc/docs/files/10089_自定义校验token.md +++ b/doc/docs/files/10089_自定义校验token.md @@ -46,7 +46,7 @@ public class MyConfig { // TODO: 校验token有效性,可以从redis中读取 // 返回true表示这个token真实、有效 -}); + }); } } ``` From 3cef44dc9624eae72d78c54fb291e5512df8e229 Mon Sep 17 00:00:00 2001 From: tanghc Date: Thu, 29 Oct 2020 14:06:20 +0800 Subject: [PATCH 3/3] 4.0.3 --- .../com/gitee/sop/gatewaycommon/bean/SopConstants.java | 2 ++ .../gateway/handler/GatewayExceptionHandler.java | 5 ++++- .../gatewaycommon/gateway/route/GatewayForwardChooser.java | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java index c6d56b4c..7af00f96 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java @@ -56,4 +56,6 @@ public class SopConstants { public static final String METADATA_KEY_TIME_STARTUP = "server.startup-time"; + public static final String CACHE_ROUTE_INFO = "cacheRouteInfo"; + } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java index 0f623358..4c992a9c 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java @@ -1,6 +1,8 @@ package com.gitee.sop.gatewaycommon.gateway.handler; import com.gitee.sop.gatewaycommon.bean.ApiContext; +import com.gitee.sop.gatewaycommon.bean.SopConstants; +import com.gitee.sop.gatewaycommon.bean.TargetRoute; import com.gitee.sop.gatewaycommon.gateway.ServerWebExchangeUtil; import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.result.ResultExecutor; @@ -55,7 +57,8 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler { String errorResult = resultExecutor.buildErrorResult(exchange, ex); ApiParam apiParam = ServerWebExchangeUtil.getApiParam(exchange); // 错误记录 - log.error("gateway网关报错,params:{}, errorMsg:{}", apiParam, ex.getMessage(), ex); + Object routeDefinition = exchange.getAttribute(SopConstants.CACHE_ROUTE_INFO); + log.error("网关报错,参数:{}, 错误信息:{}, 路由信息:{}", apiParam, ex.getMessage(), routeDefinition, ex); // 参考AbstractErrorWebExceptionHandler if (exchange.getResponse().isCommitted()) { return Mono.error(ex); diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java index bb9b474d..85ced0da 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayForwardChooser.java @@ -1,5 +1,7 @@ package com.gitee.sop.gatewaycommon.gateway.route; +import com.gitee.sop.gatewaycommon.bean.SopConstants; +import com.gitee.sop.gatewaycommon.bean.TargetRoute; import com.gitee.sop.gatewaycommon.gateway.ServerWebExchangeUtil; import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.route.BaseForwardChooser; @@ -22,6 +24,9 @@ public class GatewayForwardChooser extends BaseForwardChooser if (ServerWebExchangeUtil.getThrowable(exchange) != null) { return ForwardInfo.getErrorForwardInfo(); } - return super.getForwardInfo(exchange); + ForwardInfo forwardInfo = super.getForwardInfo(exchange); + TargetRoute targetRoute = forwardInfo.getTargetRoute(); + exchange.getAttributes().put(SopConstants.CACHE_ROUTE_INFO, targetRoute.getRouteDefinition()); + return forwardInfo; } }