Merge branch '1.5.x'
This commit is contained in:
commit
79ad03b584
|
@ -33,7 +33,6 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,6 +82,16 @@ 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<Map<String, Object>>(body, status);
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(produces = "text/html")
|
@RequestMapping(produces = "text/html")
|
||||||
public ModelAndView errorHtml(HttpServletRequest request,
|
public ModelAndView errorHtml(HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
|
@ -95,12 +104,20 @@ public class BasicErrorController extends AbstractErrorController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping
|
@RequestMapping
|
||||||
@ResponseBody
|
public ResponseEntity<String> errorText(HttpServletRequest request) {
|
||||||
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
|
Map<String, Object> attributes = getErrorAttributes(request,
|
||||||
Map<String, Object> body = getErrorAttributes(request,
|
isIncludeStackTrace(request, MediaType.TEXT_PLAIN));
|
||||||
isIncludeStackTrace(request, MediaType.ALL));
|
int padding = 0;
|
||||||
|
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
|
||||||
|
padding = Math.max(padding, entry.getKey().length());
|
||||||
|
}
|
||||||
|
StringBuffer body = new StringBuffer();
|
||||||
|
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, status);
|
return new ResponseEntity<>(body.toString(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -169,6 +169,7 @@ 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();
|
||||||
|
@ -189,6 +190,18 @@ 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();
|
||||||
|
|
|
@ -92,7 +92,8 @@ public class Handler extends URLStreamHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URLConnection openConnection(URL url) throws IOException {
|
protected URLConnection openConnection(URL url) throws IOException {
|
||||||
if (this.jarFile != null) {
|
if (this.jarFile != null
|
||||||
|
&& url.toString().startsWith(this.jarFile.getUrl().toString())) {
|
||||||
return JarURLConnection.get(url, this.jarFile);
|
return JarURLConnection.get(url, this.jarFile);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -481,4 +481,24 @@ public class JarFileTests {
|
||||||
assertThat(temp.delete()).isTrue();
|
assertThat(temp.delete()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createUrlFromStringWithContextWhenNotFound() throws Exception {
|
||||||
|
// gh-12483
|
||||||
|
JarURLConnection.setUseFastExceptions(true);
|
||||||
|
try {
|
||||||
|
JarFile.registerUrlProtocolHandler();
|
||||||
|
JarFile nested = this.jarFile
|
||||||
|
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||||
|
URL context = nested.getUrl();
|
||||||
|
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat")
|
||||||
|
.openConnection().getInputStream().close();
|
||||||
|
this.thrown.expect(FileNotFoundException.class);
|
||||||
|
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat")
|
||||||
|
.openConnection().getInputStream().close();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
JarURLConnection.setUseFastExceptions(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue