Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
05eb2e45
Commit
05eb2e45
authored
May 11, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
网关返回结果封装
parent
b1f3f9e2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
38 deletions
+47
-38
pom.xml
byit-myth-gateway/pom.xml
+1
-2
ErrorHandlerController.java
...a/com/byit/gateway/controller/ErrorHandlerController.java
+43
-0
ResponseGlobalFilter.java
...n/java/com/byit/gateway/filters/ResponseGlobalFilter.java
+0
-36
application-dev.yml
byit-myth-gateway/src/main/resources/application-dev.yml
+3
-0
No files found.
byit-myth-gateway/pom.xml
View file @
05eb2e45
...
...
@@ -45,8 +45,7 @@
<dependency>
<groupId>
myth-job
</groupId>
<artifactId>
myth-web-core
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<artifactId>
myth-core-common
</artifactId>
</dependency>
...
...
byit-myth-gateway/src/main/java/com/byit/gateway/controller/ErrorHandlerController.java
0 → 100644
View file @
05eb2e45
package
com
.
byit
.
gateway
.
controller
;
import
com.byit.dto.web.ResponseResult
;
import
com.byit.enums.TransferResultEnum
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.exception.ZuulException
;
import
org.springframework.boot.autoconfigure.web.ErrorController
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author huangfu
*/
@RestController
public
class
ErrorHandlerController
implements
ErrorController
{
@Override
public
String
getErrorPath
()
{
return
"/error"
;
}
@RequestMapping
(
value
=
"/error"
,
produces
={
"application/json; charset=utf-8"
})
public
Object
error
(
HttpServletResponse
response
){
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
ZuulException
exception
=
(
ZuulException
)
ctx
.
getThrowable
();
String
msg
=
""
;
String
code
=
""
;
if
(
exception
==
null
)
{
code
=
TransferResultEnum
.
ERROR
.
getCode
();
msg
=
"网关异常:"
+
TransferResultEnum
.
ERROR
.
getMsg
();
}
else
{
msg
=
"网关异常:"
+
exception
.
getMessage
();
code
=
exception
.
nStatusCode
+
""
;
}
ResponseResult
responseResult
=
new
ResponseResult
();
responseResult
.
setMsg
(
msg
);
responseResult
.
setTimeCost
(
System
.
currentTimeMillis
());
responseResult
.
setCode
(
code
);
return
responseResult
;
}
}
byit-myth-gateway/src/main/java/com/byit/gateway/filters/ResponseGlobalFilter.java
deleted
100644 → 0
View file @
b1f3f9e2
package
com
.
byit
.
gateway
.
filters
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
org.springframework.cloud.netflix.zuul.filters.support.FilterConstants
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author huangfu
*/
public
class
ResponseGlobalFilter
extends
ZuulFilter
{
@Override
public
String
filterType
()
{
return
FilterConstants
.
POST_TYPE
;
}
@Override
public
int
filterOrder
()
{
return
900
;
}
@Override
public
boolean
shouldFilter
()
{
return
true
;
}
@Override
public
Object
run
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
String
responseBody
=
ctx
.
getResponseBody
();
System
.
out
.
println
(
responseBody
);
return
null
;
}
}
byit-myth-gateway/src/main/resources/application-dev.yml
View file @
05eb2e45
...
...
@@ -34,3 +34,6 @@ spring:
zuul
:
ignored-services
:
'
*'
# sendErrorFilter:
# error:
# disable: true
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment