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
8b1a101c
Commit
8b1a101c
authored
Apr 09, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
1454bce7
a06de4d9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
4 deletions
+90
-4
ErrorPageFilter.java
...ngframework/boot/web/servlet/support/ErrorPageFilter.java
+1
-1
SampleController.java
...nt-test-tomcat/src/main/java/sample/SampleController.java
+15
-1
SampleTomcatDeployApplicationIT.java
...src/test/java/sample/SampleTomcatDeployApplicationIT.java
+74
-2
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/ErrorPageFilter.java
View file @
8b1a101c
...
...
@@ -181,7 +181,7 @@ public class ErrorPageFilter implements Filter, ErrorPageRegistry {
request
.
setAttribute
(
ERROR_EXCEPTION
,
ex
);
request
.
setAttribute
(
ERROR_EXCEPTION_TYPE
,
ex
.
getClass
());
response
.
reset
();
response
.
se
ndError
(
500
,
ex
.
getMessage
()
);
response
.
se
tStatus
(
500
);
request
.
getRequestDispatcher
(
path
).
forward
(
request
,
response
);
request
.
removeAttribute
(
ERROR_EXCEPTION
);
request
.
removeAttribute
(
ERROR_EXCEPTION_TYPE
);
...
...
spring-boot-tests/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/src/main/java/sample/SampleController.java
View file @
8b1a101c
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,6 +16,10 @@
package
sample
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -27,4 +31,14 @@ public class SampleController {
return
"Hello World"
;
}
@RequestMapping
(
"/send-error"
)
public
void
sendError
(
HttpServletResponse
response
)
throws
IOException
{
response
.
sendError
(
500
);
}
@RequestMapping
(
"/exception"
)
public
void
exception
()
{
throw
new
RuntimeException
();
}
}
spring-boot-tests/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/src/test/java/sample/SampleTomcatDeployApplicationIT.java
View file @
8b1a101c
...
...
@@ -16,10 +16,14 @@
package
sample
;
import
java.net.URI
;
import
org.junit.Test
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.RequestEntity
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -29,13 +33,14 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public
class
SampleTomcatDeployApplicationIT
{
private
final
TestRestTemplate
rest
=
new
TestRestTemplate
();
private
int
port
=
Integer
.
valueOf
(
System
.
getProperty
(
"port"
));
@Test
public
void
testHome
()
throws
Exception
{
String
url
=
"http://localhost:"
+
this
.
port
+
"/bootapp/"
;
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
url
,
String
.
class
);
ResponseEntity
<
String
>
entity
=
this
.
rest
.
getForEntity
(
url
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
...
...
@@ -50,4 +55,71 @@ public class SampleTomcatDeployApplicationIT {
assertThat
(
entity
.
getBody
()).
isEqualTo
(
"{\"status\":\"UP\"}"
);
}
@Test
public
void
errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse
()
throws
Exception
{
assertThatErrorFromExceptionProducesExpectedResponse
(
MediaType
.
ALL
,
MediaType
.
APPLICATION_JSON
);
}
@Test
public
void
errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse
()
throws
Exception
{
assertThatErrorFromExceptionProducesExpectedResponse
(
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_JSON
);
}
@Test
public
void
errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse
()
throws
Exception
{
assertThatErrorFromExceptionProducesExpectedResponse
(
MediaType
.
TEXT_HTML
,
MediaType
.
TEXT_HTML
);
}
@Test
public
void
sendErrorForRequestAcceptingAnythingProducesAJsonResponse
()
throws
Exception
{
assertThatSendErrorProducesExpectedResponse
(
MediaType
.
ALL
,
MediaType
.
APPLICATION_JSON
);
}
@Test
public
void
sendErrorForRequestAcceptingJsonProducesAJsonResponse
()
throws
Exception
{
assertThatSendErrorProducesExpectedResponse
(
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_JSON
);
}
@Test
public
void
sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse
()
throws
Exception
{
assertThatSendErrorProducesExpectedResponse
(
MediaType
.
TEXT_HTML
,
MediaType
.
TEXT_HTML
);
}
private
void
assertThatSendErrorProducesExpectedResponse
(
MediaType
accept
,
MediaType
contentType
)
{
RequestEntity
<
Void
>
request
=
RequestEntity
.
get
(
URI
.
create
(
"http://localhost:"
+
this
.
port
+
"/bootapp/send-error"
))
.
accept
(
accept
).
build
();
ResponseEntity
<
String
>
response
=
this
.
rest
.
exchange
(
request
,
String
.
class
);
assertThat
(
response
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
contentType
.
isCompatibleWith
(
response
.
getHeaders
().
getContentType
()))
.
as
(
"%s is compatible with %s"
,
contentType
,
response
.
getHeaders
().
getContentType
())
.
isTrue
();
}
private
void
assertThatErrorFromExceptionProducesExpectedResponse
(
MediaType
accept
,
MediaType
contentType
)
{
RequestEntity
<
Void
>
request
=
RequestEntity
.
get
(
URI
.
create
(
"http://localhost:"
+
this
.
port
+
"/bootapp/exception"
))
.
accept
(
accept
).
build
();
ResponseEntity
<
String
>
response
=
this
.
rest
.
exchange
(
request
,
String
.
class
);
assertThat
(
response
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
contentType
.
isCompatibleWith
(
response
.
getHeaders
().
getContentType
()))
.
as
(
"%s is compatible with %s"
,
contentType
,
response
.
getHeaders
().
getContentType
())
.
isTrue
();
}
}
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