From 13594159659f7f7590ac2244d20019836fcc7ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Sat, 20 Jul 2024 17:34:03 +0800 Subject: [PATCH] upgrade(core bom): springboot 3.3.2 &spring cloud 2023.0.3 - springboot 3.3.2 - spring cloud 2023.0.3 - spring cloud alibaba 2023.0.1.2 - spring boot admin 3.3.2 - hutool 5.8.29 (cherry picked from commit ba8fc7e8d3cfc15725db50e161e8db17d267df89) --- .../PigxSentinelAutoConfiguration.java | 4 +-- .../sentinel/handle/PigxUrlBlockHandler.java | 31 ++++++++++++------- .../parser/PigxHeaderRequestOriginParser.java | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java index 5913648e5..78555134b 100755 --- a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java +++ b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/PigxSentinelAutoConfiguration.java @@ -18,8 +18,8 @@ package com.pig4cloud.pigx.common.sentinel; import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; -import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler; -import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser; +import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.BlockExceptionHandler; +import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.RequestOriginParser; import com.pig4cloud.pigx.common.sentinel.feign.PigxSentinelFeign; import com.pig4cloud.pigx.common.sentinel.handle.GlobalBizExceptionHandler; import com.pig4cloud.pigx.common.sentinel.handle.PigxUrlBlockHandler; diff --git a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/PigxUrlBlockHandler.java b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/PigxUrlBlockHandler.java index 26b75a97a..15287b8ef 100644 --- a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/PigxUrlBlockHandler.java +++ b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/PigxUrlBlockHandler.java @@ -18,14 +18,13 @@ package com.pig4cloud.pigx.common.sentinel.handle; import cn.hutool.json.JSONUtil; -import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler; +import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.BlockExceptionHandler; import com.alibaba.csp.sentinel.slots.block.BlockException; import com.pig4cloud.pigx.common.core.util.R; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; - import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; /** * @author lengleng @@ -36,12 +35,20 @@ import jakarta.servlet.http.HttpServletResponse; @Slf4j public class PigxUrlBlockHandler implements BlockExceptionHandler { - @Override - public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception { - log.error("sentinel 降级 资源名称{}", e.getRule().getResource(), e); - response.setContentType("application/json"); - response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value()); - response.getWriter().print(JSONUtil.toJsonStr(R.failed(e.getMessage()))); - } - + /** + * Handle the request when blocked. + * + * @param request Servlet request + * @param response Servlet response + * @param resourceName resource name + * @param e the block exception + * @throws Exception users may throw out the BlockException or other error occurs + */ + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, String resourceName, BlockException e) throws Exception { + log.error("sentinel 降级 资源名称{}", resourceName, e); + response.setContentType("application/json"); + response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value()); + response.getWriter().print(JSONUtil.toJsonStr(R.failed(e.getMessage()))); + } } diff --git a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/parser/PigxHeaderRequestOriginParser.java b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/parser/PigxHeaderRequestOriginParser.java index a661d79a9..c31f7c2da 100644 --- a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/parser/PigxHeaderRequestOriginParser.java +++ b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/parser/PigxHeaderRequestOriginParser.java @@ -17,8 +17,8 @@ package com.pig4cloud.pigx.common.sentinel.parser; -import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser; +import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.RequestOriginParser; import jakarta.servlet.http.HttpServletRequest; /**