Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
spring-cloud-timeloit
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
loit-Infrastructure
spring-cloud-timeloit
Commits
a68e7168
提交
a68e7168
authored
8月 20, 2020
作者:
陈世营
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[修改]sentinel 自定义默认异常
上级
dd18ffee
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
50 行增加
和
8 行删除
+50
-8
SentinelWebAutoConfiguration.java
...timeloit/cloud/sentinel/SentinelWebAutoConfiguration.java
+11
-8
CustomBlockExceptionHandler.java
...loit/cloud/sentinel/loit/CustomBlockExceptionHandler.java
+29
-0
README.md
.../src/main/java/com/timeloit/cloud/sentinel/loit/README.md
+10
-0
没有找到文件。
spring-cloud-timeloit-sentinel/src/main/java/com/timeloit/cloud/sentinel/SentinelWebAutoConfiguration.java
浏览文件 @
a68e7168
...
@@ -16,17 +16,15 @@
...
@@ -16,17 +16,15 @@
package
com
.
timeloit
.
cloud
.
sentinel
;
package
com
.
timeloit
.
cloud
.
sentinel
;
import
java.util.Optional
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig
;
import
com.timeloit.cloud.sentinel.loit.CustomBlockExceptionHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
...
@@ -39,6 +37,8 @@ import org.springframework.util.StringUtils;
...
@@ -39,6 +37,8 @@ import org.springframework.util.StringUtils;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
java.util.Optional
;
/**
/**
* @author xiaojing
* @author xiaojing
* @author yuhuangbin
* @author yuhuangbin
...
@@ -68,6 +68,7 @@ public class SentinelWebAutoConfiguration implements WebMvcConfigurer {
...
@@ -68,6 +68,7 @@ public class SentinelWebAutoConfiguration implements WebMvcConfigurer {
@Autowired
@Autowired
private
Optional
<
SentinelWebInterceptor
>
sentinelWebInterceptorOptional
;
private
Optional
<
SentinelWebInterceptor
>
sentinelWebInterceptorOptional
;
@Override
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
if
(!
sentinelWebInterceptorOptional
.
isPresent
())
{
if
(!
sentinelWebInterceptorOptional
.
isPresent
())
{
...
@@ -100,15 +101,17 @@ public class SentinelWebAutoConfiguration implements WebMvcConfigurer {
...
@@ -100,15 +101,17 @@ public class SentinelWebAutoConfiguration implements WebMvcConfigurer {
if
(
blockExceptionHandlerOptional
.
isPresent
())
{
if
(
blockExceptionHandlerOptional
.
isPresent
())
{
blockExceptionHandlerOptional
blockExceptionHandlerOptional
.
ifPresent
(
sentinelWebMvcConfig:
:
setBlockExceptionHandler
);
.
ifPresent
(
sentinelWebMvcConfig:
:
setBlockExceptionHandler
);
}
}
else
{
else
{
if
(
StringUtils
.
hasText
(
properties
.
getBlockPage
()))
{
if
(
StringUtils
.
hasText
(
properties
.
getBlockPage
()))
{
sentinelWebMvcConfig
.
setBlockExceptionHandler
(((
request
,
response
,
sentinelWebMvcConfig
.
setBlockExceptionHandler
(((
request
,
response
,
e
)
->
response
.
sendRedirect
(
properties
.
getBlockPage
())));
e
)
->
response
.
sendRedirect
(
properties
.
getBlockPage
())));
}
}
else
{
else
{
// sentinelWebMvcConfig
// .setBlockExceptionHandler(new DefaultBlockExceptionHandler());
// for loitTime custom sentinel exception by chenshiying
sentinelWebMvcConfig
sentinelWebMvcConfig
.
setBlockExceptionHandler
(
new
Default
BlockExceptionHandler
());
.
setBlockExceptionHandler
(
new
Custom
BlockExceptionHandler
());
}
}
}
}
...
...
spring-cloud-timeloit-sentinel/src/main/java/com/timeloit/cloud/sentinel/loit/CustomBlockExceptionHandler.java
0 → 100644
浏览文件 @
a68e7168
package
com
.
timeloit
.
cloud
.
sentinel
.
loit
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.PrintWriter
;
public
class
CustomBlockExceptionHandler
implements
BlockExceptionHandler
{
@Override
public
void
handle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
BlockException
e
)
throws
Exception
{
response
.
setStatus
(
HttpStatus
.
OK
.
value
());
System
.
out
.
println
(
MediaType
.
APPLICATION_JSON
.
toString
());
response
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
);
PrintWriter
out
=
response
.
getWriter
();
out
.
print
(
"{\"success\":false,\"code\":\"444\",\"msg\":\"系统繁忙请稍后再试\"}"
);
out
.
flush
();
out
.
close
();
}
}
spring-cloud-timeloit-sentinel/src/main/java/com/timeloit/cloud/sentinel/loit/README.md
0 → 100644
浏览文件 @
a68e7168
# 时代凌宇sentinel 自定义异常类
SentinelWebAutoConfiguration.sentinelWebMvcConfig
```
$xslt
// for loitTime custom sentinel exception by chenshiying
sentinelWebMvcConfig
.setBlockExceptionHandler(new CustomBlockExceptionHandler());
```
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论