Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
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
openSource
spring-cloud-netflix
Commits
95541e01
Commit
95541e01
authored
Jan 08, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only run SendErrorFilter once (fixes recursive forwarding if /error fails)
parent
64e5a2e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
SendErrorFilter.java
...work/cloud/netflix/zuul/filters/post/SendErrorFilter.java
+9
-5
SendErrorFilterTests.java
...cloud/netflix/zuul/filters/post/SendErrorFilterTests.java
+9
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/post/SendErrorFilter.java
View file @
95541e01
...
...
@@ -14,6 +14,8 @@ import javax.servlet.RequestDispatcher;
@Slf4j
public
class
SendErrorFilter
extends
ZuulFilter
{
protected
static
final
String
SEND_ERROR_FILTER_RAN
=
"sendErrorFilter.ran"
;
@Value
(
"${error.path:/error}"
)
private
String
errorPath
;
...
...
@@ -30,7 +32,8 @@ public class SendErrorFilter extends ZuulFilter {
@Override
public
boolean
shouldFilter
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
return
ctx
.
containsKey
(
"error.status_code"
);
//only forward to errorPath if it hasn't been forwarded to already
return
ctx
.
containsKey
(
"error.status_code"
)
&&
!
ctx
.
getBoolean
(
SEND_ERROR_FILTER_RAN
,
false
);
}
@Override
...
...
@@ -44,10 +47,11 @@ public class SendErrorFilter extends ZuulFilter {
ctx
.
getRequest
().
setAttribute
(
"javax.servlet.error.exception"
,
e
);
}
ctx
.
getRequest
().
setAttribute
(
"javax.servlet.error.status_code"
,
statusCode
);
RequestDispatcher
dispatcher
=
ctx
.
getRequest
().
getRequestDispatcher
(
errorPath
);
if
(
dispatcher
!=
null
)
{
dispatcher
.
forward
(
ctx
.
getRequest
(),
ctx
.
getResponse
());
}
RequestDispatcher
dispatcher
=
ctx
.
getRequest
().
getRequestDispatcher
(
errorPath
);
if
(
dispatcher
!=
null
)
{
ctx
.
set
(
SEND_ERROR_FILTER_RAN
,
true
);
dispatcher
.
forward
(
ctx
.
getRequest
(),
ctx
.
getResponse
());
}
}
catch
(
Exception
e
)
{
Throwables
.
propagate
(
e
);
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/post/SendErrorFilterTests.java
View file @
95541e01
...
...
@@ -48,4 +48,13 @@ public class SendErrorFilterTests {
assertTrue
(
"shouldFilter returned false"
,
filter
.
shouldFilter
());
filter
.
run
();
}
@Test
public
void
doesNotRunTwice
()
{
SendErrorFilter
filter
=
createSendErrorFilter
(
new
MockHttpServletRequest
());
assertTrue
(
"shouldFilter returned false"
,
filter
.
shouldFilter
());
filter
.
run
();
assertFalse
(
"shouldFilter returned true"
,
filter
.
shouldFilter
());
}
}
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