Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
roncoo
roncoo-education
提交
18eb38d1
R
roncoo-education
项目概览
roncoo
/
roncoo-education
10 个月 前同步成功
通知
146
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roncoo-education
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
18eb38d1
编写于
5月 30, 2020
作者:
F
fengyongwei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改网关的bug
上级
cca2e72f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
19 deletion
+40
-19
roncoo-education-server-gateway/src/main/java/com/roncoo/education/server/gateway/common/FilterPre.java
...com/roncoo/education/server/gateway/common/FilterPre.java
+8
-19
roncoo-education-server-gateway/src/main/java/com/roncoo/education/server/gateway/controller/HandlerController.java
...ducation/server/gateway/controller/HandlerController.java
+32
-0
未找到文件。
roncoo-education-server-gateway/src/main/java/com/roncoo/education/server/gateway/common/FilterPre.java
浏览文件 @
18eb38d1
...
...
@@ -16,6 +16,7 @@ import javax.servlet.ServletInputStream;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
com.netflix.zuul.exception.ZuulException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -73,7 +74,7 @@ public class FilterPre extends ZuulFilter {
}
@Override
public
Object
run
()
{
public
Object
run
()
throws
ZuulException
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
String
uri
=
RequestContext
.
getCurrentContext
().
getRequest
().
getServletPath
();
logger
.
info
(
"请求地址"
+
uri
);
...
...
@@ -96,20 +97,18 @@ public class FilterPre extends ZuulFilter {
}
}
catch
(
BaseException
e
)
{
logger
.
error
(
"系统异常"
,
e
.
getMessage
());
ctx
.
setSendZuulResponse
(
false
);
resp
(
ctx
,
e
.
getMessage
(),
e
.
getCode
());
return
null
;
logger
.
error
(
"系统异常"
,
e
);
throw
new
ZuulException
(
e
,
e
.
getCode
(),
e
.
getMessage
());
}
// 参数封装
try
{
ctx
.
setRequest
(
requestWrapper
(
request
,
userNo
));
}
catch
(
IOException
e
)
{
return
null
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"封装参数异常"
,
e
.
getMessage
());
ctx
.
setSendZuulResponse
(
false
);
resp
(
ctx
,
"系统异常,请重试"
);
throw
new
ZuulException
(
e
,
ResultEnum
.
ERROR
.
getCode
(),
e
.
getMessage
());
}
return
null
;
}
/**
...
...
@@ -180,16 +179,6 @@ public class FilterPre extends ZuulFilter {
};
}
private
void
resp
(
RequestContext
ctx
,
String
msg
)
{
ctx
.
getResponse
().
setCharacterEncoding
(
"UTF-8"
);
ctx
.
setResponseBody
(
JSONUtil
.
toJSONString
(
Result
.
error
(
msg
)));
}
private
void
resp
(
RequestContext
ctx
,
String
msg
,
int
code
)
{
ctx
.
getResponse
().
setCharacterEncoding
(
"UTF-8"
);
ctx
.
setResponseBody
(
JSONUtil
.
toJSONString
(
Result
.
error
(
code
,
msg
)));
}
@SuppressWarnings
(
"unchecked"
)
private
static
TreeMap
<
String
,
Object
>
getParamMap
(
HttpServletRequest
request
)
{
TreeMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
...
...
roncoo-education-server-gateway/src/main/java/com/roncoo/education/server/gateway/controller/HandlerController.java
0 → 100644
浏览文件 @
18eb38d1
package
com.roncoo.education.server.gateway.controller
;
import
com.roncoo.education.util.base.Result
;
import
org.springframework.boot.web.servlet.error.ErrorController
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.exception.ZuulException
;
@RestController
public
class
HandlerController
implements
ErrorController
{
/**
* 出异常后进入该方法,交由下面的方法处理
*/
@Override
public
String
getErrorPath
()
{
return
"/error"
;
}
@RequestMapping
(
"/error"
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
Result
<
String
>
error
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
ZuulException
e
=
(
ZuulException
)
ctx
.
getThrowable
();
return
Result
.
error
(
e
.
nStatusCode
,
e
.
errorCause
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录