Browse Source

Polishing

pull/1426/head
Juergen Hoeller 9 years ago
parent
commit
78931ee3ea
  1. 8
      spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java
  2. 4
      spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java
  3. 5
      spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java
  4. 12
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java
  5. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java
  6. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java

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

@ -219,7 +219,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
return readJavaType(javaType, inputMessage); return readJavaType(javaType, inputMessage);
} }
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) { private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) throws IOException {
try { try {
if (inputMessage instanceof MappingJacksonInputMessage) { if (inputMessage instanceof MappingJacksonInputMessage) {
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView(); Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
@ -230,8 +230,8 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
} }
return this.objectMapper.readValue(inputMessage.getBody(), javaType); return this.objectMapper.readValue(inputMessage.getBody(), javaType);
} }
catch (IOException ex) { catch (JsonProcessingException ex) {
throw new HttpMessageNotReadableException("Could not read JSON document: " + ex.getMessage(), ex); throw new HttpMessageNotReadableException("JSON parse error: " + ex.getOriginalMessage(), ex);
} }
} }
@ -283,7 +283,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
} }
catch (JsonProcessingException ex) { catch (JsonProcessingException ex) {
throw new HttpMessageNotWritableException("Could not write JSON document: " + ex.getMessage(), ex); throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getOriginalMessage(), ex);
} }
} }

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

@ -161,7 +161,7 @@ public class GsonHttpMessageConverter extends AbstractGenericHttpMessageConverte
return this.gson.fromJson(json, token.getType()); return this.gson.fromJson(json, token.getType());
} }
catch (JsonParseException ex) { catch (JsonParseException ex) {
throw new HttpMessageNotReadableException("Could not read JSON document: " + ex.getMessage(), ex); throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
} }
} }
@ -191,7 +191,7 @@ public class GsonHttpMessageConverter extends AbstractGenericHttpMessageConverte
writer.close(); writer.close();
} }
catch (JsonIOException ex) { catch (JsonIOException ex) {
throw new HttpMessageNotWritableException("Could not write JSON document: " + ex.getMessage(), ex); throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
} }
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-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.
@ -86,7 +86,8 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
for (HttpMessageConverter<?> messageConverter : this.messageConverters) { for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
if (messageConverter instanceof GenericHttpMessageConverter) { if (messageConverter instanceof GenericHttpMessageConverter) {
GenericHttpMessageConverter<?> genericMessageConverter = (GenericHttpMessageConverter<?>) messageConverter; GenericHttpMessageConverter<?> genericMessageConverter =
(GenericHttpMessageConverter<?>) messageConverter;
if (genericMessageConverter.canRead(this.responseType, null, contentType)) { if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Reading [" + this.responseType + "] as \"" + logger.debug("Reading [" + this.responseType + "] as \"" +

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-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.
@ -45,7 +45,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen * @author Sam Brannen
* @since 3.0 * @since 3.0
* @see AnnotatedElementUtils#findMergedAnnotation * @see ResponseStatus
*/ */
public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware { public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware {
@ -99,14 +99,14 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes
int statusCode = responseStatus.code().value(); int statusCode = responseStatus.code().value();
String reason = responseStatus.reason(); String reason = responseStatus.reason();
if (this.messageSource != null) {
reason = this.messageSource.getMessage(reason, null, reason, LocaleContextHolder.getLocale());
}
if (!StringUtils.hasLength(reason)) { if (!StringUtils.hasLength(reason)) {
response.sendError(statusCode); response.sendError(statusCode);
} }
else { else {
response.sendError(statusCode, reason); String resolvedReason = (this.messageSource != null ?
this.messageSource.getMessage(reason, null, reason, LocaleContextHolder.getLocale()) :
reason);
response.sendError(statusCode, resolvedReason);
} }
return new ModelAndView(); return new ModelAndView();
} }

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

@ -226,7 +226,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
} }
} }
catch (IOException ex) { catch (IOException ex) {
throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex); throw new HttpMessageNotReadableException("I/O error while reading input message", ex);
} }
if (body == NO_VALUE) { if (body == NO_VALUE) {

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-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.
@ -156,8 +156,8 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
* @param inputMessage the input messages. Used to inspect the {@code Accept} header. * @param inputMessage the input messages. Used to inspect the {@code Accept} header.
* @param outputMessage the output message to write to * @param outputMessage the output message to write to
* @throws IOException thrown in case of I/O errors * @throws IOException thrown in case of I/O errors
* @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated by {@code Accept} header on * @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated
* the request cannot be met by the message converters * by the {@code Accept} header on the request cannot be met by the message converters
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T> void writeWithMessageConverters(T value, MethodParameter returnType, protected <T> void writeWithMessageConverters(T value, MethodParameter returnType,

Loading…
Cancel
Save