Skip to content

Commit

Permalink
Delete ErrorProperties.IncludeStacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Dec 24, 2020
1 parent 1a2577a commit e4618cf
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ private ErrorAttributeOptions getErrorAttributeOptions(ServletWebRequest request
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void errorResponseNeverDetails() {

@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");
Expand All @@ -74,7 +74,7 @@ void errorResponseAlwaysDetails() {

@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));
Expand All @@ -84,7 +84,7 @@ void errorResponseParamsAbsent() {

@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");
Expand All @@ -97,7 +97,7 @@ void errorResponseParamsTrue() {

@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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -73,11 +73,11 @@ public void setIncludeException(boolean includeException) {
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;
}

Expand All @@ -101,34 +101,6 @@ public Whitelabel getWhitelabel() {
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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;
Expand Down Expand Up @@ -292,7 +292,7 @@ private void customizeStaticResources(ConfigurableTomcatWebServerFactory factory
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,11 @@ protected ErrorAttributeOptions getErrorAttributeOptions(ServerRequest request,
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,11 @@ protected ErrorAttributeOptions getErrorAttributeOptions(HttpServletRequest requ
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ void testErrorForMachineClientDefault() {
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void postProcessEnablesIncludeStackTraceProperty() throws Exception {
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());
}
Expand Down

0 comments on commit e4618cf

Please sign in to comment.