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
a7338e18
Commit
a7338e18
authored
Aug 04, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.1.x'
parents
68582bba
9372d154
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
+26
-3
ErrorPageFilter.java
...org/springframework/boot/context/web/ErrorPageFilter.java
+4
-3
ErrorPageFilterTests.java
...pringframework/boot/context/web/ErrorPageFilterTests.java
+22
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java
View file @
a7338e18
...
@@ -56,7 +56,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
...
@@ -56,7 +56,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
@Component
@Component
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
class
ErrorPageFilter
extends
AbstractConfigurableEmbeddedServletContainer
implements
class
ErrorPageFilter
extends
AbstractConfigurableEmbeddedServletContainer
implements
Filter
,
NonEmbeddedServletContainerFactory
{
Filter
,
NonEmbeddedServletContainerFactory
{
private
static
Log
logger
=
LogFactory
.
getLog
(
ErrorPageFilter
.
class
);
private
static
Log
logger
=
LogFactory
.
getLog
(
ErrorPageFilter
.
class
);
...
@@ -123,19 +123,20 @@ Filter, NonEmbeddedServletContainerFactory {
...
@@ -123,19 +123,20 @@ Filter, NonEmbeddedServletContainerFactory {
private
void
handleErrorStatus
(
HttpServletRequest
request
,
private
void
handleErrorStatus
(
HttpServletRequest
request
,
HttpServletResponse
response
,
int
status
,
String
message
)
HttpServletResponse
response
,
int
status
,
String
message
)
throws
ServletException
,
IOException
{
throws
ServletException
,
IOException
{
String
errorPath
=
getErrorPath
(
this
.
statuses
,
status
);
String
errorPath
=
getErrorPath
(
this
.
statuses
,
status
);
if
(
errorPath
==
null
)
{
if
(
errorPath
==
null
)
{
response
.
sendError
(
status
,
message
);
response
.
sendError
(
status
,
message
);
return
;
return
;
}
}
response
.
setStatus
(
status
);
setErrorAttributes
(
request
,
status
,
message
);
setErrorAttributes
(
request
,
status
,
message
);
request
.
getRequestDispatcher
(
errorPath
).
forward
(
request
,
response
);
request
.
getRequestDispatcher
(
errorPath
).
forward
(
request
,
response
);
}
}
private
void
handleException
(
HttpServletRequest
request
,
private
void
handleException
(
HttpServletRequest
request
,
HttpServletResponse
response
,
ErrorWrapperResponse
wrapped
,
Throwable
ex
)
HttpServletResponse
response
,
ErrorWrapperResponse
wrapped
,
Throwable
ex
)
throws
IOException
,
ServletException
{
throws
IOException
,
ServletException
{
Class
<?>
type
=
ex
.
getClass
();
Class
<?>
type
=
ex
.
getClass
();
String
errorPath
=
getErrorPath
(
type
);
String
errorPath
=
getErrorPath
(
type
);
if
(
errorPath
==
null
)
{
if
(
errorPath
==
null
)
{
...
...
spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java
View file @
a7338e18
...
@@ -63,6 +63,28 @@ public class ErrorPageFilterTests {
...
@@ -63,6 +63,28 @@ public class ErrorPageFilterTests {
assertTrue
(
this
.
response
.
isCommitted
());
assertTrue
(
this
.
response
.
isCommitted
());
}
}
@Test
public
void
unauthorizedWithErrorPath
()
throws
Exception
{
this
.
filter
.
addErrorPages
(
new
ErrorPage
(
"/error"
));
this
.
chain
=
new
MockFilterChain
()
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
)
throws
IOException
,
ServletException
{
((
HttpServletResponse
)
response
).
sendError
(
401
,
"UNAUTHORIZED"
);
super
.
doFilter
(
request
,
response
);
}
};
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
this
.
chain
.
getRequest
(),
equalTo
((
ServletRequest
)
this
.
request
));
HttpServletResponseWrapper
wrapper
=
(
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
();
assertThat
(
wrapper
.
getResponse
(),
equalTo
((
ServletResponse
)
this
.
response
));
assertTrue
(
this
.
response
.
isCommitted
());
assertThat
(
wrapper
.
getStatus
(),
equalTo
(
401
));
// The real response has to be 401 as well...
assertThat
(
this
.
response
.
getStatus
(),
equalTo
(
401
));
}
@Test
@Test
public
void
responseCommitted
()
throws
Exception
{
public
void
responseCommitted
()
throws
Exception
{
this
.
filter
.
addErrorPages
(
new
ErrorPage
(
"/error"
));
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