Polishing

(cherry picked from commit acbb254)
This commit is contained in:
Juergen Hoeller
2016-08-30 23:57:11 +02:00
parent e76ed49513
commit 458d49bdb8
13 changed files with 134 additions and 146 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -42,8 +42,7 @@ import org.springframework.util.comparator.CompoundComparator;
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
* @since 3.0
* @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP 1.1: Semantics
* and Content, section 3.1.1.1</a>
* @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP 1.1: Semantics and Content, section 3.1.1.1</a>
*/
public class MediaType extends MimeType implements Serializable {
@@ -71,7 +70,7 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code application/x-www-form-urlencoded}.
* */
*/
public final static MediaType APPLICATION_FORM_URLENCODED;
/**
@@ -103,7 +102,7 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code application/octet-stream}.
* */
*/
public final static MediaType APPLICATION_OCTET_STREAM;
/**
@@ -113,7 +112,7 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code application/xhtml+xml}.
* */
*/
public final static MediaType APPLICATION_XHTML_XML;
/**
@@ -163,7 +162,7 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code multipart/form-data}.
* */
*/
public final static MediaType MULTIPART_FORM_DATA;
/**
@@ -173,7 +172,7 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code text/html}.
* */
*/
public final static MediaType TEXT_HTML;
/**
@@ -183,7 +182,7 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code text/plain}.
* */
*/
public final static MediaType TEXT_PLAIN;
/**
@@ -193,7 +192,7 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code text/xml}.
* */
*/
public final static MediaType TEXT_XML;
/**
@@ -364,6 +363,8 @@ public class MediaType extends MimeType implements Serializable {
* Parse the given String value into a {@code MediaType} object,
* with this method name following the 'valueOf' naming convention
* (as supported by {@link org.springframework.core.convert.ConversionService}.
* @param value the string to parse
* @throws InvalidMediaTypeException if the media type value cannot be parsed
* @see #parseMediaType(String)
*/
public static MediaType valueOf(String value) {
@@ -374,7 +375,7 @@ public class MediaType extends MimeType implements Serializable {
* Parse the given String into a single {@code MediaType}.
* @param mediaType the string to parse
* @return the media type
* @throws InvalidMediaTypeException if the string cannot be parsed
* @throws InvalidMediaTypeException if the media type value cannot be parsed
*/
public static MediaType parseMediaType(String mediaType) {
MimeType type;
@@ -392,13 +393,12 @@ public class MediaType extends MimeType implements Serializable {
}
}
/**
* Parse the given, comma-separated string into a list of {@code MediaType} objects.
* Parse the given comma-separated string into a list of {@code MediaType} objects.
* <p>This method can be used to parse an Accept or Content-Type header.
* @param mediaTypes the string to parse
* @return the list of media types
* @throws IllegalArgumentException if the string cannot be parsed
* @throws InvalidMediaTypeException if the media type value cannot be parsed
*/
public static List<MediaType> parseMediaTypes(String mediaTypes) {
if (!StringUtils.hasLength(mediaTypes)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@@ -61,6 +61,7 @@ public class HttpPutFormContentFilter extends OncePerRequestFilter {
private final FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();
/**
* The default character set to use for reading form data.
*/
@@ -68,6 +69,7 @@ public class HttpPutFormContentFilter extends OncePerRequestFilter {
this.formConverter.setCharset(charset);
}
@Override
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
@@ -104,29 +106,30 @@ public class HttpPutFormContentFilter extends OncePerRequestFilter {
}
}
private static class HttpPutFormContentRequestWrapper extends HttpServletRequestWrapper {
private MultiValueMap<String, String> formParameters;
public HttpPutFormContentRequestWrapper(HttpServletRequest request, MultiValueMap<String, String> parameters) {
super(request);
this.formParameters = (parameters != null) ? parameters : new LinkedMultiValueMap<String, String>();
this.formParameters = (parameters != null ? parameters : new LinkedMultiValueMap<String, String>());
}
@Override
public String getParameter(String name) {
String queryStringValue = super.getParameter(name);
String formValue = this.formParameters.getFirst(name);
return (queryStringValue != null) ? queryStringValue : formValue;
return (queryStringValue != null ? queryStringValue : formValue);
}
@Override
public Map<String, String[]> getParameterMap() {
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
Enumeration<String> names = this.getParameterNames();
Enumeration<String> names = getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
result.put(name, this.getParameterValues(name));
result.put(name, getParameterValues(name));
}
return result;
}
@@ -150,7 +153,7 @@ public class HttpPutFormContentFilter extends OncePerRequestFilter {
return formValues.toArray(new String[formValues.size()]);
}
else {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<String>(queryStringValues.length + formValues.size());
result.addAll(Arrays.asList(queryStringValues));
result.addAll(formValues);
return result.toArray(new String[result.size()]);

View File

@@ -686,8 +686,7 @@ public class UriComponentsBuilder implements Cloneable {
else {
String hostHeader = headers.getFirst("X-Forwarded-Host");
if (StringUtils.hasText(hostHeader)) {
String[] hosts = StringUtils.commaDelimitedListToStringArray(hostHeader);
String hostToUse = hosts[0];
String hostToUse = StringUtils.commaDelimitedListToStringArray(hostHeader)[0];
if (hostToUse.contains(":")) {
String[] hostAndPort = StringUtils.split(hostToUse, ":");
host(hostAndPort[0]);
@@ -701,14 +700,12 @@ public class UriComponentsBuilder implements Cloneable {
String portHeader = headers.getFirst("X-Forwarded-Port");
if (StringUtils.hasText(portHeader)) {
String[] ports = StringUtils.commaDelimitedListToStringArray(portHeader);
port(Integer.parseInt(ports[0]));
port(Integer.parseInt(StringUtils.commaDelimitedListToStringArray(portHeader)[0]));
}
String protocolHeader = headers.getFirst("X-Forwarded-Proto");
if (StringUtils.hasText(protocolHeader)) {
String[] protocols = StringUtils.commaDelimitedListToStringArray(protocolHeader);
scheme(protocols[0]);
scheme(StringUtils.commaDelimitedListToStringArray(protocolHeader)[0]);
}
}