Skip to content

Commit d49a102

Browse files
committed
Merge branch '1.5.x'
2 parents 696aeda + 6b59814 commit d49a102

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
import org.springframework.expression.EvaluationContext;
7070
import org.springframework.expression.Expression;
7171
import org.springframework.expression.spel.standard.SpelExpressionParser;
72-
import org.springframework.expression.spel.support.StandardEvaluationContext;
72+
import org.springframework.expression.spel.support.SimpleEvaluationContext;
7373
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
7474
import org.springframework.web.servlet.DispatcherServlet;
7575
import org.springframework.web.servlet.View;
@@ -304,10 +304,8 @@ private static class ExpressionResolver implements PlaceholderResolver {
304304
}
305305

306306
private EvaluationContext getContext(Map<String, ?> map) {
307-
StandardEvaluationContext context = new StandardEvaluationContext();
308-
context.addPropertyAccessor(new MapAccessor());
309-
context.setRootObject(map);
310-
return context;
307+
return SimpleEvaluationContext.forPropertyAccessors(new MapAccessor())
308+
.withRootObject(map).build();
311309
}
312310

313311
@Override

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfigurationTests.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,26 @@ public class ErrorMvcAutoConfigurationTests {
4545
public OutputCapture outputCapture = new OutputCapture();
4646

4747
@Test
48-
public void testDefaultViewWithResponseAlreadyCommitted() {
48+
public void renderContainsViewWithExceptionDetails() throws Exception {
4949
this.contextRunner.run((context) -> {
5050
View errorView = context.getBean("error", View.class);
5151
ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class);
52-
DispatcherServletWebRequest webRequest = createCommittedWebRequest(
53-
new IllegalStateException("Exception message"));
52+
DispatcherServletWebRequest webRequest = createWebRequest(
53+
new IllegalStateException("Exception message"), false);
54+
errorView.render(errorAttributes.getErrorAttributes(webRequest, true),
55+
webRequest.getRequest(), webRequest.getResponse());
56+
assertThat(((MockHttpServletResponse) webRequest.getResponse())
57+
.getContentAsString()).contains("<div>Exception message</div>");
58+
});
59+
}
60+
61+
@Test
62+
public void renderWhenAlreadyCommittedLogsMessage() {
63+
this.contextRunner.run((context) -> {
64+
View errorView = context.getBean("error", View.class);
65+
ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class);
66+
DispatcherServletWebRequest webRequest = createWebRequest(
67+
new IllegalStateException("Exception message"), true);
5468
errorView.render(errorAttributes.getErrorAttributes(webRequest, true),
5569
webRequest.getRequest(), webRequest.getResponse());
5670
assertThat(this.outputCapture.toString())
@@ -61,7 +75,8 @@ public void testDefaultViewWithResponseAlreadyCommitted() {
6175
});
6276
}
6377

64-
protected DispatcherServletWebRequest createCommittedWebRequest(Exception ex) {
78+
private DispatcherServletWebRequest createWebRequest(Exception ex,
79+
boolean committed) {
6580
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/path");
6681
MockHttpServletResponse response = new MockHttpServletResponse();
6782
DispatcherServletWebRequest webRequest = new DispatcherServletWebRequest(request,
@@ -70,9 +85,9 @@ protected DispatcherServletWebRequest createCommittedWebRequest(Exception ex) {
7085
RequestAttributes.SCOPE_REQUEST);
7186
webRequest.setAttribute("javax.servlet.error.request_uri", "/path",
7287
RequestAttributes.SCOPE_REQUEST);
73-
response.setCommitted(true);
74-
response.setOutputStreamAccessAllowed(false);
75-
response.setWriterAccessAllowed(false);
88+
response.setCommitted(committed);
89+
response.setOutputStreamAccessAllowed(!committed);
90+
response.setWriterAccessAllowed(!committed);
7691
return webRequest;
7792
}
7893

0 commit comments

Comments
 (0)