Browse Source

Ensure status in ErrorPageFilter defaults to 200

Fixes gh-1369. Note that this is caused by the ErrorPageFilter, so
only a problem when deployed as a WAR.
pull/1487/merge
Dave Syer 12 years ago
parent
commit
2fae4afe95
  1. 9
      spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java
  2. 1
      spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java
  3. 15
      spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java

9
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java

@ -93,10 +93,17 @@ public class MetricFilterAutoConfiguration { @@ -93,10 +93,17 @@ public class MetricFilterAutoConfiguration {
int status = getStatus(response);
Object bestMatchingPattern = request
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
HttpStatus httpStatus = HttpStatus.OK;
try {
httpStatus = HttpStatus.valueOf(status);
}
catch (Exception e) {
// not convertible
}
if (bestMatchingPattern != null) {
suffix = bestMatchingPattern.toString().replaceAll("[{}]", "-");
}
else if (HttpStatus.valueOf(status).is4xxClientError()) {
else if (httpStatus.is4xxClientError()) {
suffix = UNKNOWN_PATH_SUFFIX;
}
String gaugeKey = getKey("response" + suffix);

1
spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java

@ -239,6 +239,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple @@ -239,6 +239,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
public ErrorWrapperResponse(HttpServletResponse response) {
super(response);
this.status = response.getStatus();
}
@Override

15
spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java

@ -205,6 +205,21 @@ public class ErrorPageFilterTests { @@ -205,6 +205,21 @@ public class ErrorPageFilterTests {
assertTrue(this.response.isCommitted());
}
@Test
public void statusCode() throws Exception {
this.chain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
assertThat(((HttpServletResponse) response).getStatus(), equalTo(200));
super.doFilter(request, response);
}
};
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus(),
equalTo(200));
}
@Test
public void subClassExceptionError() throws Exception {
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));

Loading…
Cancel
Save