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
b0bf9c77
Commit
b0bf9c77
authored
Jun 25, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix logic error in ErrorPageFilter (fixes gh-1149)
parent
91bbd20c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
3 deletions
+47
-3
WelcomeController.java
...e-web-jsp/src/main/java/sample/jsp/WelcomeController.java
+5
-0
ErrorPageFilter.java
...org/springframework/boot/context/web/ErrorPageFilter.java
+4
-3
ErrorPageFilterTests.java
...pringframework/boot/context/web/ErrorPageFilterTests.java
+38
-0
No files found.
spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java
View file @
b0bf9c77
...
@@ -36,4 +36,9 @@ public class WelcomeController {
...
@@ -36,4 +36,9 @@ public class WelcomeController {
return
"welcome"
;
return
"welcome"
;
}
}
@RequestMapping
(
"/foo"
)
public
String
foo
(
Map
<
String
,
Object
>
model
)
{
throw
new
RuntimeException
(
"Foo"
);
}
}
}
spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java
View file @
b0bf9c77
...
@@ -135,13 +135,13 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
...
@@ -135,13 +135,13 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
setErrorAttributes
(
request
,
500
,
ex
.
getMessage
());
setErrorAttributes
(
request
,
500
,
ex
.
getMessage
());
request
.
setAttribute
(
ERROR_EXCEPTION
,
ex
);
request
.
setAttribute
(
ERROR_EXCEPTION
,
ex
);
request
.
setAttribute
(
ERROR_EXCEPTION_TYPE
,
type
.
getName
());
request
.
setAttribute
(
ERROR_EXCEPTION_TYPE
,
type
.
getName
());
wrapped
.
sendError
(
500
,
ex
.
getMessage
());
forwardToErrorPage
(
errorPath
,
request
,
wrapped
,
ex
);
forwardToErrorPage
(
errorPath
,
request
,
wrapped
,
ex
);
}
}
private
void
forwardToErrorPage
(
String
path
,
HttpServletRequest
request
,
private
void
forwardToErrorPage
(
String
path
,
HttpServletRequest
request
,
ServletResponse
response
,
Throwable
ex
)
throws
ServletException
,
IOException
{
HttpServletResponse
response
,
Throwable
ex
)
throws
ServletException
,
if
(!
response
.
isCommitted
())
{
IOException
{
if
(
response
.
isCommitted
())
{
String
message
=
"Cannot forward to error page for"
+
request
.
getRequestURI
()
String
message
=
"Cannot forward to error page for"
+
request
.
getRequestURI
()
+
" (response is committed), so this response may have "
+
" (response is committed), so this response may have "
+
"the wrong status code"
;
+
"the wrong status code"
;
...
@@ -151,6 +151,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
...
@@ -151,6 +151,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
return
;
return
;
}
}
response
.
reset
();
response
.
reset
();
response
.
sendError
(
500
,
ex
.
getMessage
());
request
.
getRequestDispatcher
(
path
).
forward
(
request
,
response
);
request
.
getRequestDispatcher
(
path
).
forward
(
request
,
response
);
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java
View file @
b0bf9c77
...
@@ -59,6 +59,44 @@ public class ErrorPageFilterTests {
...
@@ -59,6 +59,44 @@ public class ErrorPageFilterTests {
equalTo
((
ServletResponse
)
this
.
response
));
equalTo
((
ServletResponse
)
this
.
response
));
}
}
@Test
public
void
responseCommitted
()
throws
Exception
{
this
.
filter
.
addErrorPages
(
new
ErrorPage
(
"/error"
));
this
.
response
.
setCommitted
(
true
);
this
.
chain
=
new
MockFilterChain
()
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
)
throws
IOException
,
ServletException
{
((
HttpServletResponse
)
response
).
sendError
(
400
,
"BAD"
);
super
.
doFilter
(
request
,
response
);
}
};
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
this
.
chain
.
getRequest
(),
equalTo
((
ServletRequest
)
this
.
request
));
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getResponse
(),
equalTo
((
ServletResponse
)
this
.
response
));
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getStatus
(),
equalTo
(
400
));
}
@Test
public
void
responseUncommitted
()
throws
Exception
{
this
.
chain
=
new
MockFilterChain
()
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
)
throws
IOException
,
ServletException
{
((
HttpServletResponse
)
response
).
sendError
(
400
,
"BAD"
);
super
.
doFilter
(
request
,
response
);
}
};
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
this
.
chain
.
getRequest
(),
equalTo
((
ServletRequest
)
this
.
request
));
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getResponse
(),
equalTo
((
ServletResponse
)
this
.
response
));
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getStatus
(),
equalTo
(
400
));
}
@Test
@Test
public
void
globalError
()
throws
Exception
{
public
void
globalError
()
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