mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-27 17:49:02 +00:00
Polishing contribution
Closes gh-35294
This commit is contained in:
@@ -102,7 +102,8 @@ public class ProblemDetail implements Serializable {
|
||||
|
||||
/**
|
||||
* Setter for the {@link #getType() problem type}.
|
||||
* <p>By default, this is not set. According to the spec, when not present, its value is assumed to be "about:blank"
|
||||
* <p>By default, this is not set. According to the spec, when not present,
|
||||
* the type is assumed to be "about:blank"
|
||||
* @param type the problem type
|
||||
*/
|
||||
public void setType(@Nullable URI type) {
|
||||
|
||||
@@ -85,7 +85,7 @@ final class DefaultErrorResponseBuilder implements ErrorResponse.Builder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorResponse.Builder type(URI type) {
|
||||
public ErrorResponse.Builder type(@Nullable URI type) {
|
||||
this.problemDetail.setType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ErrorResponseException extends NestedRuntimeException implements Er
|
||||
* Set the {@link ProblemDetail#setType(URI) type} field of the response body.
|
||||
* @param type the problem type
|
||||
*/
|
||||
public void setType(URI type) {
|
||||
public void setType(@Nullable URI type) {
|
||||
this.body.setType(type);
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -42,12 +42,11 @@ class ProblemDetailJacksonMixinTests {
|
||||
|
||||
|
||||
@Test
|
||||
void writeStatusAndHeaders() throws Exception {
|
||||
void writeStatusAndHeaders() {
|
||||
ProblemDetail detail = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Missing header");
|
||||
testWrite(detail,
|
||||
"""
|
||||
{
|
||||
"type": "about:blank",
|
||||
"title": "Bad Request",
|
||||
"status": 400,
|
||||
"detail": "Missing header"
|
||||
@@ -55,14 +54,13 @@ class ProblemDetailJacksonMixinTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeCustomProperty() throws Exception {
|
||||
void writeCustomProperty() {
|
||||
ProblemDetail detail = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Missing header");
|
||||
detail.setProperty("host", "abc.org");
|
||||
detail.setProperty("user", null);
|
||||
|
||||
testWrite(detail, """
|
||||
{
|
||||
"type": "about:blank",
|
||||
"title": "Bad Request",
|
||||
"status": 400,
|
||||
"detail": "Missing header",
|
||||
@@ -72,7 +70,7 @@ class ProblemDetailJacksonMixinTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void readCustomProperty() throws Exception {
|
||||
void readCustomProperty() {
|
||||
ProblemDetail detail = this.mapper.readValue("""
|
||||
{
|
||||
"type": "about:blank",
|
||||
@@ -93,7 +91,7 @@ class ProblemDetailJacksonMixinTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void readCustomPropertyFromXml() throws Exception {
|
||||
void readCustomPropertyFromXml() {
|
||||
ObjectMapper xmlMapper = XmlMapper.builder().addMixIn(ProblemDetail.class, ProblemDetailJacksonMixin.class).build();
|
||||
ProblemDetail detail = xmlMapper.readValue("""
|
||||
<problem xmlns="urn:ietf:rfc:7807">
|
||||
@@ -111,7 +109,7 @@ class ProblemDetailJacksonMixinTests {
|
||||
assertThat(detail.getProperties()).containsEntry("host", "abc.org");
|
||||
}
|
||||
|
||||
private void testWrite(ProblemDetail problemDetail, String expected) throws Exception {
|
||||
private void testWrite(ProblemDetail problemDetail, String expected) {
|
||||
String output = this.mapper.writeValueAsString(problemDetail);
|
||||
JSONAssert.assertEquals(expected, output, false);
|
||||
}
|
||||
|
||||
+1
-2
@@ -125,8 +125,7 @@ public class DispatcherHandlerErrorTests {
|
||||
"detail":"No static resource non-existing.",\
|
||||
"instance":"\\/resources\\/non-existing",\
|
||||
"status":404,\
|
||||
"title":"Not Found",\
|
||||
"type":"about:blank"}\
|
||||
"title":"Not Found"}\
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -125,8 +125,7 @@ class RequestMappingExceptionHandlingIntegrationTests extends AbstractRequestMap
|
||||
assertThat(ex.getResponseBodyAsString()).isEqualTo("{" +
|
||||
"\"instance\":\"\\/no-such-handler\"," +
|
||||
"\"status\":404," +
|
||||
"\"title\":\"Not Found\"," +
|
||||
"\"type\":\"about:blank\"}");
|
||||
"\"title\":\"Not Found\"}");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,8 +141,7 @@ class RequestMappingExceptionHandlingIntegrationTests extends AbstractRequestMap
|
||||
"\"detail\":\"Required query parameter 'q' is not present.\"," +
|
||||
"\"instance\":\"\\/missing-request-parameter\"," +
|
||||
"\"status\":400," +
|
||||
"\"title\":\"Bad Request\"," +
|
||||
"\"type\":\"about:blank\"}");
|
||||
"\"title\":\"Bad Request\"}");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -152,8 +152,7 @@ class ResponseBodyResultHandlerTests {
|
||||
{\
|
||||
"status":400,\
|
||||
"instance":"\\/path",\
|
||||
"title":"Bad Request",\
|
||||
"type":"about:blank"\
|
||||
"title":"Bad Request"\
|
||||
}""");
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -244,8 +244,7 @@ class ResponseEntityResultHandlerTests {
|
||||
{\
|
||||
"instance":"\\/path",\
|
||||
"status":400,\
|
||||
"title":"Bad Request",\
|
||||
"type":"about:blank"\
|
||||
"title":"Bad Request"\
|
||||
}""");
|
||||
}
|
||||
|
||||
@@ -265,8 +264,7 @@ class ResponseEntityResultHandlerTests {
|
||||
{\
|
||||
"instance":"\\/path",\
|
||||
"status":400,\
|
||||
"title":"Bad Request",\
|
||||
"type":"about:blank"\
|
||||
"title":"Bad Request"\
|
||||
}""");
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -395,7 +395,6 @@ class RequestResponseBodyMethodProcessorTests {
|
||||
<status>400</status>
|
||||
<instance>/path</instance>
|
||||
<title>Bad Request</title>
|
||||
<type>about:blank</type>
|
||||
</problem>""")
|
||||
.ignoreWhitespace()
|
||||
.areIdentical();
|
||||
@@ -403,7 +402,6 @@ class RequestResponseBodyMethodProcessorTests {
|
||||
else {
|
||||
JSONAssert.assertEquals("""
|
||||
{
|
||||
"type": "about:blank",
|
||||
"title": "Bad Request",
|
||||
"status": 400,
|
||||
"instance": "/path"
|
||||
|
||||
+1
-2
@@ -144,8 +144,7 @@ class ResourceHttpRequestHandlerIntegrationTests {
|
||||
"detail":"No static resource non-existing.",\
|
||||
"instance":"\\/cp\\/non-existing",\
|
||||
"status":404,\
|
||||
"title":"Not Found",\
|
||||
"type":"about:blank"\
|
||||
"title":"Not Found"\
|
||||
}\
|
||||
""");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user