Browse Source

Polishing

pull/739/head
Juergen Hoeller 10 years ago
parent
commit
0c15a54007
  1. 7
      spring-core/src/main/java/org/springframework/core/ResolvableType.java
  2. 7
      spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java
  3. 25
      spring-web/src/main/java/org/springframework/web/client/RestTemplate.java
  4. 4
      spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java
  5. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java

7
spring-core/src/main/java/org/springframework/core/ResolvableType.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 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.
@ -1092,9 +1092,8 @@ public final class ResolvableType implements Serializable {
public static ResolvableType forMethodParameter(MethodParameter methodParameter, Type targetType) { public static ResolvableType forMethodParameter(MethodParameter methodParameter, Type targetType) {
Assert.notNull(methodParameter, "MethodParameter must not be null"); Assert.notNull(methodParameter, "MethodParameter must not be null");
ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass()); ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass());
return forType(targetType, new MethodParameterTypeProvider(methodParameter), return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()).
owner.asVariableResolver()).getNested(methodParameter.getNestingLevel(), getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel);
methodParameter.typeIndexesPerLevel);
} }
/** /**

7
spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2015 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.
@ -29,7 +29,6 @@ import org.springframework.http.MediaType;
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 3.2 * @since 3.2
*
* @see org.springframework.core.ParameterizedTypeReference * @see org.springframework.core.ParameterizedTypeReference
*/ */
public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T> { public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T> {
@ -38,7 +37,7 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T>
* Indicates whether the given type can be read by this converter. * Indicates whether the given type can be read by this converter.
* @param type the type to test for readability * @param type the type to test for readability
* @param contextClass a context class for the target type, for example a class * @param contextClass a context class for the target type, for example a class
* in which the target type appears in a method signature, can be {@code null} * in which the target type appears in a method signature (can be {@code null})
* @param mediaType the media type to read, can be {@code null} if not specified. * @param mediaType the media type to read, can be {@code null} if not specified.
* Typically the value of a {@code Content-Type} header. * Typically the value of a {@code Content-Type} header.
* @return {@code true} if readable; {@code false} otherwise * @return {@code true} if readable; {@code false} otherwise
@ -51,7 +50,7 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T>
* been passed to the {@link #canRead canRead} method of this interface, * been passed to the {@link #canRead canRead} method of this interface,
* which must have returned {@code true}. * which must have returned {@code true}.
* @param contextClass a context class for the target type, for example a class * @param contextClass a context class for the target type, for example a class
* in which the target type appears in a method signature, can be {@code null} * in which the target type appears in a method signature (can be {@code null})
* @param inputMessage the HTTP input message to read from * @param inputMessage the HTTP input message to read from
* @return the converted object * @return the converted object
* @throws IOException in case of I/O errors * @throws IOException in case of I/O errors

25
spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 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.
@ -596,7 +596,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
logger.debug(method.name() + " request for \"" + url + "\" resulted in " + logger.debug(method.name() + " request for \"" + url + "\" resulted in " +
response.getRawStatusCode() + " (" + response.getStatusText() + ")"); response.getRawStatusCode() + " (" + response.getStatusText() + ")");
} }
catch (IOException e) { catch (IOException ex) {
// ignore // ignore
} }
} }
@ -608,7 +608,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
logger.warn(method.name() + " request for \"" + url + "\" resulted in " + logger.warn(method.name() + " request for \"" + url + "\" resulted in " +
response.getRawStatusCode() + " (" + response.getStatusText() + "); invoking error handler"); response.getRawStatusCode() + " (" + response.getStatusText() + "); invoking error handler");
} }
catch (IOException e) { catch (IOException ex) {
// ignore // ignore
} }
} }
@ -668,12 +668,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
@Override @Override
public void doWithRequest(ClientHttpRequest request) throws IOException { public void doWithRequest(ClientHttpRequest request) throws IOException {
if (responseType != null) { if (this.responseType != null) {
Class<?> responseClass = null; Class<?> responseClass = null;
if (responseType instanceof Class) { if (this.responseType instanceof Class) {
responseClass = (Class<?>) responseType; responseClass = (Class<?>) this.responseType;
} }
List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>(); List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
for (HttpMessageConverter<?> converter : getMessageConverters()) { for (HttpMessageConverter<?> converter : getMessageConverters()) {
if (responseClass != null) { if (responseClass != null) {
@ -682,13 +681,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
} }
} }
else if (converter instanceof GenericHttpMessageConverter) { else if (converter instanceof GenericHttpMessageConverter) {
GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter; GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter;
if (genericConverter.canRead(responseType, null, null)) { if (genericConverter.canRead(this.responseType, null, null)) {
allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter)); allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
} }
} }
} }
if (!allSupportedMediaTypes.isEmpty()) { if (!allSupportedMediaTypes.isEmpty()) {
MediaType.sortBySpecificity(allSupportedMediaTypes); MediaType.sortBySpecificity(allSupportedMediaTypes);
@ -744,9 +741,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void doWithRequest(ClientHttpRequest httpRequest) throws IOException { public void doWithRequest(ClientHttpRequest httpRequest) throws IOException {
super.doWithRequest(httpRequest); super.doWithRequest(httpRequest);
if (!requestEntity.hasBody()) { if (!this.requestEntity.hasBody()) {
HttpHeaders httpHeaders = httpRequest.getHeaders(); HttpHeaders httpHeaders = httpRequest.getHeaders();
HttpHeaders requestHeaders = requestEntity.getHeaders(); HttpHeaders requestHeaders = this.requestEntity.getHeaders();
if (!requestHeaders.isEmpty()) { if (!requestHeaders.isEmpty()) {
httpHeaders.putAll(requestHeaders); httpHeaders.putAll(requestHeaders);
} }
@ -755,9 +752,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
} }
} }
else { else {
Object requestBody = requestEntity.getBody(); Object requestBody = this.requestEntity.getBody();
Class<?> requestType = requestBody.getClass(); Class<?> requestType = requestBody.getClass();
HttpHeaders requestHeaders = requestEntity.getHeaders(); HttpHeaders requestHeaders = this.requestEntity.getHeaders();
MediaType requestContentType = requestHeaders.getContentType(); MediaType requestContentType = requestHeaders.getContentType();
for (HttpMessageConverter<?> messageConverter : getMessageConverters()) { for (HttpMessageConverter<?> messageConverter : getMessageConverters()) {
if (messageConverter.canWrite(requestType, requestContentType)) { if (messageConverter.canWrite(requestType, requestContentType)) {

4
spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

@ -268,9 +268,9 @@ public class UriComponentsBuilder implements Cloneable {
* Create a new {@code UriComponents} object from the URI associated with * Create a new {@code UriComponents} object from the URI associated with
* the given HttpRequest while also overlaying with values from the headers * the given HttpRequest while also overlaying with values from the headers
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if present. * "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if present.
*
* @param request the source request * @param request the source request
* @return the URI components of the UR * @return the URI components of the URI
* @since 4.1.5
*/ */
public static UriComponentsBuilder fromHttpRequest(HttpRequest request) { public static UriComponentsBuilder fromHttpRequest(HttpRequest request) {
URI uri = request.getURI(); URI uri = request.getURI();

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 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.
@ -93,7 +93,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
} }
/** /**
* @throws MethodArgumentNotValidException if validation fails * Throws MethodArgumentNotValidException if validation fails.
* @throws HttpMessageNotReadableException if {@link RequestBody#required()} * @throws HttpMessageNotReadableException if {@link RequestBody#required()}
* is {@code true} and there is no body content or if there is no suitable * is {@code true} and there is no body content or if there is no suitable
* converter to read the content with. * converter to read the content with.
@ -143,8 +143,8 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
} }
@Override @Override
protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter methodParam,
MethodParameter methodParam, Type paramType) throws IOException, HttpMediaTypeNotSupportedException { Type paramType) throws IOException, HttpMediaTypeNotSupportedException {
final HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); final HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
HttpInputMessage inputMessage = new ServletServerHttpRequest(servletRequest); HttpInputMessage inputMessage = new ServletServerHttpRequest(servletRequest);

Loading…
Cancel
Save