Polish
This commit is contained in:
parent
81f876aac5
commit
143536f72d
|
|
@ -24,6 +24,7 @@ import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.http.converter.FormHttpMessageConverter;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
||||||
import org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter;
|
import org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter;
|
||||||
|
|
@ -155,15 +156,14 @@ public class HttpMessageConverters implements Iterable<HttpMessageConverter<?>>
|
||||||
formConverter.setPartConverters(combinedConverters);
|
formConverter.setPartConverters(combinedConverters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private List<HttpMessageConverter<?>> extractPartConverters(
|
private List<HttpMessageConverter<?>> extractPartConverters(
|
||||||
AllEncompassingFormHttpMessageConverter formConverter) {
|
FormHttpMessageConverter formConverter) {
|
||||||
Field field = ReflectionUtils.findField(
|
Field field = ReflectionUtils.findField(FormHttpMessageConverter.class,
|
||||||
AllEncompassingFormHttpMessageConverter.class, "partConverters");
|
"partConverters");
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
@SuppressWarnings("unchecked")
|
return (List<HttpMessageConverter<?>>) ReflectionUtils.getField(field,
|
||||||
List<HttpMessageConverter<?>> partConverters = (List<HttpMessageConverter<?>>) ReflectionUtils
|
formConverter);
|
||||||
.getField(field, formConverter);
|
|
||||||
return partConverters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -172,14 +172,16 @@ public class BasicErrorControllerIntegrationTests {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void testRequestBodyValidationForMachineClient() throws Exception {
|
public void testRequestBodyValidationForMachineClient() throws Exception {
|
||||||
load();
|
load();
|
||||||
RequestEntity request = RequestEntity.post(URI.create(createUrl("/bodyValidation")))
|
RequestEntity request = RequestEntity
|
||||||
|
.post(URI.create(createUrl("/bodyValidation")))
|
||||||
.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();
|
||||||
assertThat(resp, containsString("Error count: 1"));
|
assertThat(resp, containsString("Error count: 1"));
|
||||||
assertThat(resp, containsString("errors=[{"));
|
assertThat(resp, containsString("errors=[{"));
|
||||||
assertThat(resp, containsString("codes=["));
|
assertThat(resp, containsString("codes=["));
|
||||||
assertThat(resp, containsString("org.springframework.web.bind.MethodArgumentNotValidException"));
|
assertThat(resp, containsString(
|
||||||
|
"org.springframework.web.bind.MethodArgumentNotValidException"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertErrorAttributes(Map<?, ?> content, String status, String error,
|
private void assertErrorAttributes(Map<?, ?> content, String status, String error,
|
||||||
|
|
@ -278,7 +280,7 @@ public class BasicErrorControllerIntegrationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DummyBody {
|
static class DummyBody {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String content;
|
private String content;
|
||||||
|
|
@ -290,6 +292,7 @@ public class BasicErrorControllerIntegrationTests {
|
||||||
public void setContent(String content) {
|
public void setContent(String content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,8 @@ public class DefaultErrorAttributesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extractMethodArgumentNotValidExceptionBindingResultErrors() throws Exception {
|
public void extractMethodArgumentNotValidExceptionBindingResultErrors()
|
||||||
|
throws Exception {
|
||||||
BindingResult bindingResult = new MapBindingResult(
|
BindingResult bindingResult = new MapBindingResult(
|
||||||
Collections.singletonMap("a", "b"), "objectName");
|
Collections.singletonMap("a", "b"), "objectName");
|
||||||
bindingResult.addError(new ObjectError("c", "d"));
|
bindingResult.addError(new ObjectError("c", "d"));
|
||||||
|
|
|
||||||
|
|
@ -634,8 +634,8 @@ Nested POJO properties can also be created (so a setter is not mandatory) if the
|
||||||
default constructor, or a constructor accepting a single value that can be coerced from
|
default constructor, or a constructor accepting a single value that can be coerced from
|
||||||
String. Some people use Project Lombok to add getters and setters automatically.
|
String. Some people use Project Lombok to add getters and setters automatically.
|
||||||
|
|
||||||
TIP: Contrary to `@Value`, SpEL expressions are not evaluated prior to injecting a value
|
NOTE: Contrary to `@Value`, SpEL expressions are not evaluated prior to injecting a value
|
||||||
in the relevant `@ConfigurationProperties` bean as said value is usually externalized.
|
in the relevant `@ConfigurationProperties` bean.
|
||||||
|
|
||||||
The `@EnableConfigurationProperties` annotation is automatically applied to your project
|
The `@EnableConfigurationProperties` annotation is automatically applied to your project
|
||||||
so that any beans annotated with `@ConfigurationProperties` will be configured from the
|
so that any beans annotated with `@ConfigurationProperties` will be configured from the
|
||||||
|
|
@ -962,7 +962,7 @@ NOTE: Logback does not have a `FATAL` level (it is mapped to `ERROR`)
|
||||||
=== Console output
|
=== Console output
|
||||||
The default log configuration will echo messages to the console as they are written. By
|
The default log configuration will echo messages to the console as they are written. By
|
||||||
default `ERROR`, `WARN` and `INFO` level messages are logged. You can also enable a
|
default `ERROR`, `WARN` and `INFO` level messages are logged. You can also enable a
|
||||||
"debug" mode by starting your application with a `--debug` flag.
|
"`debug`" mode by starting your application with a `--debug` flag.
|
||||||
|
|
||||||
[indent=0]
|
[indent=0]
|
||||||
----
|
----
|
||||||
|
|
@ -972,8 +972,8 @@ default `ERROR`, `WARN` and `INFO` level messages are logged. You can also enabl
|
||||||
NOTE: you can also specify `debug=true` in your `application.properties`.
|
NOTE: you can also specify `debug=true` in your `application.properties`.
|
||||||
|
|
||||||
When the debug mode is enabled, a selection of core loggers (embedded container, Hibernate
|
When the debug mode is enabled, a selection of core loggers (embedded container, Hibernate
|
||||||
and Spring) are configured to output more information. In other words, enabling the debug
|
and Spring) are configured to output more information. Enabling the debug mode does _not_
|
||||||
mode does not configure your application log messages with `DEBUG` level.
|
configure your application log all messages with `DEBUG` level.
|
||||||
|
|
||||||
If your terminal supports ANSI, color output will be used to aid readability. You can set
|
If your terminal supports ANSI, color output will be used to aid readability. You can set
|
||||||
`spring.output.ansi.enabled` to a
|
`spring.output.ansi.enabled` to a
|
||||||
|
|
@ -1452,7 +1452,6 @@ particular controller and/or exception type.
|
||||||
|
|
||||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||||
----
|
----
|
||||||
|
|
||||||
@ControllerAdvice(basePackageClasses = FooController.class)
|
@ControllerAdvice(basePackageClasses = FooController.class)
|
||||||
public class FooControllerAdvice extends ResponseEntityExceptionHandler {
|
public class FooControllerAdvice extends ResponseEntityExceptionHandler {
|
||||||
|
|
||||||
|
|
@ -1474,9 +1473,9 @@ particular controller and/or exception type.
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
In the example above, if `YourException` is thrown by a controller defined in the same package
|
In the example above, if `YourException` is thrown by a controller defined in the same
|
||||||
as `FooController`, a json representation of the `CustomerErrorType` POJO will be used instead
|
package as `FooController`, a json representation of the `CustomerErrorType` POJO will be
|
||||||
of the `ErrorAttributes` representation.
|
used instead of the `ErrorAttributes` representation.
|
||||||
|
|
||||||
If you want more specific error pages for some conditions, the embedded servlet containers
|
If you want more specific error pages for some conditions, the embedded servlet containers
|
||||||
support a uniform Java DSL for customizing the error handling. Assuming that you have a
|
support a uniform Java DSL for customizing the error handling. Assuming that you have a
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue