Merge branch '1.2.x'
This commit is contained in:
commit
4f7752d467
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.web;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeStacktrace;
|
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeStacktrace;
|
||||||
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory;
|
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory;
|
||||||
|
|
@ -79,7 +80,9 @@ public class BasicErrorController extends AbstractErrorController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(produces = "text/html")
|
@RequestMapping(produces = "text/html")
|
||||||
public ModelAndView errorHtml(HttpServletRequest request) {
|
public ModelAndView errorHtml(HttpServletRequest request,
|
||||||
|
HttpServletResponse response) {
|
||||||
|
response.setStatus(getStatus(request).value());
|
||||||
Map<String, Object> model = getErrorAttributes(request,
|
Map<String, Object> model = getErrorAttributes(request,
|
||||||
isIncludeStackTrace(request, MediaType.TEXT_HTML));
|
isIncludeStackTrace(request, MediaType.TEXT_HTML));
|
||||||
return new ModelAndView("error", model);
|
return new ModelAndView("error", model);
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ public class BasicErrorControllerDirectMockMvcTests {
|
||||||
.run("--server.port=0"));
|
.run("--server.port=0"));
|
||||||
MvcResult response = this.mockMvc
|
MvcResult response = this.mockMvc
|
||||||
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk()).andReturn();
|
.andExpect(status().is5xxServerError()).andReturn();
|
||||||
String content = response.getResponse().getContentAsString();
|
String content = response.getResponse().getContentAsString();
|
||||||
assertTrue("Wrong content: " + content, content.contains("status=999"));
|
assertTrue("Wrong content: " + content, content.contains("status=999"));
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ public class BasicErrorControllerDirectMockMvcTests {
|
||||||
WebMvcIncludedConfiguration.class).run("--server.port=0"));
|
WebMvcIncludedConfiguration.class).run("--server.port=0"));
|
||||||
MvcResult response = this.mockMvc
|
MvcResult response = this.mockMvc
|
||||||
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk()).andReturn();
|
.andExpect(status().is5xxServerError()).andReturn();
|
||||||
String content = response.getResponse().getContentAsString();
|
String content = response.getResponse().getContentAsString();
|
||||||
assertTrue("Wrong content: " + content, content.contains("status=999"));
|
assertTrue("Wrong content: " + content, content.contains("status=999"));
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +116,7 @@ public class BasicErrorControllerDirectMockMvcTests {
|
||||||
WithAopConfiguration.class).run("--server.port=0"));
|
WithAopConfiguration.class).run("--server.port=0"));
|
||||||
MvcResult response = this.mockMvc
|
MvcResult response = this.mockMvc
|
||||||
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk()).andReturn();
|
.andExpect(status().is5xxServerError()).andReturn();
|
||||||
String content = response.getResponse().getContentAsString();
|
String content = response.getResponse().getContentAsString();
|
||||||
assertTrue("Wrong content: " + content, content.contains("status=999"));
|
assertTrue("Wrong content: " + content, content.contains("status=999"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ public class BasicErrorControllerMockMvcTests {
|
||||||
public void testDirectAccessForBrowserClient() throws Exception {
|
public void testDirectAccessForBrowserClient() throws Exception {
|
||||||
MvcResult response = this.mockMvc
|
MvcResult response = this.mockMvc
|
||||||
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk()).andReturn();
|
.andExpect(status().is5xxServerError()).andReturn();
|
||||||
String content = response.getResponse().getContentAsString();
|
String content = response.getResponse().getContentAsString();
|
||||||
assertTrue("Wrong content: " + content, content.contains("ERROR_BEAN"));
|
assertTrue("Wrong content: " + content, content.contains("ERROR_BEAN"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ public class DefaultErrorViewIntegrationTests {
|
||||||
public void testErrorForBrowserClient() throws Exception {
|
public void testErrorForBrowserClient() throws Exception {
|
||||||
MvcResult response = this.mockMvc
|
MvcResult response = this.mockMvc
|
||||||
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
.perform(get("/error").accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk()).andReturn();
|
.andExpect(status().is5xxServerError()).andReturn();
|
||||||
String content = response.getResponse().getContentAsString();
|
String content = response.getResponse().getContentAsString();
|
||||||
assertTrue("Wrong content: " + content, content.contains("<html>"));
|
assertTrue("Wrong content: " + content, content.contains("<html>"));
|
||||||
assertTrue("Wrong content: " + content, content.contains("999"));
|
assertTrue("Wrong content: " + content, content.contains("999"));
|
||||||
|
|
@ -83,7 +83,7 @@ public class DefaultErrorViewIntegrationTests {
|
||||||
new RuntimeException(
|
new RuntimeException(
|
||||||
"<script>alert('Hello World')</script>"))
|
"<script>alert('Hello World')</script>"))
|
||||||
.accept(MediaType.TEXT_HTML))
|
.accept(MediaType.TEXT_HTML))
|
||||||
.andExpect(status().isOk()).andReturn();
|
.andExpect(status().is5xxServerError()).andReturn();
|
||||||
String content = response.getResponse().getContentAsString();
|
String content = response.getResponse().getContentAsString();
|
||||||
assertTrue("Wrong content: " + content, content.contains("<script>"));
|
assertTrue("Wrong content: " + content, content.contains("<script>"));
|
||||||
assertTrue("Wrong content: " + content, content.contains("Hello World"));
|
assertTrue("Wrong content: " + content, content.contains("Hello World"));
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ public class SampleActuatorUiApplicationTests {
|
||||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||||
"http://localhost:" + this.port + "/error", HttpMethod.GET,
|
"http://localhost:" + this.port + "/error", HttpMethod.GET,
|
||||||
new HttpEntity<Void>(headers), String.class);
|
new HttpEntity<Void>(headers), String.class);
|
||||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||||
entity.getBody().contains("<html>"));
|
entity.getBody().contains("<html>"));
|
||||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue