Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
4a33ab55
Commit
4a33ab55
authored
Jul 17, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure ErrorPageFilter is only applied once per request
Fixes gh-1257
parent
0c52817c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
11 deletions
+36
-11
ErrorPageFilter.java
...org/springframework/boot/context/web/ErrorPageFilter.java
+15
-7
ErrorPageFilterTests.java
...pringframework/boot/context/web/ErrorPageFilterTests.java
+21
-4
No files found.
spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java
View file @
4a33ab55
...
...
@@ -38,6 +38,7 @@ import org.springframework.boot.context.embedded.ErrorPage;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.filter.OncePerRequestFilter
;
/**
* A special {@link AbstractConfigurableEmbeddedServletContainer} for non-embedded
...
...
@@ -76,21 +77,28 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
private
final
Map
<
Class
<?>,
String
>
exceptions
=
new
HashMap
<
Class
<?>,
String
>();
private
final
Map
<
Class
<?>,
Class
<?>>
subtypes
=
new
HashMap
<
Class
<?>,
Class
<?>>();
private
final
OncePerRequestFilter
delegate
=
new
OncePerRequestFilter
(
)
{
@Override
protected
void
doFilterInternal
(
HttpServletRequest
request
,
HttpServletResponse
response
,
FilterChain
chain
)
throws
ServletException
,
IOException
{
ErrorPageFilter
.
this
.
doFilter
(
request
,
response
,
chain
);
}
};
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
delegate
.
init
(
filterConfig
);
}
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
if
(
request
instanceof
HttpServletRequest
&&
response
instanceof
HttpServletResponse
)
{
doFilter
((
HttpServletRequest
)
request
,
(
HttpServletResponse
)
response
,
chain
);
}
else
{
chain
.
doFilter
(
request
,
response
);
}
delegate
.
doFilter
(
request
,
response
,
chain
);
}
private
void
doFilter
(
HttpServletRequest
request
,
HttpServletResponse
response
,
...
...
spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java
View file @
4a33ab55
...
...
@@ -16,6 +16,11 @@
package
org
.
springframework
.
boot
.
context
.
web
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.IOException
;
import
javax.servlet.RequestDispatcher
;
...
...
@@ -29,13 +34,10 @@ import org.junit.Test;
import
org.springframework.boot.context.embedded.ErrorPage
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.mock.web.MockFilterChain
;
import
org.springframework.mock.web.MockFilterConfig
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
* Tests for {@link ErrorPageFilter}.
*
...
...
@@ -97,6 +99,21 @@ public class ErrorPageFilterTests {
equalTo
(
400
));
}
@Test
public
void
oncePerRequest
()
throws
Exception
{
this
.
chain
=
new
MockFilterChain
()
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
)
throws
IOException
,
ServletException
{
((
HttpServletResponse
)
response
).
sendError
(
400
,
"BAD"
);
assertNotNull
(
request
.
getAttribute
(
"FILTER.FILTERED"
));
super
.
doFilter
(
request
,
response
);
}
};
filter
.
init
(
new
MockFilterConfig
(
"FILTER"
));
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
}
@Test
public
void
globalError
()
throws
Exception
{
this
.
filter
.
addErrorPages
(
new
ErrorPage
(
"/error"
));
...
...
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