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
14f24dbe
Commit
14f24dbe
authored
Jul 07, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x' into 2.2.x
Closes gh-22248
parents
1ad66cf9
26f59126
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
ErrorPageFilter.java
...ngframework/boot/web/servlet/support/ErrorPageFilter.java
+5
-2
ErrorPageFilterTests.java
...mework/boot/web/servlet/support/ErrorPageFilterTests.java
+26
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/ErrorPageFilter.java
View file @
14f24dbe
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -137,7 +137,10 @@ public class ErrorPageFilter implements Filter, ErrorPageRegistry {
catch
(
Throwable
ex
)
{
Throwable
exceptionToHandle
=
ex
;
if
(
ex
instanceof
NestedServletException
)
{
exceptionToHandle
=
((
NestedServletException
)
ex
).
getRootCause
();
Throwable
rootCause
=
((
NestedServletException
)
ex
).
getRootCause
();
if
(
rootCause
!=
null
)
{
exceptionToHandle
=
rootCause
;
}
}
handleException
(
request
,
response
,
wrapped
,
exceptionToHandle
);
response
.
flushBuffer
();
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java
View file @
14f24dbe
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -43,6 +43,7 @@ import org.springframework.mock.web.MockFilterConfig;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.mock.web.MockRequestDispatcher
;
import
org.springframework.web.bind.MissingServletRequestParameterException
;
import
org.springframework.web.context.request.async.DeferredResult
;
import
org.springframework.web.context.request.async.StandardServletAsyncWebRequest
;
import
org.springframework.web.context.request.async.WebAsyncManager
;
...
...
@@ -387,6 +388,30 @@ class ErrorPageFilterTests {
assertThat
(
this
.
response
.
getForwardedUrl
()).
isEqualTo
(
"/500"
);
}
@Test
void
nestedServletExceptionWithNoCause
()
throws
Exception
{
this
.
filter
.
addErrorPages
(
new
ErrorPage
(
MissingServletRequestParameterException
.
class
,
"/500"
));
this
.
chain
=
new
TestFilterChain
((
request
,
response
,
chain
)
->
{
chain
.
call
();
throw
new
MissingServletRequestParameterException
(
"test"
,
"string"
);
});
this
.
filter
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(((
HttpServletResponseWrapper
)
this
.
chain
.
getResponse
()).
getStatus
()).
isEqualTo
(
500
);
assertThat
(
this
.
request
.
getAttribute
(
RequestDispatcher
.
ERROR_STATUS_CODE
)).
isEqualTo
(
500
);
assertThat
(
this
.
request
.
getAttribute
(
RequestDispatcher
.
ERROR_MESSAGE
))
.
isEqualTo
(
"Required string parameter 'test' is not present"
);
Map
<
String
,
Object
>
requestAttributes
=
getAttributesForDispatch
(
"/500"
);
assertThat
(
requestAttributes
.
get
(
RequestDispatcher
.
ERROR_EXCEPTION_TYPE
))
.
isEqualTo
(
MissingServletRequestParameterException
.
class
);
assertThat
(
requestAttributes
.
get
(
RequestDispatcher
.
ERROR_EXCEPTION
))
.
isInstanceOf
(
MissingServletRequestParameterException
.
class
);
assertThat
(
this
.
request
.
getAttribute
(
RequestDispatcher
.
ERROR_EXCEPTION_TYPE
)).
isNull
();
assertThat
(
this
.
request
.
getAttribute
(
RequestDispatcher
.
ERROR_EXCEPTION
)).
isNull
();
assertThat
(
this
.
request
.
getAttribute
(
RequestDispatcher
.
ERROR_REQUEST_URI
)).
isEqualTo
(
"/test/path"
);
assertThat
(
this
.
response
.
isCommitted
()).
isTrue
();
assertThat
(
this
.
response
.
getForwardedUrl
()).
isEqualTo
(
"/500"
);
}
@Test
void
whenErrorIsSentAndWriterIsFlushedErrorIsSentToTheClient
()
throws
Exception
{
this
.
chain
=
new
TestFilterChain
((
request
,
response
,
chain
)
->
{
...
...
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