Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -81,11 +81,11 @@ public abstract class AopNamespaceUtils {
|
||||
|
||||
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, Element sourceElement) {
|
||||
if (sourceElement != null) {
|
||||
boolean proxyTargetClass = Boolean.valueOf(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
|
||||
boolean proxyTargetClass = Boolean.parseBoolean(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
|
||||
if (proxyTargetClass) {
|
||||
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
|
||||
}
|
||||
boolean exposeProxy = Boolean.valueOf(sourceElement.getAttribute(EXPOSE_PROXY_ATTRIBUTE));
|
||||
boolean exposeProxy = Boolean.parseBoolean(sourceElement.getAttribute(EXPOSE_PROXY_ATTRIBUTE));
|
||||
if (exposeProxy) {
|
||||
AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ public class CronSequenceGenerator {
|
||||
if (!split[0].contains("-")) {
|
||||
range[1] = max - 1;
|
||||
}
|
||||
int delta = Integer.valueOf(split[1]);
|
||||
int delta = Integer.parseInt(split[1]);
|
||||
if (delta <= 0) {
|
||||
throw new IllegalArgumentException("Incrementer delta must be 1 or higher: '" +
|
||||
field + "' in expression \"" + this.expression + "\"");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -36,8 +36,8 @@ import org.springframework.util.StringUtils;
|
||||
* is not available in a number of environments (e.g. Android, Java ME), so this is
|
||||
* desirable for portability of Spring's core conversion facility.
|
||||
*
|
||||
* <p>Used to build a TypeDescriptor from a property location.
|
||||
* The built TypeDescriptor can then be used to convert from/to the property type.
|
||||
* <p>Used to build a {@link TypeDescriptor} from a property location. The built
|
||||
* {@code TypeDescriptor} can then be used to convert from/to the property type.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Phillip Webb
|
||||
|
||||
@@ -694,11 +694,11 @@ public abstract class StringUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given {@code localeString} value into a {@link Locale}.
|
||||
* Parse the given {@code String} representation into a {@link Locale}.
|
||||
* <p>This is the inverse operation of {@link Locale#toString Locale's toString}.
|
||||
* @param localeString the locale {@code String}, following {@code Locale's}
|
||||
* {@code toString()} format ("en", "en_UK", etc);
|
||||
* also accepts spaces as separators, as an alternative to underscores
|
||||
* @param localeString the locale {@code String}: following {@code Locale's}
|
||||
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
|
||||
* separators (as an alternative to underscores)
|
||||
* @return a corresponding {@code Locale} instance, or {@code null} if none
|
||||
* @throws IllegalArgumentException in case of an invalid locale specification
|
||||
*/
|
||||
|
||||
@@ -368,7 +368,7 @@ public class ReflectionHelper {
|
||||
}
|
||||
|
||||
|
||||
static enum ArgumentsMatchKind {
|
||||
enum ArgumentsMatchKind {
|
||||
|
||||
/** An exact match is where the parameter types exactly match what the method/constructor is expecting */
|
||||
EXACT,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -240,8 +240,8 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
* be parsed unambiguously. Such values should be substituted for URI
|
||||
* variables to enable correct parsing:
|
||||
* <pre class="code">
|
||||
* String uriString = "/hotels/42?filter={value}";
|
||||
* UriComponentsBuilder.fromUriString(uriString).buildAndExpand("hot&cold");
|
||||
* String urlString = "https://example.com/hotels/42?filter={value}";
|
||||
* UriComponentsBuilder.fromHttpUrl(urlString).buildAndExpand("hot&cold");
|
||||
* </pre>
|
||||
* @param httpUrl the source URI
|
||||
* @return the URI components of the URI
|
||||
@@ -373,10 +373,10 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
}
|
||||
|
||||
|
||||
// URI components methods
|
||||
// Instance methods
|
||||
|
||||
/**
|
||||
* Initialize all components of this URI builder with the components of the given URI.
|
||||
* Initialize components of this builder from components of the given URI.
|
||||
* @param uri the URI
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
@@ -412,6 +412,21 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or append individual URI components of this builder from the values
|
||||
* of the given {@link UriComponents} instance.
|
||||
* <p>For the semantics of each component (i.e. set vs append) check the
|
||||
* builder methods on this class. For example {@link #host(String)} sets
|
||||
* while {@link #path(String)} appends.
|
||||
* @param uriComponents the UriComponents to copy from
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
public UriComponentsBuilder uriComponents(UriComponents uriComponents) {
|
||||
Assert.notNull(uriComponents, "UriComponents must not be null");
|
||||
uriComponents.copyToUriComponentsBuilder(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URI scheme. The given scheme may contain URI template variables,
|
||||
* and may also be {@code null} to clear the scheme of this builder.
|
||||
@@ -423,17 +438,6 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all components of this URI builder from the given {@link UriComponents}.
|
||||
* @param uriComponents the UriComponents instance
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
public UriComponentsBuilder uriComponents(UriComponents uriComponents) {
|
||||
Assert.notNull(uriComponents, "UriComponents must not be null");
|
||||
uriComponents.copyToUriComponentsBuilder(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URI scheme-specific-part. When invoked, this method overwrites
|
||||
* {@linkplain #userInfo(String) user-info}, {@linkplain #host(String) host},
|
||||
@@ -509,17 +513,6 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path of this builder overriding all existing path and path segment values.
|
||||
* @param path the URI path; a {@code null} value results in an empty path.
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
public UriComponentsBuilder replacePath(String path) {
|
||||
this.pathBuilder = new CompositePathComponentBuilder(path);
|
||||
resetSchemeSpecificPart();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append path segments to the existing path. Each path segment may contain
|
||||
* URI template variables and should not contain any slashes.
|
||||
@@ -533,6 +526,17 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path of this builder overriding all existing path and path segment values.
|
||||
* @param path the URI path (a {@code null} value results in an empty path)
|
||||
* @return this UriComponentsBuilder
|
||||
*/
|
||||
public UriComponentsBuilder replacePath(String path) {
|
||||
this.pathBuilder = new CompositePathComponentBuilder(path);
|
||||
resetSchemeSpecificPart();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the given query to the existing query of this builder.
|
||||
* The given query may contain URI template variables.
|
||||
@@ -582,7 +586,7 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
* Append the given query parameter to the existing query parameters. The
|
||||
* given name or any of the values may contain URI template variables. If no
|
||||
* values are given, the resulting URI will contain the query parameter name
|
||||
* only (i.e. {@code ?foo} instead of {@code ?foo=bar}.
|
||||
* only (i.e. {@code ?foo} instead of {@code ?foo=bar}).
|
||||
* @param name the query parameter name
|
||||
* @param values the query parameter values
|
||||
* @return this UriComponentsBuilder
|
||||
@@ -704,7 +708,7 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
if ((this.scheme != null) && ((this.scheme.equals("http") && "80".equals(this.port)) ||
|
||||
if (this.scheme != null && ((this.scheme.equals("http") && "80".equals(this.port)) ||
|
||||
(this.scheme.equals("https") && "443".equals(this.port)))) {
|
||||
port(null);
|
||||
}
|
||||
@@ -740,7 +744,6 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
/**
|
||||
* Public declaration of Object's {@code clone()} method.
|
||||
* Delegates to {@link #cloneBuilder()}.
|
||||
* @see Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
|
||||
@@ -185,7 +185,7 @@ public class UriComponentsBuilderTests {
|
||||
}
|
||||
|
||||
@Test // SPR-9832
|
||||
public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxException {
|
||||
public void fromUriStringQueryParamWithReservedCharInValue() {
|
||||
String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR";
|
||||
UriComponents result = UriComponentsBuilder.fromUriString(uri).build();
|
||||
|
||||
@@ -494,7 +494,7 @@ public class UriComponentsBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void path() throws URISyntaxException {
|
||||
public void path() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
|
||||
UriComponents result = builder.build();
|
||||
|
||||
@@ -503,7 +503,7 @@ public class UriComponentsBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathSegments() throws URISyntaxException {
|
||||
public void pathSegments() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.pathSegment("foo").pathSegment("bar").build();
|
||||
|
||||
@@ -593,7 +593,7 @@ public class UriComponentsBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParams() throws URISyntaxException {
|
||||
public void queryParams() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.queryParam("baz", "qux", 42).build();
|
||||
|
||||
@@ -605,7 +605,7 @@ public class UriComponentsBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyQueryParam() throws URISyntaxException {
|
||||
public void emptyQueryParam() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.queryParam("baz").build();
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class ViewControllerBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
HttpStatus statusCode = null;
|
||||
if (element.hasAttribute("status-code")) {
|
||||
int statusValue = Integer.valueOf(element.getAttribute("status-code"));
|
||||
int statusValue = Integer.parseInt(element.getAttribute("status-code"));
|
||||
statusCode = HttpStatus.valueOf(statusValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,10 +183,11 @@ public class PathResourceResolver extends AbstractResourceResolver {
|
||||
return resource;
|
||||
}
|
||||
else if (logger.isTraceEnabled()) {
|
||||
logger.trace("Resource path=\"" + resourcePath + "\" was successfully resolved " +
|
||||
"but resource=\"" + resource.getURL() + "\" is neither under the " +
|
||||
"current location=\"" + location.getURL() + "\" nor under any of the " +
|
||||
"allowed locations=" + Arrays.asList(getAllowedLocations()));
|
||||
Resource[] allowedLocations = getAllowedLocations();
|
||||
logger.trace("Resource path \"" + resourcePath + "\" was successfully resolved " +
|
||||
"but resource \"" + resource.getURL() + "\" is neither under the " +
|
||||
"current location \"" + location.getURL() + "\" nor under any of the " +
|
||||
"allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -287,7 +288,7 @@ public class PathResourceResolver extends AbstractResourceResolver {
|
||||
String decodedPath = URLDecoder.decode(resourcePath, "UTF-8");
|
||||
if (decodedPath.contains("../") || decodedPath.contains("..\\")) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Ignoring invalid resource path with escape sequences [" + resourcePath + "]");
|
||||
logger.trace("Resolved resource path contains encoded \"../\" or \"..\\\": " + resourcePath);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -16,19 +16,15 @@
|
||||
|
||||
package org.springframework.web.servlet.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for
|
||||
@@ -94,10 +90,7 @@ public class ServletUriComponentsBuilderTests {
|
||||
request.addHeader("X-Forwarded-Proto", "https");
|
||||
request.addHeader("X-Forwarded-Host", "84.198.58.199");
|
||||
request.addHeader("X-Forwarded-Port", "443");
|
||||
|
||||
HttpRequest httpRequest = new ServletServerHttpRequest(request);
|
||||
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
|
||||
|
||||
UriComponents result = ServletUriComponentsBuilder.fromRequest(request).build();
|
||||
assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
|
||||
}
|
||||
|
||||
@@ -114,7 +107,6 @@ public class ServletUriComponentsBuilderTests {
|
||||
this.request.setRequestURI("/bar");
|
||||
this.request.addHeader("X-Forwarded-Prefix", "/foo");
|
||||
UriComponents result = ServletUriComponentsBuilder.fromRequest(this.request).build();
|
||||
|
||||
assertEquals("http://localhost/foo/bar", result.toUriString());
|
||||
}
|
||||
|
||||
@@ -123,7 +115,6 @@ public class ServletUriComponentsBuilderTests {
|
||||
this.request.setRequestURI("/bar");
|
||||
this.request.addHeader("X-Forwarded-Prefix", "/foo/");
|
||||
UriComponents result = ServletUriComponentsBuilder.fromRequest(this.request).build();
|
||||
|
||||
assertEquals("http://localhost/foo/bar", result.toUriString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user