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
a354657a
Commit
a354657a
authored
Sep 24, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-18343
parents
4ab53dc8
c6134184
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
BasicErrorController.java
...autoconfigure/web/servlet/error/BasicErrorController.java
+4
-1
BasicErrorControllerMockMvcTests.java
...e/web/servlet/error/BasicErrorControllerMockMvcTests.java
+26
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java
View file @
a354657a
...
@@ -94,8 +94,11 @@ public class BasicErrorController extends AbstractErrorController {
...
@@ -94,8 +94,11 @@ public class BasicErrorController extends AbstractErrorController {
@RequestMapping
@RequestMapping
public
ResponseEntity
<
Map
<
String
,
Object
>>
error
(
HttpServletRequest
request
)
{
public
ResponseEntity
<
Map
<
String
,
Object
>>
error
(
HttpServletRequest
request
)
{
Map
<
String
,
Object
>
body
=
getErrorAttributes
(
request
,
isIncludeStackTrace
(
request
,
MediaType
.
ALL
));
HttpStatus
status
=
getStatus
(
request
);
HttpStatus
status
=
getStatus
(
request
);
if
(
status
==
HttpStatus
.
NO_CONTENT
)
{
return
new
ResponseEntity
<
Map
<
String
,
Object
>>(
status
);
}
Map
<
String
,
Object
>
body
=
getErrorAttributes
(
request
,
isIncludeStackTrace
(
request
,
MediaType
.
ALL
));
return
new
ResponseEntity
<>(
body
,
status
);
return
new
ResponseEntity
<>(
body
,
status
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerMockMvcTests.java
View file @
a354657a
...
@@ -90,13 +90,23 @@ class BasicErrorControllerMockMvcTests {
...
@@ -90,13 +90,23 @@ class BasicErrorControllerMockMvcTests {
}
}
@Test
@Test
void
testErrorWithResponseStatus
()
throws
Exception
{
void
testErrorWith
NotFound
ResponseStatus
()
throws
Exception
{
MvcResult
result
=
this
.
mockMvc
.
perform
(
get
(
"/bang"
)).
andExpect
(
status
().
isNotFound
()).
andReturn
();
MvcResult
result
=
this
.
mockMvc
.
perform
(
get
(
"/bang"
)).
andExpect
(
status
().
isNotFound
()).
andReturn
();
MvcResult
response
=
this
.
mockMvc
.
perform
(
new
ErrorDispatcher
(
result
,
"/error"
)).
andReturn
();
MvcResult
response
=
this
.
mockMvc
.
perform
(
new
ErrorDispatcher
(
result
,
"/error"
)).
andReturn
();
String
content
=
response
.
getResponse
().
getContentAsString
();
String
content
=
response
.
getResponse
().
getContentAsString
();
assertThat
(
content
).
contains
(
"Expected!"
);
assertThat
(
content
).
contains
(
"Expected!"
);
}
}
@Test
void
testErrorWithNoContentResponseStatus
()
throws
Exception
{
MvcResult
result
=
this
.
mockMvc
.
perform
(
get
(
"/noContent"
).
accept
(
"some/thing"
))
.
andExpect
(
status
().
isNoContent
()).
andReturn
();
MvcResult
response
=
this
.
mockMvc
.
perform
(
new
ErrorDispatcher
(
result
,
"/error"
))
.
andExpect
(
status
().
isNoContent
()).
andReturn
();
String
content
=
response
.
getResponse
().
getContentAsString
();
assertThat
(
content
).
isEmpty
();
}
@Test
@Test
void
testBindingExceptionForMachineClient
()
throws
Exception
{
void
testBindingExceptionForMachineClient
()
throws
Exception
{
// In a real server the response is carried over into the error dispatcher, but
// In a real server the response is carried over into the error dispatcher, but
...
@@ -168,6 +178,11 @@ class BasicErrorControllerMockMvcTests {
...
@@ -168,6 +178,11 @@ class BasicErrorControllerMockMvcTests {
throw
error
;
throw
error
;
}
}
@RequestMapping
(
"/noContent"
)
void
noContent
()
throws
Exception
{
throw
new
NoContentException
(
"Expected!"
);
}
public
String
getFoo
()
{
public
String
getFoo
()
{
return
"foo"
;
return
"foo"
;
}
}
...
@@ -185,6 +200,15 @@ class BasicErrorControllerMockMvcTests {
...
@@ -185,6 +200,15 @@ class BasicErrorControllerMockMvcTests {
}
}
@ResponseStatus
(
HttpStatus
.
NO_CONTENT
)
private
static
class
NoContentException
extends
RuntimeException
{
NoContentException
(
String
string
)
{
super
(
string
);
}
}
private
class
ErrorDispatcher
implements
RequestBuilder
{
private
class
ErrorDispatcher
implements
RequestBuilder
{
private
MvcResult
result
;
private
MvcResult
result
;
...
@@ -201,6 +225,7 @@ class BasicErrorControllerMockMvcTests {
...
@@ -201,6 +225,7 @@ class BasicErrorControllerMockMvcTests {
MockHttpServletRequest
request
=
this
.
result
.
getRequest
();
MockHttpServletRequest
request
=
this
.
result
.
getRequest
();
request
.
setDispatcherType
(
DispatcherType
.
ERROR
);
request
.
setDispatcherType
(
DispatcherType
.
ERROR
);
request
.
setRequestURI
(
this
.
path
);
request
.
setRequestURI
(
this
.
path
);
request
.
setAttribute
(
"javax.servlet.error.status_code"
,
this
.
result
.
getResponse
().
getStatus
());
return
request
;
return
request
;
}
}
...
...
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