Polishing

This commit is contained in:
Juergen Hoeller
2014-09-17 01:51:23 +02:00
parent b39e66b897
commit f8b729aa5f
24 changed files with 157 additions and 139 deletions

View File

@@ -241,7 +241,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
if (requiredConstructor != null) {
throw new BeanCreationException(beanName,
"Invalid autowire-marked constructor: " + candidate +
". Found another constructor with 'required' Autowired annotation: " +
". Found constructor with 'required' Autowired annotation already: " +
requiredConstructor);
}
if (candidate.getParameterTypes().length == 0) {
@@ -253,7 +253,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
if (!candidates.isEmpty()) {
throw new BeanCreationException(beanName,
"Invalid autowire-marked constructors: " + candidates +
". Found another constructor with 'required' Autowired annotation: " +
". Found constructor with 'required' Autowired annotation: " +
candidate);
}
requiredConstructor = candidate;

View File

@@ -2610,7 +2610,7 @@ public class AutowiredAnnotationBeanPostProcessorTests {
}
public static class GenericInterface1Impl<T> implements GenericInterface1<T>{
public static class GenericInterface1Impl<T> implements GenericInterface1<T> {
@Autowired
private GenericInterface2<T> gi2;

View File

@@ -200,7 +200,7 @@ public class GenericConversionService implements ConfigurableConversionService {
}
// subclassing hooks
// Protected template methods
/**
* Template method to convert a null source.
@@ -548,7 +548,7 @@ public class GenericConversionService implements ConfigurableConversionService {
Class<?> candidate = hierarchy.get(i);
candidate = (array ? candidate.getComponentType() : ClassUtils.resolvePrimitiveIfNecessary(candidate));
Class<?> superclass = candidate.getSuperclass();
if (candidate.getSuperclass() != null && superclass != Object.class) {
if (superclass != null && superclass != Object.class) {
addToClassHierarchy(i + 1, candidate.getSuperclass(), array, hierarchy, visited);
}
for (Class<?> implementedInterface : candidate.getInterfaces()) {
@@ -563,6 +563,7 @@ public class GenericConversionService implements ConfigurableConversionService {
private void addToClassHierarchy(int index, Class<?> type, boolean asArray,
List<Class<?>> hierarchy, Set<Class<?>> visited) {
if (asArray) {
type = Array.newInstance(type, 0).getClass();
}

View File

@@ -194,7 +194,6 @@ public class SocketUtils {
private static enum SocketType {
TCP {
@Override
protected boolean isPortAvailable(int port) {
try {
@@ -209,7 +208,6 @@ public class SocketUtils {
},
UDP {
@Override
protected boolean isPortAvailable(int port) {
try {

View File

@@ -57,11 +57,13 @@ import static org.junit.Assert.*;
* @author Keith Donald
* @author Juergen Hoeller
* @author Phillip Webb
* @author David Haraburda
*/
public class GenericConversionServiceTests {
private GenericConversionService conversionService = new GenericConversionService();
@Test
public void canConvert() {
assertFalse(conversionService.canConvert(String.class, Integer.class));
@@ -749,6 +751,13 @@ public class GenericConversionServiceTests {
assertEquals("A", result);
}
@Test
public void testSubclassOfEnumToString() throws Exception {
conversionService.addConverter(new EnumToStringConverter(conversionService));
String result = conversionService.convert(EnumWithSubclass.FIRST, String.class);
assertEquals("FIRST", result);
}
@Test
public void testEnumWithInterfaceToStringConversion() {
// SPR-9692
@@ -850,6 +859,7 @@ public class GenericConversionServiceTests {
@ExampleAnnotation
public String annotatedString;
@Retention(RetentionPolicy.RUNTIME)
public static @interface ExampleAnnotation {
}
@@ -892,8 +902,7 @@ public class GenericConversionServiceTests {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType,
TypeDescriptor targetType) {
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return null;
}
@@ -936,6 +945,7 @@ public class GenericConversionServiceTests {
String getCode();
}
public static enum MyEnum implements MyEnumInterface {
A {
@@ -947,6 +957,17 @@ public class GenericConversionServiceTests {
}
public enum EnumWithSubclass {
FIRST {
@Override
public String toString() {
return "1st";
}
}
}
public static class MyStringToRawCollectionConverter implements Converter<String, Collection> {
@Override
@@ -955,6 +976,7 @@ public class GenericConversionServiceTests {
}
}
public static class MyStringToGenericCollectionConverter implements Converter<String, Collection<?>> {
@Override
@@ -963,6 +985,7 @@ public class GenericConversionServiceTests {
}
}
private static class MyEnumInterfaceToStringConverter<T extends MyEnumInterface> implements Converter<T, String> {
@Override
@@ -971,6 +994,7 @@ public class GenericConversionServiceTests {
}
}
public static class MyStringToStringCollectionConverter implements Converter<String, Collection<String>> {
@Override
@@ -979,6 +1003,7 @@ public class GenericConversionServiceTests {
}
}
public static class MyStringToIntegerCollectionConverter implements Converter<String, Collection<Integer>> {
@Override

View File

@@ -357,7 +357,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
@Override
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
ParsedSql parsedSql = this.getParsedSql(sql);
ParsedSql parsedSql = getParsedSql(sql);
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(parsedSql, batchArgs, getJdbcOperations());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -40,8 +40,7 @@ public @interface Header {
/**
* Whether the header is required.
* <p>
* Default is {@code true}, leading to an exception if the header missing. Switch this
* <p>Default is {@code true}, leading to an exception if the header missing. Switch this
* to {@code false} if you prefer a {@code null} in case of the header missing.
*/
boolean required() default true;

View File

@@ -88,7 +88,6 @@ public class HeaderMethodArgumentResolverTests {
@Test
public void resolveArgumentNativeHeader() throws Exception {
TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor();
headers.setNativeHeader("param1", "foo");
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
@@ -98,7 +97,6 @@ public class HeaderMethodArgumentResolverTests {
@Test
public void resolveArgumentNativeHeaderAmbiguity() throws Exception {
TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor();
headers.setHeader("param1", "foo");
headers.setNativeHeader("param1", "native-foo");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -23,7 +23,8 @@ import org.springframework.http.HttpHeaders;
import org.springframework.util.Assert;
/**
* Abstract base for {@link ClientHttpRequest} that makes sure that headers and body are not written multiple times.
* Abstract base for {@link ClientHttpRequest} that makes sure that headers
* and body are not written multiple times.
*
* @author Arjen Poutsma
* @since 3.0
@@ -55,8 +56,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
}
/**
* Asserts that this request has not been {@linkplain #execute() executed} yet.
*
* Assert that this request has not been {@linkplain #execute() executed} yet.
* @throws IllegalStateException if this request has been executed
*/
protected void assertNotExecuted() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -28,7 +28,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.util.Assert;
/**
* {@link ClientHttpRequestFactory} implementation that uses standard J2SE facilities.
* {@link ClientHttpRequestFactory} implementation that uses standard JDK facilities.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
@@ -36,8 +36,7 @@ import org.springframework.util.Assert;
* @see java.net.HttpURLConnection
* @see HttpComponentsClientHttpRequestFactory
*/
public class SimpleClientHttpRequestFactory
implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory {
public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory {
private static final int DEFAULT_CHUNK_SIZE = 4096;
@@ -111,14 +110,12 @@ public class SimpleClientHttpRequestFactory
}
/**
* Set if the underlying URLConnection can be set to 'output streaming' mode. When
* output streaming is enabled, authentication and redirection cannot be handled
* automatically. If output streaming is disabled the
* {@link HttpURLConnection#setFixedLengthStreamingMode(int)
* setFixedLengthStreamingMode} and
* {@link HttpURLConnection#setChunkedStreamingMode(int) setChunkedStreamingMode}
* methods of the underlying connection will never be called.
* <p>Default is {@code true}.
* Set if the underlying URLConnection can be set to 'output streaming' mode.
* Default is {@code true}.
* <p>When output streaming is enabled, authentication and redirection cannot be handled automatically.
* If output streaming is disabled, the {@link HttpURLConnection#setFixedLengthStreamingMode} and
* {@link HttpURLConnection#setChunkedStreamingMode} methods of the underlying connection will never
* be called.
* @param outputStreaming if output streaming is enabled
*/
public void setOutputStreaming(boolean outputStreaming) {
@@ -126,15 +123,15 @@ public class SimpleClientHttpRequestFactory
}
/**
* Sets the task executor for this request factory. Setting this property is required
* for {@linkplain #createAsyncRequest(URI, HttpMethod) creating asynchronous
* request}.
* Set the task executor for this request factory. Setting this property is required
* for {@linkplain #createAsyncRequest(URI, HttpMethod) creating asynchronous requests}.
* @param taskExecutor the task executor
*/
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) {
this.taskExecutor = taskExecutor;
}
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
@@ -153,10 +150,8 @@ public class SimpleClientHttpRequestFactory
* is required before calling this method.
*/
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
throws IOException {
Assert.state(this.taskExecutor != null, "Asynchronous execution requires an " +
"AsyncTaskExecutor to be set");
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
Assert.state(this.taskExecutor != null, "Asynchronous execution requires an AsyncTaskExecutor to be set");
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
prepareConnection(connection, httpMethod.name());
if (this.bufferRequestBody) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -24,7 +24,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.util.StringUtils;
/**
* {@link ClientHttpResponse} implementation that uses standard J2SE facilities.
* {@link ClientHttpResponse} implementation that uses standard JDK facilities.
* Obtained via {@link SimpleBufferingClientHttpRequest#execute()} and
* {@link SimpleStreamingClientHttpRequest#execute()}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -48,6 +48,7 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract
super(beanFactory);
}
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(CookieValue.class);
@@ -60,16 +61,17 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract
}
@Override
protected void handleMissingValue(String cookieName, MethodParameter param) throws ServletRequestBindingException {
String paramType = param.getParameterType().getName();
throw new ServletRequestBindingException(
"Missing cookie named '" + cookieName + "' for method parameter type [" + paramType + "]");
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
throw new ServletRequestBindingException("Missing cookie '" + name +
"' for method parameter of type " + parameter.getParameterType().getSimpleName());
}
private static class CookieValueNamedValueInfo extends NamedValueInfo {
private CookieValueNamedValueInfo(CookieValue annotation) {
super(annotation.value(), annotation.required(), annotation.defaultValue());
}
}
}

View File

@@ -96,7 +96,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
}
arg = handleNullValue(namedValueInfo.name, arg, paramType);
}
else if ("".equals(arg) && (namedValueInfo.defaultValue != null)) {
else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
arg = resolveDefaultValue(namedValueInfo.defaultValue);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -48,6 +48,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet
super(beanFactory);
}
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(Value.class);
@@ -60,8 +61,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet
}
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest)
throws Exception {
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
// No name to resolve
return null;
}
@@ -71,10 +71,12 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet
throw new UnsupportedOperationException("@Value is never required: " + parameter.getMethod());
}
private static class ExpressionValueNamedValueInfo extends NamedValueInfo {
private ExpressionValueNamedValueInfo(Value annotation) {
super("@Value", false, annotation.value());
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -47,8 +47,8 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(RequestHeader.class)
&& Map.class.isAssignableFrom(parameter.getParameterType());
return parameter.hasParameterAnnotation(RequestHeader.class) &&
Map.class.isAssignableFrom(parameter.getParameterType());
}
@Override
@@ -85,4 +85,5 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu
return result;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -52,10 +52,11 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho
super(beanFactory);
}
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(RequestHeader.class)
&& !Map.class.isAssignableFrom(parameter.getParameterType());
return parameter.hasParameterAnnotation(RequestHeader.class) &&
!Map.class.isAssignableFrom(parameter.getParameterType());
}
@Override
@@ -76,16 +77,17 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho
}
@Override
protected void handleMissingValue(String headerName, MethodParameter param) throws ServletRequestBindingException {
String paramType = param.getParameterType().getName();
throw new ServletRequestBindingException(
"Missing header '" + headerName + "' for method parameter type [" + paramType + "]");
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
throw new ServletRequestBindingException("Missing request header '" + name +
"' for method parameter of type " + parameter.getParameterType().getSimpleName());
}
private static class RequestHeaderNamedValueInfo extends NamedValueInfo {
private RequestHeaderNamedValueInfo(RequestHeader annotation) {
super(annotation.value(), annotation.required(), annotation.defaultValue());
}
}
}

View File

@@ -152,19 +152,16 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
RequestParam annotation = parameter.getParameterAnnotation(RequestParam.class);
return (annotation != null) ?
new RequestParamNamedValueInfo(annotation) :
new RequestParamNamedValueInfo();
RequestParam ann = parameter.getParameterAnnotation(RequestParam.class);
return (ann != null ? new RequestParamNamedValueInfo(ann) : new RequestParamNamedValueInfo());
}
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
Object arg;
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
MultipartHttpServletRequest multipartRequest =
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
Object arg;
if (MultipartFile.class.equals(parameter.getParameterType())) {
assertIsMultipartRequest(servletRequest);
@@ -179,7 +176,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
else if (isMultipartFileArray(parameter)) {
assertIsMultipartRequest(servletRequest);
Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
arg = multipartRequest.getFiles(name).toArray(new MultipartFile[0]);
List<MultipartFile> multipartFiles = multipartRequest.getFiles(name);
arg = multipartFiles.toArray(new MultipartFile[multipartFiles.size()]);
}
else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
assertIsMultipartRequest(servletRequest);
@@ -251,8 +249,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
@Override
protected void handleMissingValue(String paramName, MethodParameter parameter) throws ServletException {
throw new MissingServletRequestParameterException(paramName, parameter.getParameterType().getSimpleName());
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletException {
throw new MissingServletRequestParameterException(name, parameter.getParameterType().getSimpleName());
}
@Override
@@ -265,8 +263,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
return;
}
RequestParam annot = parameter.getParameterAnnotation(RequestParam.class);
String name = StringUtils.isEmpty(annot.value()) ? parameter.getParameterName() : annot.value();
RequestParam ann = parameter.getParameterAnnotation(RequestParam.class);
String name = (ann == null || StringUtils.isEmpty(ann.value()) ? parameter.getParameterName() : ann.value());
if (value == null) {
builder.queryParam(name);
@@ -298,6 +296,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
}
private static class RequestPartResolver {
public static Object resolvePart(HttpServletRequest servletRequest) throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -95,10 +95,10 @@ final class OpaqueUriComponents extends UriComponents {
@Override
protected UriComponents expandInternal(UriTemplateVariables uriVariables) {
String expandedScheme = expandUriComponent(this.getScheme(), uriVariables);
String expandedSSp = expandUriComponent(this.ssp, uriVariables);
String expandedFragment = expandUriComponent(this.getFragment(), uriVariables);
return new OpaqueUriComponents(expandedScheme, expandedSSp, expandedFragment);
String expandedScheme = expandUriComponent(getScheme(), uriVariables);
String expandedSsp = expandUriComponent(getSchemeSpecificPart(), uriVariables);
String expandedFragment = expandUriComponent(getFragment(), uriVariables);
return new OpaqueUriComponents(expandedScheme, expandedSsp, expandedFragment);
}
@Override

View File

@@ -252,7 +252,6 @@ public abstract class UriComponents implements Serializable {
* Get the value for the given URI variable name.
* If the value is {@code null}, an empty String is expanded.
* If the value is {@link #SKIP_VALUE}, the URI variable is not expanded.
*
* @param name the variable name
* @return the variable value, possibly {@code null} or {@link #SKIP_VALUE}
*/
@@ -295,8 +294,7 @@ public abstract class UriComponents implements Serializable {
@Override
public Object getValue(String name) {
if (!this.valueIterator.hasNext()) {
throw new IllegalArgumentException(
"Not enough variable values available to expand '" + name + "'");
throw new IllegalArgumentException("Not enough variable values available to expand '" + name + "'");
}
return this.valueIterator.next();
}

View File

@@ -163,20 +163,20 @@ public class UriComponentsBuilder {
*/
public static UriComponentsBuilder fromUriString(String uri) {
Assert.hasLength(uri, "'uri' must not be empty");
Matcher m = URI_PATTERN.matcher(uri);
if (m.matches()) {
Matcher matcher = URI_PATTERN.matcher(uri);
if (matcher.matches()) {
UriComponentsBuilder builder = new UriComponentsBuilder();
String scheme = m.group(2);
String userInfo = m.group(5);
String host = m.group(6);
String port = m.group(8);
String path = m.group(9);
String query = m.group(11);
String fragment = m.group(13);
String scheme = matcher.group(2);
String userInfo = matcher.group(5);
String host = matcher.group(6);
String port = matcher.group(8);
String path = matcher.group(9);
String query = matcher.group(11);
String fragment = matcher.group(13);
boolean opaque = false;
if (StringUtils.hasLength(scheme)) {
String s = uri.substring(scheme.length());
if (!s.startsWith(":/")) {
String rest = uri.substring(scheme.length());
if (!rest.startsWith(":/")) {
opaque = true;
}
}
@@ -223,25 +223,23 @@ public class UriComponentsBuilder {
*/
public static UriComponentsBuilder fromHttpUrl(String httpUrl) {
Assert.notNull(httpUrl, "'httpUrl' must not be null");
Matcher m = HTTP_URL_PATTERN.matcher(httpUrl);
if (m.matches()) {
Matcher matcher = HTTP_URL_PATTERN.matcher(httpUrl);
if (matcher.matches()) {
UriComponentsBuilder builder = new UriComponentsBuilder();
String scheme = m.group(1);
builder.scheme((scheme != null) ? scheme.toLowerCase() : scheme);
builder.userInfo(m.group(4));
String host = m.group(5);
String scheme = matcher.group(1);
builder.scheme(scheme != null ? scheme.toLowerCase() : null);
builder.userInfo(matcher.group(4));
String host = matcher.group(5);
if (StringUtils.hasLength(scheme) && !StringUtils.hasLength(host)) {
throw new IllegalArgumentException("[" + httpUrl + "] is not a valid HTTP URL");
}
builder.host(host);
String port = m.group(7);
String port = matcher.group(7);
if (StringUtils.hasLength(port)) {
builder.port(Integer.parseInt(port));
}
builder.path(m.group(8));
builder.query(m.group(10));
builder.path(matcher.group(8));
builder.query(matcher.group(10));
return builder;
}
else {
@@ -264,7 +262,7 @@ public class UriComponentsBuilder {
* Build a {@code UriComponents} instance from the various components
* contained in this builder.
* @param encoded whether all the components set in this builder are
* encoded ({@code true}) or not ({@code false}).
* encoded ({@code true}) or not ({@code false})
* @return the URI components
*/
public UriComponents build(boolean encoded) {
@@ -509,13 +507,12 @@ public class UriComponentsBuilder {
*/
public UriComponentsBuilder query(String query) {
if (query != null) {
Matcher m = QUERY_PARAM_PATTERN.matcher(query);
while (m.find()) {
String name = m.group(1);
String eq = m.group(2);
String value = m.group(3);
queryParam(name, (value != null ? value :
(StringUtils.hasLength(eq) ? "" : null)));
Matcher matcher = QUERY_PARAM_PATTERN.matcher(query);
while (matcher.find()) {
String name = matcher.group(1);
String eq = matcher.group(2);
String value = matcher.group(3);
queryParam(name, (value != null ? value : (StringUtils.hasLength(eq) ? "" : null)));
}
}
else {
@@ -550,7 +547,7 @@ public class UriComponentsBuilder {
Assert.notNull(name, "'name' must not be null");
if (!ObjectUtils.isEmpty(values)) {
for (Object value : values) {
String valueAsString = value != null ? value.toString() : null;
String valueAsString = (value != null ? value.toString() : null);
this.queryParams.add(name, valueAsString);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -86,17 +86,17 @@ public class UriTemplate implements Serializable {
* UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
* Map&lt;String, String&gt; uriVariables = new HashMap&lt;String, String&gt;();
* uriVariables.put("booking", "42");
* uriVariables.put("hotel", "1");
* uriVariables.put("hotel", "Rest & Relax");
* System.out.println(template.expand(uriVariables));
* </pre>
* will print: <blockquote>{@code http://example.com/hotels/1/bookings/42}</blockquote>
* will print: <blockquote>{@code http://example.com/hotels/Rest%20%26%20Relax/bookings/42}</blockquote>
* @param uriVariables the map of URI variables
* @return the expanded URI
* @throws IllegalArgumentException if {@code uriVariables} is {@code null};
* or if it does not contain values for all the variable names
*/
public URI expand(Map<String, ?> uriVariables) {
UriComponents expandedComponents = uriComponents.expand(uriVariables);
UriComponents expandedComponents = this.uriComponents.expand(uriVariables);
UriComponents encodedComponents = expandedComponents.encode();
return encodedComponents.toUri();
}
@@ -107,16 +107,16 @@ public class UriTemplate implements Serializable {
* <p>Example:
* <pre class="code">
* UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
* System.out.println(template.expand("1", "42));
* System.out.println(template.expand("Rest & Relax", "42));
* </pre>
* will print: <blockquote>{@code http://example.com/hotels/1/bookings/42}</blockquote>
* will print: <blockquote>{@code http://example.com/hotels/Rest%20%26%20Relax/bookings/42}</blockquote>
* @param uriVariableValues the array of URI variables
* @return the expanded URI
* @throws IllegalArgumentException if {@code uriVariables} is {@code null}
* or if it does not contain sufficient variables
*/
public URI expand(Object... uriVariableValues) {
UriComponents expandedComponents = uriComponents.expand(uriVariableValues);
UriComponents expandedComponents = this.uriComponents.expand(uriVariableValues);
UriComponents encodedComponents = expandedComponents.encode();
return encodedComponents.toUri();
}
@@ -177,11 +177,11 @@ public class UriTemplate implements Serializable {
private Parser(String uriTemplate) {
Assert.hasText(uriTemplate, "'uriTemplate' must not be null");
Matcher m = NAMES_PATTERN.matcher(uriTemplate);
Matcher matcher = NAMES_PATTERN.matcher(uriTemplate);
int end = 0;
while (m.find()) {
this.patternBuilder.append(quote(uriTemplate, end, m.start()));
String match = m.group(1);
while (matcher.find()) {
this.patternBuilder.append(quote(uriTemplate, end, matcher.start()));
String match = matcher.group(1);
int colonIdx = match.indexOf(':');
if (colonIdx == -1) {
this.patternBuilder.append(DEFAULT_VARIABLE_PATTERN);
@@ -199,7 +199,7 @@ public class UriTemplate implements Serializable {
String variableName = match.substring(0, colonIdx);
this.variableNames.add(variableName);
}
end = m.end();
end = matcher.end();
}
this.patternBuilder.append(quote(uriTemplate, end, uriTemplate.length()));
int lastIdx = this.patternBuilder.length() - 1;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -114,10 +114,9 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
}
@Override
protected void handleMissingValue(String name, MethodParameter param) throws ServletRequestBindingException {
String paramType = param.getParameterType().getName();
throw new ServletRequestBindingException(
"Missing matrix variable '" + name + "' for method parameter type [" + paramType + "]");
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
throw new ServletRequestBindingException("Missing matrix variable '" + name +
"' for method parameter of type " + parameter.getParameterType().getSimpleName());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -101,10 +101,9 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod
}
@Override
protected void handleMissingValue(String name, MethodParameter param) throws ServletRequestBindingException {
String paramType = param.getParameterType().getName();
throw new ServletRequestBindingException(
"Missing URI template variable '" + name + "' for method parameter type [" + paramType + "]");
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
throw new ServletRequestBindingException("Missing URI template variable '" + name +
"' for method parameter of type " + parameter.getParameterType().getSimpleName());
}
@Override
@@ -130,8 +129,8 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod
return;
}
PathVariable annot = parameter.getParameterAnnotation(PathVariable.class);
String name = StringUtils.isEmpty(annot.value()) ? parameter.getParameterName() : annot.value();
PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
String name = (ann == null || StringUtils.isEmpty(ann.value()) ? parameter.getParameterName() : ann.value());
if (conversionService != null) {
value = conversionService.convert(value, new TypeDescriptor(parameter), STRING_TYPE_DESCRIPTOR);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -27,8 +27,8 @@ import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.WebUtils;
/**
* An {@link org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver} that resolves cookie
* values from an {@link HttpServletRequest}.
* An {@link org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver}
* that resolves cookie values from an {@link HttpServletRequest}.
*
* @author Rossen Stoyanchev
* @since 3.1
@@ -37,17 +37,19 @@ public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValu
private UrlPathHelper urlPathHelper = new UrlPathHelper();
public ServletCookieValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) {
super(beanFactory);
}
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
this.urlPathHelper = urlPathHelper;
}
@Override
protected Object resolveName(String cookieName, MethodParameter parameter, NativeWebRequest webRequest)
throws Exception {
protected Object resolveName(String cookieName, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
Cookie cookieValue = WebUtils.getCookie(servletRequest, cookieName);
if (Cookie.class.isAssignableFrom(parameter.getParameterType())) {
@@ -60,4 +62,5 @@ public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValu
return null;
}
}
}