This commit is contained in:
Phillip Webb
2018-01-18 23:10:28 -08:00
parent 6d93573db0
commit f3379668ac
51 changed files with 139 additions and 158 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.

View File

@@ -62,7 +62,6 @@ public final class JettyCustomizer {
if (jettyProperties.getMaxHttpPostSize() > 0) {
customizeMaxHttpPostSize(factory, jettyProperties.getMaxHttpPostSize());
}
if (serverProperties.getConnectionTimeout() != null) {
customizeConnectionTimeout(factory, serverProperties.getConnectionTimeout());
}
@@ -176,4 +175,5 @@ public final class JettyCustomizer {
server.setRequestLog(log);
});
}
}

View File

@@ -197,7 +197,6 @@ public final class TomcatCustomizer {
private static void customizeAccessLog(ServerProperties.Tomcat tomcatProperties,
ConfigurableTomcatWebServerFactory factory) {
AccessLogValve valve = new AccessLogValve();
valve.setPattern(tomcatProperties.getAccesslog().getPattern());
valve.setDirectory(tomcatProperties.getAccesslog().getDirectory());

View File

@@ -38,7 +38,6 @@ public final class UndertowCustomizer {
public static void customizeUndertow(ServerProperties serverProperties,
Environment environment, ConfigurableUndertowWebServerFactory factory) {
ServerProperties.Undertow undertowProperties = serverProperties.getUndertow();
ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties
.getAccesslog();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.

View File

@@ -327,6 +327,7 @@ public class WebMvcProperties {
public void setParameterName(String parameterName) {
this.parameterName = parameterName;
}
}
public static class PathMatch {
@@ -360,6 +361,7 @@ public class WebMvcProperties {
public void setUseRegisteredSuffixPattern(boolean useRegisteredSuffixPattern) {
this.useRegisteredSuffixPattern = useRegisteredSuffixPattern;
}
}
public enum LocaleResolver {

View File

@@ -238,22 +238,21 @@ public class ErrorMvcAutoConfiguration {
if (response.getContentType() == null) {
response.setContentType(getContentType());
}
PlaceholderResolver resolver = new ExpressionResolver(getExpressions(), model);
PlaceholderResolver resolver = new ExpressionResolver(getExpressions(),
model);
String result = this.helper.replacePlaceholders(this.template, resolver);
response.getWriter().append(result);
}
private String getMessage(Map<String, ?> model) {
StringBuilder builder = new StringBuilder();
builder.append("Cannot render error page for request [")
.append(model.get("path")).append("]");
Object path = model.get("path");
String message = "Cannot render error page for request [" + path + "]";
if (model.get("message") != null) {
builder.append(" and exception [").append(model.get("message"))
.append("]");
message += " and exception [" + model.get("message") + "]";
}
return builder.append("] as the response has already been committed.")
.append("As a result, the response may have the wrong status code.")
.toString();
message += " as the response has already been committed.";
message += " As a result, the response may have the wrong status code.";
return message;
}
private Map<String, Expression> getExpressions() {

View File

@@ -25,12 +25,11 @@ import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.handler.DispatcherServletWebRequest;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ErrorMvcAutoConfiguration}.
@@ -50,26 +49,31 @@ public class ErrorMvcAutoConfigurationTests {
this.contextRunner.run((context) -> {
View errorView = context.getBean("error", View.class);
ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class);
DispatcherServletWebRequest webRequest =
createCommittedWebRequest(new IllegalStateException("Exception message"));
DispatcherServletWebRequest webRequest = createCommittedWebRequest(
new IllegalStateException("Exception message"));
errorView.render(errorAttributes.getErrorAttributes(webRequest, true),
webRequest.getRequest(), webRequest.getResponse());
this.outputCapture.expect(allOf(
containsString("Cannot render error page for request [/path]" +
" and exception [Exception message]] as the response has already been committed."),
containsString("As a result, the response may have the wrong status code.")));
assertThat(this.outputCapture.toString())
.contains("Cannot render error page for request [/path] "
+ "and exception [Exception message] as the response has "
+ "already been committed. As a result, the response may "
+ "have the wrong status code.");
});
}
protected DispatcherServletWebRequest createCommittedWebRequest(Exception e) {
protected DispatcherServletWebRequest createCommittedWebRequest(Exception ex) {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/path");
MockHttpServletResponse response = new MockHttpServletResponse();
DispatcherServletWebRequest webRequest = new DispatcherServletWebRequest(request, response);
webRequest.setAttribute("javax.servlet.error.exception", e, WebRequest.SCOPE_REQUEST);
webRequest.setAttribute("javax.servlet.error.request_uri", "/path", WebRequest.SCOPE_REQUEST);
DispatcherServletWebRequest webRequest = new DispatcherServletWebRequest(request,
response);
webRequest.setAttribute("javax.servlet.error.exception", ex,
RequestAttributes.SCOPE_REQUEST);
webRequest.setAttribute("javax.servlet.error.request_uri", "/path",
RequestAttributes.SCOPE_REQUEST);
response.setCommitted(true);
response.setOutputStreamAccessAllowed(false);
response.setWriterAccessAllowed(false);
return webRequest;
}
}