Merge branch '1.5.x'
This commit is contained in:
commit
6fb4fba43a
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -33,6 +33,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,16 +83,6 @@ public class BasicErrorController extends AbstractErrorController {
|
|||||||
return this.errorProperties.getPath();
|
return this.errorProperties.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(produces = { "application/xml", "text/xml", "application/json",
|
|
||||||
"application/*+xml", "application/*+json" })
|
|
||||||
public ResponseEntity<Map<String, Object>> errorStructured(
|
|
||||||
HttpServletRequest request) {
|
|
||||||
Map<String, Object> body = getErrorAttributes(request,
|
|
||||||
isIncludeStackTrace(request, MediaType.ALL));
|
|
||||||
HttpStatus status = getStatus(request);
|
|
||||||
return new ResponseEntity<>(body, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(produces = "text/html")
|
@RequestMapping(produces = "text/html")
|
||||||
public ModelAndView errorHtml(HttpServletRequest request,
|
public ModelAndView errorHtml(HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
@ -104,20 +95,12 @@ public class BasicErrorController extends AbstractErrorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping
|
@RequestMapping
|
||||||
public ResponseEntity<String> errorText(HttpServletRequest request) {
|
@ResponseBody
|
||||||
Map<String, Object> attributes = getErrorAttributes(request,
|
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
|
||||||
isIncludeStackTrace(request, MediaType.TEXT_PLAIN));
|
Map<String, Object> body = getErrorAttributes(request,
|
||||||
int padding = 0;
|
isIncludeStackTrace(request, MediaType.ALL));
|
||||||
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
|
|
||||||
padding = Math.max(padding, entry.getKey().length());
|
|
||||||
}
|
|
||||||
StringBuilder body = new StringBuilder();
|
|
||||||
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
|
|
||||||
body.append(String.format("%-" + padding + "s : %s%n", entry.getKey(),
|
|
||||||
entry.getValue()));
|
|
||||||
}
|
|
||||||
HttpStatus status = getStatus(request);
|
HttpStatus status = getStatus(request);
|
||||||
return new ResponseEntity<>(body.toString(), status);
|
return new ResponseEntity<>(body, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,7 +169,6 @@ public class BasicErrorControllerIntegrationTests {
|
|||||||
load("--server.error.include-exception=true");
|
load("--server.error.include-exception=true");
|
||||||
RequestEntity request = RequestEntity
|
RequestEntity request = RequestEntity
|
||||||
.post(URI.create(createUrl("/bodyValidation")))
|
.post(URI.create(createUrl("/bodyValidation")))
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON).body("{}");
|
.contentType(MediaType.APPLICATION_JSON).body("{}");
|
||||||
ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
|
ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
|
||||||
String resp = entity.getBody().toString();
|
String resp = entity.getBody().toString();
|
||||||
@ -190,18 +189,6 @@ public class BasicErrorControllerIntegrationTests {
|
|||||||
assertThat(resp).doesNotContain("org.springframework.validation.BindException");
|
assertThat(resp).doesNotContain("org.springframework.validation.BindException");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRequestBodyValidationForText() {
|
|
||||||
load();
|
|
||||||
RequestEntity<Void> request = RequestEntity.post(URI.create(createUrl("/")))
|
|
||||||
.accept(MediaType.TEXT_PLAIN).build();
|
|
||||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(request,
|
|
||||||
String.class);
|
|
||||||
String resp = entity.getBody().toString();
|
|
||||||
assertThat(resp).contains("status");
|
|
||||||
assertThat(resp).contains("error");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConventionTemplateMapping() {
|
public void testConventionTemplateMapping() {
|
||||||
load();
|
load();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user