From 7242ddae3cc008488b6ae0bc38dc96570b271005 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 4 Apr 2018 12:04:47 -0700 Subject: [PATCH 1/2] Polish --- .../sample/data/jpa/service/HotelRepositoryIntegrationTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java index ead0f9955ea..842d395b195 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java @@ -45,6 +45,7 @@ public class HotelRepositoryIntegrationTests { @Autowired CityRepository cityRepository; + @Autowired HotelRepository repository; From dd0866000f5159ee6579d9b031d50a2abf2ccf35 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 4 Apr 2018 12:06:13 -0700 Subject: [PATCH 2/2] Revert "Add text/plain error response support" This reverts commit 23892e33d6ed73a130850d27342dba631b9fb8d7. --- .../web/BasicErrorController.java | 29 ++++--------------- .../BasicErrorControllerIntegrationTests.java | 14 --------- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java index 0e008ecfbf4..755dfa7a73e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java @@ -31,6 +31,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; /** @@ -81,16 +82,6 @@ public class BasicErrorController extends AbstractErrorController { return this.errorProperties.getPath(); } - @RequestMapping(produces = { "application/xml", "text/xml", "application/json", - "application/*+xml", "application/*+json" }) - public ResponseEntity> errorStructured( - HttpServletRequest request) { - Map body = getErrorAttributes(request, - isIncludeStackTrace(request, MediaType.ALL)); - HttpStatus status = getStatus(request); - return new ResponseEntity>(body, status); - } - @RequestMapping(produces = "text/html") public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) { @@ -103,20 +94,12 @@ public class BasicErrorController extends AbstractErrorController { } @RequestMapping - public ResponseEntity errorText(HttpServletRequest request) { - Map attributes = getErrorAttributes(request, - isIncludeStackTrace(request, MediaType.TEXT_PLAIN)); - int padding = 0; - for (Map.Entry entry : attributes.entrySet()) { - padding = Math.max(padding, entry.getKey().length()); - } - StringBuffer body = new StringBuffer(); - for (Map.Entry entry : attributes.entrySet()) { - body.append(String.format("%-" + padding + "s : %s%n", entry.getKey(), - entry.getValue())); - } + @ResponseBody + public ResponseEntity> error(HttpServletRequest request) { + Map body = getErrorAttributes(request, + isIncludeStackTrace(request, MediaType.ALL)); HttpStatus status = getStatus(request); - return new ResponseEntity(body.toString(), status); + return new ResponseEntity>(body, status); } /** diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java index b70ba9fc1f6..3e6012e3ba0 100755 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java @@ -158,7 +158,6 @@ public class BasicErrorControllerIntegrationTests { load(); RequestEntity request = RequestEntity .post(URI.create(createUrl("/bodyValidation"))) - .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON).body("{}"); ResponseEntity entity = new TestRestTemplate().exchange(request, Map.class); String resp = entity.getBody().toString(); @@ -168,19 +167,6 @@ public class BasicErrorControllerIntegrationTests { assertThat(resp).contains(MethodArgumentNotValidException.class.getName()); } - @Test - public void testRequestBodyValidationForText() throws Exception { - load(); - RequestEntity request = RequestEntity.post(URI.create(createUrl("/"))) - .accept(MediaType.TEXT_PLAIN).build(); - ResponseEntity entity = new TestRestTemplate().exchange(request, - String.class); - String resp = entity.getBody().toString(); - assertThat(resp).contains("status"); - assertThat(resp).contains("error"); - assertThat(resp).contains(IllegalStateException.class.getName()); - } - @Test public void testConventionTemplateMapping() throws Exception { load();