Restore trace request param behaviour with error controller

This commits restores the behaviour of Spring Boot 1.x with regards to
the "trace" request param used to add the stacktrace to the model.

This was inadvertently changed so that the stacktrace would be added
if the parameter wasn't set.

Closes gh-14171
pull/14268/head
Stephane Nicoll 6 years ago
parent 9938d1f4b6
commit 5e7be50265

@ -76,6 +76,9 @@ public abstract class AbstractErrorController implements ErrorController {
protected boolean getTraceParameter(HttpServletRequest request) {
String parameter = request.getParameter("trace");
if (parameter == null) {
return false;
}
return !"false".equalsIgnoreCase(parameter);
}

@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -94,15 +95,30 @@ public class BasicErrorControllerIntegrationTests {
}
@Test
public void testErrorForMachineClientTraceParamTrue() {
errorForMachineClientOnTraceParam(() -> createUrl("?trace=true"), true);
}
@Test
public void testErrorForMachineClientTraceParamFalse() {
errorForMachineClientOnTraceParam(() -> createUrl("?trace=false"), false);
}
@Test
public void testErrorForMachineClientTraceParamAbsent() {
errorForMachineClientOnTraceParam(() -> createUrl(""), false);
}
@SuppressWarnings("rawtypes")
public void testErrorForMachineClientTraceParamStacktrace() {
private void errorForMachineClientOnTraceParam(Supplier<String> url,
boolean expectedTrace) {
load("--server.error.include-exception=true",
"--server.error.include-stacktrace=on-trace-param");
ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity(createUrl("?trace=true"), Map.class);
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(url.get(),
Map.class);
assertErrorAttributes(entity.getBody(), "500", "Internal Server Error",
IllegalStateException.class, "Expected!", "/");
assertThat(entity.getBody().containsKey("trace")).isTrue();
assertThat(entity.getBody().containsKey("trace")).isEqualTo(expectedTrace);
}
@Test

Loading…
Cancel
Save