diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java index 5a1fc50554d..ea5baf769e7 100644 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -20,8 +20,10 @@ import java.util.Date; import java.util.Map; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; @Controller public class WelcomeController { @@ -36,4 +38,29 @@ public class WelcomeController { return "welcome"; } + @RequestMapping("/serviceUnavailable") + public String ServiceUnavailable() { + throw new ServiceUnavailableException(); + } + + @RequestMapping("/bang") + public String bang() { + throw new RuntimeException("Boom"); + } + + @RequestMapping("/insufficientStorage") + public String insufficientStorage() { + throw new InsufficientStorageException(); + } + + @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) + private static class ServiceUnavailableException extends RuntimeException { + + } + + @ResponseStatus(HttpStatus.INSUFFICIENT_STORAGE) + private static class InsufficientStorageException extends RuntimeException { + + } + } diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/503.html b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/503.html new file mode 100644 index 00000000000..d1634ee2946 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/503.html @@ -0,0 +1,9 @@ + + + + + + I'm a 503 + + + diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/5xx.html b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/5xx.html new file mode 100644 index 00000000000..8fd8ab798a7 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/5xx.html @@ -0,0 +1,9 @@ + + + + + + I'm a 5xx + + + diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/error/507.html b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/error/507.html new file mode 100644 index 00000000000..d96bb229424 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/error/507.html @@ -0,0 +1,9 @@ + + + + + + I'm a 507 + + + diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java index 2eeb9638c90..122c9a02687 100644 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java @@ -63,14 +63,48 @@ public class SampleWebMustacheApplicationTests { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity requestEntity = new HttpEntity(headers); - ResponseEntity responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(responseEntity.getBody()) .contains("Something went wrong: 404 Not Found"); } + @Test + public void test503HtmlResource() throws Exception { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity requestEntity = new HttpEntity(headers); + ResponseEntity entity = new TestRestTemplate().exchange( + "http://localhost:" + this.port + "/serviceUnavailable", HttpMethod.GET, + requestEntity, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); + assertThat(entity.getBody()).contains("I'm a 503"); + } + + @Test + public void test5xxHtmlResource() throws Exception { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity requestEntity = new HttpEntity(headers); + ResponseEntity entity = new TestRestTemplate().exchange( + "http://localhost:" + this.port + "/bang", HttpMethod.GET, requestEntity, + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + assertThat(entity.getBody()).contains("I'm a 5xx"); + } + + @Test + public void test507Template() throws Exception { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity requestEntity = new HttpEntity(headers); + ResponseEntity entity = new TestRestTemplate().exchange( + "http://localhost:" + this.port + "/insufficientStorage", HttpMethod.GET, + requestEntity, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INSUFFICIENT_STORAGE); + assertThat(entity.getBody()).contains("I'm a 507"); + } + }