mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-11-14 22:49:33 +08:00
⚡ 适配新版api
This commit is contained in:
parent
72f0fd4ca4
commit
f1372114e0
@ -16,7 +16,7 @@
|
|||||||
package org.springblade.core.cloud.config;
|
package org.springblade.core.cloud.config;
|
||||||
|
|
||||||
import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
|
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_v6x.callback.BlockExceptionHandler;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import org.springblade.core.cloud.feign.BladeFeignSentinel;
|
import org.springblade.core.cloud.feign.BladeFeignSentinel;
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
package org.springblade.core.cloud.config;
|
package org.springblade.core.cloud.config;
|
||||||
|
|
||||||
import com.alibaba.cloud.sentinel.SentinelProperties;
|
import com.alibaba.cloud.sentinel.SentinelProperties;
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.SentinelWebInterceptor;
|
||||||
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.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.DefaultBlockExceptionHandler;
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.RequestOriginParser;
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.config.SentinelWebMvcConfig;
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig;
|
import com.alibaba.csp.sentinel.adapter.web.common.UrlCleaner;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -56,7 +56,7 @@ public class BladeSentinelFilterConfiguration {
|
|||||||
} else {
|
} else {
|
||||||
if (StringUtils.hasText(properties.getBlockPage())) {
|
if (StringUtils.hasText(properties.getBlockPage())) {
|
||||||
sentinelWebMvcConfig.setBlockExceptionHandler(
|
sentinelWebMvcConfig.setBlockExceptionHandler(
|
||||||
((request, response, e) -> response.sendRedirect(properties.getBlockPage())));
|
((request, response, s, e) -> response.sendRedirect(properties.getBlockPage())));
|
||||||
} else {
|
} else {
|
||||||
sentinelWebMvcConfig.setBlockExceptionHandler(new DefaultBlockExceptionHandler());
|
sentinelWebMvcConfig.setBlockExceptionHandler(new DefaultBlockExceptionHandler());
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package org.springblade.core.cloud.sentinel;
|
package org.springblade.core.cloud.sentinel;
|
||||||
|
|
||||||
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.alibaba.csp.sentinel.slots.block.BlockException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.api.R;
|
||||||
import org.springblade.core.tool.jackson.JsonUtil;
|
import org.springblade.core.tool.jackson.JsonUtil;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sentinel统一限流策略
|
* Sentinel统一限流策略
|
||||||
*
|
*
|
||||||
@ -17,7 +16,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
*/
|
*/
|
||||||
public class BladeBlockExceptionHandler implements BlockExceptionHandler {
|
public class BladeBlockExceptionHandler implements BlockExceptionHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
|
public void handle(HttpServletRequest request, HttpServletResponse response, String s, BlockException e) throws Exception {
|
||||||
// Return 429 (Too Many Requests) by default.
|
// Return 429 (Too Many Requests) by default.
|
||||||
response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value());
|
response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value());
|
||||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
Loading…
Reference in New Issue
Block a user