Skip to content

Commit 78931ee

Browse files
committed
Polishing
1 parent e522fec commit 78931ee

File tree

6 files changed

+19
-18
lines changed

6 files changed

+19
-18
lines changed

spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessa
219219
return readJavaType(javaType, inputMessage);
220220
}
221221

222-
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
222+
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) throws IOException {
223223
try {
224224
if (inputMessage instanceof MappingJacksonInputMessage) {
225225
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
@@ -230,8 +230,8 @@ private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
230230
}
231231
return this.objectMapper.readValue(inputMessage.getBody(), javaType);
232232
}
233-
catch (IOException ex) {
234-
throw new HttpMessageNotReadableException("Could not read JSON document: " + ex.getMessage(), ex);
233+
catch (JsonProcessingException ex) {
234+
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getOriginalMessage(), ex);
235235
}
236236
}
237237

@@ -283,7 +283,7 @@ else if (filters != null) {
283283

284284
}
285285
catch (JsonProcessingException ex) {
286-
throw new HttpMessageNotWritableException("Could not write JSON document: " + ex.getMessage(), ex);
286+
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getOriginalMessage(), ex);
287287
}
288288
}
289289

spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private Object readTypeToken(TypeToken<?> token, HttpInputMessage inputMessage)
161161
return this.gson.fromJson(json, token.getType());
162162
}
163163
catch (JsonParseException ex) {
164-
throw new HttpMessageNotReadableException("Could not read JSON document: " + ex.getMessage(), ex);
164+
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
165165
}
166166
}
167167

@@ -191,7 +191,7 @@ protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessag
191191
writer.close();
192192
}
193193
catch (JsonIOException ex) {
194-
throw new HttpMessageNotWritableException("Could not write JSON document: " + ex.getMessage(), ex);
194+
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
195195
}
196196
}
197197

spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -86,7 +86,8 @@ public T extractData(ClientHttpResponse response) throws IOException {
8686

8787
for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
8888
if (messageConverter instanceof GenericHttpMessageConverter) {
89-
GenericHttpMessageConverter<?> genericMessageConverter = (GenericHttpMessageConverter<?>) messageConverter;
89+
GenericHttpMessageConverter<?> genericMessageConverter =
90+
(GenericHttpMessageConverter<?>) messageConverter;
9091
if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
9192
if (logger.isDebugEnabled()) {
9293
logger.debug("Reading [" + this.responseType + "] as \"" +

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@
4545
* @author Rossen Stoyanchev
4646
* @author Sam Brannen
4747
* @since 3.0
48-
* @see AnnotatedElementUtils#findMergedAnnotation
48+
* @see ResponseStatus
4949
*/
5050
public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware {
5151

@@ -99,14 +99,14 @@ protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, Http
9999

100100
int statusCode = responseStatus.code().value();
101101
String reason = responseStatus.reason();
102-
if (this.messageSource != null) {
103-
reason = this.messageSource.getMessage(reason, null, reason, LocaleContextHolder.getLocale());
104-
}
105102
if (!StringUtils.hasLength(reason)) {
106103
response.sendError(statusCode);
107104
}
108105
else {
109-
response.sendError(statusCode, reason);
106+
String resolvedReason = (this.messageSource != null ?
107+
this.messageSource.getMessage(reason, null, reason, LocaleContextHolder.getLocale()) :
108+
reason);
109+
response.sendError(statusCode, resolvedReason);
110110
}
111111
return new ModelAndView();
112112
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ else if (targetClass != null) {
226226
}
227227
}
228228
catch (IOException ex) {
229-
throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex);
229+
throw new HttpMessageNotReadableException("I/O error while reading input message", ex);
230230
}
231231

232232
if (body == NO_VALUE) {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -156,8 +156,8 @@ protected <T> void writeWithMessageConverters(T value, MethodParameter returnTyp
156156
* @param inputMessage the input messages. Used to inspect the {@code Accept} header.
157157
* @param outputMessage the output message to write to
158158
* @throws IOException thrown in case of I/O errors
159-
* @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated by {@code Accept} header on
160-
* the request cannot be met by the message converters
159+
* @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated
160+
* by the {@code Accept} header on the request cannot be met by the message converters
161161
*/
162162
@SuppressWarnings("unchecked")
163163
protected <T> void writeWithMessageConverters(T value, MethodParameter returnType,

0 commit comments

Comments
 (0)