Delete ErrorProperties.IncludeStacktrace

Closes gh-21286
This commit is contained in:
Stephane Nicoll
2020-12-24 09:33:48 +01:00
parent 1a2577a07e
commit e4618cfb8d
8 changed files with 10 additions and 51 deletions

View File

@@ -75,13 +75,11 @@ public class ManagementErrorEndpoint {
return options;
}
@SuppressWarnings("deprecation")
private boolean includeStackTrace(ServletWebRequest request) {
switch (this.errorProperties.getIncludeStacktrace()) {
case ALWAYS:
return true;
case ON_PARAM:
case ON_TRACE_PARAM:
return getBooleanParameter(request, "trace");
default:
return false;

View File

@@ -61,7 +61,7 @@ class ManagementErrorEndpointTests {
@Test
void errorResponseAlwaysDetails() {
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ALWAYS);
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ALWAYS);
this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ALWAYS);
this.request.addParameter("trace", "false");
this.request.addParameter("message", "false");
@@ -74,7 +74,7 @@ class ManagementErrorEndpointTests {
@Test
void errorResponseParamsAbsent() {
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ON_PARAM);
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ON_PARAM);
this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ON_PARAM);
ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(this.errorAttributes, this.errorProperties);
Map<String, Object> response = endpoint.invoke(new ServletWebRequest(this.request));
@@ -84,7 +84,7 @@ class ManagementErrorEndpointTests {
@Test
void errorResponseParamsTrue() {
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ON_PARAM);
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ON_PARAM);
this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ON_PARAM);
this.request.addParameter("trace", "true");
this.request.addParameter("message", "true");
@@ -97,7 +97,7 @@ class ManagementErrorEndpointTests {
@Test
void errorResponseParamsFalse() {
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeStacktrace.ON_PARAM);
this.errorProperties.setIncludeStacktrace(ErrorProperties.IncludeAttribute.ON_PARAM);
this.errorProperties.setIncludeMessage(ErrorProperties.IncludeAttribute.ON_PARAM);
this.request.addParameter("trace", "false");
this.request.addParameter("message", "false");

View File

@@ -43,7 +43,7 @@ public class ErrorProperties {
/**
* When to include the "trace" attribute.
*/
private IncludeStacktrace includeStacktrace = IncludeStacktrace.NEVER;
private IncludeAttribute includeStacktrace = IncludeAttribute.NEVER;
/**
* When to include "message" attribute.
@@ -73,11 +73,11 @@ public class ErrorProperties {
this.includeException = includeException;
}
public IncludeStacktrace getIncludeStacktrace() {
public IncludeAttribute getIncludeStacktrace() {
return this.includeStacktrace;
}
public void setIncludeStacktrace(IncludeStacktrace includeStacktrace) {
public void setIncludeStacktrace(IncludeAttribute includeStacktrace) {
this.includeStacktrace = includeStacktrace;
}
@@ -101,34 +101,6 @@ public class ErrorProperties {
return this.whitelabel;
}
/**
* Include Stacktrace attribute options.
*/
public enum IncludeStacktrace {
/**
* Never add stacktrace information.
*/
NEVER,
/**
* Always add stacktrace information.
*/
ALWAYS,
/**
* Add error attribute when the appropriate request parameter is "true".
*/
ON_PARAM,
/**
* Add stacktrace information when the "trace" request parameter is "true".
*/
@Deprecated // since 2.3.0 in favor of {@link #ON_PARAM}
ON_TRACE_PARAM;
}
/**
* Include error attributes options.
*/

View File

@@ -29,7 +29,7 @@ import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeStacktrace;
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog;
import org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Remoteip;
@@ -292,7 +292,7 @@ public class TomcatWebServerFactoryCustomizer
}
private void customizeErrorReportValve(ErrorProperties error, ConfigurableTomcatWebServerFactory factory) {
if (error.getIncludeStacktrace() == IncludeStacktrace.NEVER) {
if (error.getIncludeStacktrace() == IncludeAttribute.NEVER) {
factory.addContextCustomizers((context) -> {
ErrorReportValve valve = new ErrorReportValve();
valve.setShowServerInfo(false);

View File

@@ -187,13 +187,11 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
* @param produces the media type produced (or {@code MediaType.ALL})
* @return if the stacktrace attribute should be included
*/
@SuppressWarnings("deprecation")
protected boolean isIncludeStackTrace(ServerRequest request, MediaType produces) {
switch (this.errorProperties.getIncludeStacktrace()) {
case ALWAYS:
return true;
case ON_PARAM:
case ON_TRACE_PARAM:
return isTraceEnabled(request);
default:
return false;

View File

@@ -136,13 +136,11 @@ public class BasicErrorController extends AbstractErrorController {
* @param produces the media type produced (or {@code MediaType.ALL})
* @return if the stacktrace attribute should be included
*/
@SuppressWarnings("deprecation")
protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType produces) {
switch (getErrorProperties().getIncludeStacktrace()) {
case ALWAYS:
return true;
case ON_PARAM:
case ON_TRACE_PARAM:
return getTraceParameter(request);
default:
return false;

View File

@@ -93,13 +93,6 @@ class BasicErrorControllerIntegrationTests {
assertThat(entity.getBody().containsKey("trace")).isFalse();
}
@Test
void testErrorForMachineClientWithTraceParamsTrue() {
load("--server.error.include-exception=true", "--server.error.include-stacktrace=on-trace-param",
"--server.error.include-message=on-param");
exceptionWithStackTraceAndMessage("?trace=true&message=true");
}
@Test
void testErrorForMachineClientWithParamsTrue() {
load("--server.error.include-exception=true", "--server.error.include-stacktrace=on-param",

View File

@@ -107,7 +107,7 @@ class DevToolPropertiesIntegrationTests {
this.context = getContext(application::run);
ConfigurableEnvironment environment = this.context.getEnvironment();
String includeStackTrace = environment.getProperty("server.error.include-stacktrace");
assertThat(includeStackTrace).isEqualTo(ErrorProperties.IncludeStacktrace.ALWAYS.toString());
assertThat(includeStackTrace).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString());
String includeMessage = environment.getProperty("server.error.include-message");
assertThat(includeMessage).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString());
}