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 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -1092,9 +1092,8 @@ public final class ResolvableType implements Serializable { @@ -1092,9 +1092,8 @@ public final class ResolvableType implements Serializable {
public static ResolvableType forMethodParameter(MethodParameter methodParameter, Type targetType) {
Assert.notNull(methodParameter, "MethodParameter must not be null");
ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass());
return forType(targetType, new MethodParameterTypeProvider(methodParameter),
owner.asVariableResolver()).getNested(methodParameter.getNestingLevel(),
methodParameter.typeIndexesPerLevel);
return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()).
getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel);
}
/**

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -29,7 +29,6 @@ import org.springframework.http.MediaType; @@ -29,7 +29,6 @@ import org.springframework.http.MediaType;
* @author Arjen Poutsma
* @author Rossen Stoyanchev
* @since 3.2
*
* @see org.springframework.core.ParameterizedTypeReference
*/
public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T> {
@ -38,7 +37,7 @@ 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.
* @param type the type to test for readability
* @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.
* Typically the value of a {@code Content-Type} header.
* @return {@code true} if readable; {@code false} otherwise
@ -51,7 +50,7 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T> @@ -51,7 +50,7 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T>
* been passed to the {@link #canRead canRead} method of this interface,
* which must have returned {@code true}.
* @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
* @return the converted object
* @throws IOException in case of I/O errors

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -596,7 +596,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -596,7 +596,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
logger.debug(method.name() + " request for \"" + url + "\" resulted in " +
response.getRawStatusCode() + " (" + response.getStatusText() + ")");
}
catch (IOException e) {
catch (IOException ex) {
// ignore
}
}
@ -608,7 +608,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -608,7 +608,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
logger.warn(method.name() + " request for \"" + url + "\" resulted in " +
response.getRawStatusCode() + " (" + response.getStatusText() + "); invoking error handler");
}
catch (IOException e) {
catch (IOException ex) {
// ignore
}
}
@ -668,12 +668,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -668,12 +668,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
@Override
public void doWithRequest(ClientHttpRequest request) throws IOException {
if (responseType != null) {
if (this.responseType != null) {
Class<?> responseClass = null;
if (responseType instanceof Class) {
responseClass = (Class<?>) responseType;
if (this.responseType instanceof Class) {
responseClass = (Class<?>) this.responseType;
}
List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
for (HttpMessageConverter<?> converter : getMessageConverters()) {
if (responseClass != null) {
@ -682,13 +681,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -682,13 +681,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
}
}
else if (converter instanceof GenericHttpMessageConverter) {
GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter;
if (genericConverter.canRead(responseType, null, null)) {
if (genericConverter.canRead(this.responseType, null, null)) {
allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
}
}
}
if (!allSupportedMediaTypes.isEmpty()) {
MediaType.sortBySpecificity(allSupportedMediaTypes);
@ -744,9 +741,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -744,9 +741,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
@SuppressWarnings("unchecked")
public void doWithRequest(ClientHttpRequest httpRequest) throws IOException {
super.doWithRequest(httpRequest);
if (!requestEntity.hasBody()) {
if (!this.requestEntity.hasBody()) {
HttpHeaders httpHeaders = httpRequest.getHeaders();
HttpHeaders requestHeaders = requestEntity.getHeaders();
HttpHeaders requestHeaders = this.requestEntity.getHeaders();
if (!requestHeaders.isEmpty()) {
httpHeaders.putAll(requestHeaders);
}
@ -755,9 +752,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -755,9 +752,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
}
}
else {
Object requestBody = requestEntity.getBody();
Object requestBody = this.requestEntity.getBody();
Class<?> requestType = requestBody.getClass();
HttpHeaders requestHeaders = requestEntity.getHeaders();
HttpHeaders requestHeaders = this.requestEntity.getHeaders();
MediaType requestContentType = requestHeaders.getContentType();
for (HttpMessageConverter<?> messageConverter : getMessageConverters()) {
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 { @@ -268,9 +268,9 @@ public class UriComponentsBuilder implements Cloneable {
* Create a new {@code UriComponents} object from the URI associated with
* the given HttpRequest while also overlaying with values from the headers
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if present.
*
* @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) {
URI uri = request.getURI();

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -93,7 +93,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter @@ -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()}
* is {@code true} and there is no body content or if there is no suitable
* converter to read the content with.
@ -143,8 +143,8 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter @@ -143,8 +143,8 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
}
@Override
protected <T> Object readWithMessageConverters(NativeWebRequest webRequest,
MethodParameter methodParam, Type paramType) throws IOException, HttpMediaTypeNotSupportedException {
protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter methodParam,
Type paramType) throws IOException, HttpMediaTypeNotSupportedException {
final HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
HttpInputMessage inputMessage = new ServletServerHttpRequest(servletRequest);

Loading…
Cancel
Save