Polishing
This commit is contained in:
@@ -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;
|
||||
* @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>
|
||||
* 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>
|
||||
* 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
|
||||
|
||||
@@ -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
|
||||
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
|
||||
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
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
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
|
||||
@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
|
||||
}
|
||||
}
|
||||
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)) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.web.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeMap;
|
||||
@@ -33,7 +33,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
@@ -742,9 +742,9 @@ public abstract class WebUtils {
|
||||
* like this {@code "q1=a;q1=b;q2=a,b,c"}. The resulting map would contain
|
||||
* keys {@code "q1"} and {@code "q2"} with values {@code ["a","b"]} and
|
||||
* {@code ["a","b","c"]} respectively.
|
||||
*
|
||||
* @param matrixVariables the unparsed matrix variables string
|
||||
* @return a map with matrix variable names and values, never {@code null}
|
||||
* @since 3.2
|
||||
*/
|
||||
public static MultiValueMap<String, String> parseMatrixVariables(String matrixVariables) {
|
||||
MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>();
|
||||
@@ -773,12 +773,11 @@ public abstract class WebUtils {
|
||||
* Check the given request origin against a list of allowed origins.
|
||||
* A list containing "*" means that all origins are allowed.
|
||||
* An empty list means only same origin is allowed.
|
||||
*
|
||||
* @return true if the request origin is valid, false otherwise
|
||||
* @since 4.1.5
|
||||
* @see <a href="https://tools.ietf.org/html/rfc6454">RFC 6454: The Web Origin Concept</a>
|
||||
*/
|
||||
public static boolean isValidOrigin(ServerHttpRequest request, List<String> allowedOrigins) {
|
||||
public static boolean isValidOrigin(HttpRequest request, Collection<String> allowedOrigins) {
|
||||
Assert.notNull(request, "Request must not be null");
|
||||
Assert.notNull(allowedOrigins, "Allowed origins must not be null");
|
||||
|
||||
@@ -791,7 +790,7 @@ public abstract class WebUtils {
|
||||
UriComponents requestComponents = UriComponentsBuilder.fromHttpRequest(request).build();
|
||||
int originPort = getPort(originComponents);
|
||||
int requestPort = getPort(requestComponents);
|
||||
return originComponents.getHost().equals(requestComponents.getHost()) && (originPort == requestPort);
|
||||
return (originComponents.getHost().equals(requestComponents.getHost()) && originPort == requestPort);
|
||||
}
|
||||
else {
|
||||
return allowedOrigins.contains(origin);
|
||||
|
||||
Reference in New Issue
Block a user