Skip to content

Commit dd08660

Browse files
committed
Revert "Add text/plain error response support"
This reverts commit 23892e3.
1 parent 7242dda commit dd08660

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.stereotype.Controller;
3232
import org.springframework.util.Assert;
3333
import org.springframework.web.bind.annotation.RequestMapping;
34+
import org.springframework.web.bind.annotation.ResponseBody;
3435
import org.springframework.web.servlet.ModelAndView;
3536

3637
/**
@@ -81,16 +82,6 @@ public String getErrorPath() {
8182
return this.errorProperties.getPath();
8283
}
8384

84-
@RequestMapping(produces = { "application/xml", "text/xml", "application/json",
85-
"application/*+xml", "application/*+json" })
86-
public ResponseEntity<Map<String, Object>> errorStructured(
87-
HttpServletRequest request) {
88-
Map<String, Object> body = getErrorAttributes(request,
89-
isIncludeStackTrace(request, MediaType.ALL));
90-
HttpStatus status = getStatus(request);
91-
return new ResponseEntity<Map<String, Object>>(body, status);
92-
}
93-
9485
@RequestMapping(produces = "text/html")
9586
public ModelAndView errorHtml(HttpServletRequest request,
9687
HttpServletResponse response) {
@@ -103,20 +94,12 @@ public ModelAndView errorHtml(HttpServletRequest request,
10394
}
10495

10596
@RequestMapping
106-
public ResponseEntity<String> errorText(HttpServletRequest request) {
107-
Map<String, Object> attributes = getErrorAttributes(request,
108-
isIncludeStackTrace(request, MediaType.TEXT_PLAIN));
109-
int padding = 0;
110-
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
111-
padding = Math.max(padding, entry.getKey().length());
112-
}
113-
StringBuffer body = new StringBuffer();
114-
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
115-
body.append(String.format("%-" + padding + "s : %s%n", entry.getKey(),
116-
entry.getValue()));
117-
}
97+
@ResponseBody
98+
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
99+
Map<String, Object> body = getErrorAttributes(request,
100+
isIncludeStackTrace(request, MediaType.ALL));
118101
HttpStatus status = getStatus(request);
119-
return new ResponseEntity<String>(body.toString(), status);
102+
return new ResponseEntity<Map<String, Object>>(body, status);
120103
}
121104

122105
/**

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ public void testRequestBodyValidationForMachineClient() throws Exception {
158158
load();
159159
RequestEntity request = RequestEntity
160160
.post(URI.create(createUrl("/bodyValidation")))
161-
.accept(MediaType.APPLICATION_JSON)
162161
.contentType(MediaType.APPLICATION_JSON).body("{}");
163162
ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
164163
String resp = entity.getBody().toString();
@@ -168,19 +167,6 @@ public void testRequestBodyValidationForMachineClient() throws Exception {
168167
assertThat(resp).contains(MethodArgumentNotValidException.class.getName());
169168
}
170169

171-
@Test
172-
public void testRequestBodyValidationForText() throws Exception {
173-
load();
174-
RequestEntity<Void> request = RequestEntity.post(URI.create(createUrl("/")))
175-
.accept(MediaType.TEXT_PLAIN).build();
176-
ResponseEntity<String> entity = new TestRestTemplate().exchange(request,
177-
String.class);
178-
String resp = entity.getBody().toString();
179-
assertThat(resp).contains("status");
180-
assertThat(resp).contains("error");
181-
assertThat(resp).contains(IllegalStateException.class.getName());
182-
}
183-
184170
@Test
185171
public void testConventionTemplateMapping() throws Exception {
186172
load();

0 commit comments

Comments
 (0)