Skip to content

Commit 47ca7b3

Browse files
committed
Polishing
1 parent 448182f commit 47ca7b3

File tree

12 files changed

+72
-77
lines changed

12 files changed

+72
-77
lines changed

spring-core/src/main/java/org/springframework/util/MultiValueMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ public interface MultiValueMap<K, V> extends Map<K, List<V>> {
3030
/**
3131
* Return the first value for the given key.
3232
* @param key the key
33-
* @return the first value for the specified key, or {@code null}
33+
* @return the first value for the specified key, or {@code null} if none
3434
*/
3535
V getFirst(K key);
3636

@@ -55,7 +55,7 @@ public interface MultiValueMap<K, V> extends Map<K, List<V>> {
5555
void setAll(Map<K, V> values);
5656

5757
/**
58-
* Returns the first values contained in this {@code MultiValueMap}.
58+
* Return a {@code Map} with the first values contained in this {@code MultiValueMap}.
5959
* @return a single value representation of this map
6060
*/
6161
Map<K, V> toSingleValueMap();

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public Object invoke(Message<?> message, Object... providedArgs) throws Exceptio
118118
}
119119

120120
/**
121-
* Get the method argument values for the current request.
121+
* Get the method argument values for the current message.
122122
*/
123123
private Object[] getMethodArgumentValues(Message<?> message, Object... providedArgs) throws Exception {
124124
MethodParameter[] parameters = getMethodParameters();

spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,23 +33,24 @@
3333
* Annotation that can be used to associate the part of a "multipart/form-data" request
3434
* with a method argument.
3535
*
36-
* <p>Supported method argument types include {@link MultipartFile}
37-
* in conjunction with Spring's {@link MultipartResolver} abstraction,
38-
* {@code javax.servlet.http.Part} in conjunction with Servlet 3.0 multipart requests,
39-
* or otherwise for any other method argument, the content of the part is passed through an
40-
* {@link HttpMessageConverter} taking into consideration the 'Content-Type' header
41-
* of the request part. This is analogous to what @{@link RequestBody} does to resolve
42-
* an argument based on the content of a non-multipart regular request.
36+
* <p>Supported method argument types include {@link MultipartFile} in conjunction with
37+
* Spring's {@link MultipartResolver} abstraction, {@code javax.servlet.http.Part} in
38+
* conjunction with Servlet 3.0 multipart requests, or otherwise for any other method
39+
* argument, the content of the part is passed through an {@link HttpMessageConverter}
40+
* taking into consideration the 'Content-Type' header of the request part. This is
41+
* analogous to what @{@link RequestBody} does to resolve an argument based on the
42+
* content of a non-multipart regular request.
4343
*
44-
* <p>Note that @{@link RequestParam} annotation can also be used to associate the
45-
* part of a "multipart/form-data" request with a method argument supporting the same
46-
* method argument types. The main difference is that when the method argument is not a
47-
* String, @{@link RequestParam} relies on type conversion via a registered
48-
* {@link Converter} or {@link PropertyEditor} while @{@link RequestPart} relies
49-
* on {@link HttpMessageConverter}s taking into consideration the 'Content-Type' header
50-
* of the request part. @{@link RequestParam} is likely to be used with name-value form
51-
* fields while @{@link RequestPart} is likely to be used with parts containing more
52-
* complex content (e.g. JSON, XML).
44+
* <p>Note that @{@link RequestParam} annotation can also be used to associate the part
45+
* of a "multipart/form-data" request with a method argument supporting the same method
46+
* argument types. The main difference is that when the method argument is not a String
47+
* or raw {@code MultipartFile} / {@code Part}, {@code @RequestParam} relies on type
48+
* conversion via a registered {@link Converter} or {@link PropertyEditor} while
49+
* {@link RequestPart} relies on {@link HttpMessageConverter HttpMessageConverters}
50+
* taking into consideration the 'Content-Type' header of the request part.
51+
* {@link RequestParam} is likely to be used with name-value form fields while
52+
* {@link RequestPart} is likely to be used with parts containing more complex content
53+
* e.g. JSON, XML).
5354
*
5455
* @author Rossen Stoyanchev
5556
* @author Arjen Poutsma

spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public boolean supportsReturnType(MethodParameter returnType) {
5656
}
5757

5858
@Override
59-
@SuppressWarnings({ "unchecked", "rawtypes" })
59+
@SuppressWarnings({"unchecked", "rawtypes"})
6060
public void handleReturnValue(Object returnValue, MethodParameter returnType,
6161
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
6262

spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@
3737
*
3838
* <p>The created {@link Map} contains all request parameter name/value pairs.
3939
* If the method parameter type is {@link MultiValueMap} instead, the created
40-
* map contains all request parameters and all there values for cases where
40+
* map contains all request parameters and all their values for cases where
4141
* request parameters have multiple values.
4242
*
4343
* @author Arjen Poutsma
@@ -50,22 +50,16 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
5050
@Override
5151
public boolean supportsParameter(MethodParameter parameter) {
5252
RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
53-
if (requestParam != null) {
54-
if (Map.class.isAssignableFrom(parameter.getParameterType())) {
55-
return !StringUtils.hasText(requestParam.name());
56-
}
57-
}
58-
return false;
53+
return (requestParam != null && Map.class.isAssignableFrom(parameter.getParameterType()) &&
54+
!StringUtils.hasText(requestParam.name()));
5955
}
6056

6157
@Override
6258
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
6359
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
6460

65-
Class<?> paramType = parameter.getParameterType();
66-
6761
Map<String, String[]> parameterMap = webRequest.getParameterMap();
68-
if (MultiValueMap.class.isAssignableFrom(paramType)) {
62+
if (MultiValueMap.class.isAssignableFrom(parameter.getParameterType())) {
6963
MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(parameterMap.size());
7064
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
7165
for (String value : entry.getValue()) {
@@ -84,4 +78,5 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
8478
return result;
8579
}
8680
}
81+
8782
}

spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,6 +80,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
8080

8181

8282
/**
83+
* Create a new {@link RequestParamMethodArgumentResolver} instance.
8384
* @param useDefaultResolution in default resolution mode a method argument
8485
* that is a simple type, as defined in {@link BeanUtils#isSimpleProperty},
8586
* is treated as a request parameter even if it isn't annotated, the
@@ -90,6 +91,7 @@ public RequestParamMethodArgumentResolver(boolean useDefaultResolution) {
9091
}
9192

9293
/**
94+
* Create a new {@link RequestParamMethodArgumentResolver} instance.
9395
* @param beanFactory a bean factory used for resolving ${...} placeholder
9496
* and #{...} SpEL expressions in default values, or {@code null} if default
9597
* values are not expected to contain expressions
@@ -108,15 +110,11 @@ public RequestParamMethodArgumentResolver(ConfigurableBeanFactory beanFactory, b
108110
* Supports the following:
109111
* <ul>
110112
* <li>@RequestParam-annotated method arguments.
111-
* This excludes {@link Map} params where the annotation doesn't
112-
* specify a name. See {@link RequestParamMapMethodArgumentResolver}
113-
* instead for such params.
114-
* <li>Arguments of type {@link MultipartFile}
115-
* unless annotated with @{@link RequestPart}.
116-
* <li>Arguments of type {@code javax.servlet.http.Part}
117-
* unless annotated with @{@link RequestPart}.
118-
* <li>In default resolution mode, simple type arguments
119-
* even if not with @{@link RequestParam}.
113+
* This excludes {@link Map} params where the annotation does not specify a name.
114+
* See {@link RequestParamMapMethodArgumentResolver} instead for such params.
115+
* <li>Arguments of type {@link MultipartFile} unless annotated with @{@link RequestPart}.
116+
* <li>Arguments of type {@code Part} unless annotated with @{@link RequestPart}.
117+
* <li>In default resolution mode, simple type arguments even if not with @{@link RequestParam}.
120118
* </ul>
121119
*/
122120
@Override

spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ public void resolveMultiValueMapArgument() throws Exception {
104104
request.addHeader(name, value1);
105105
request.addHeader(name, value2);
106106

107-
MultiValueMap<String, String> expected = new LinkedMultiValueMap<String, String>(1);
107+
MultiValueMap<String, String> expected = new LinkedMultiValueMap<>(1);
108108
expected.add(name, value1);
109109
expected.add(name, value2);
110110

@@ -135,9 +135,8 @@ public void resolveHttpHeadersArgument() throws Exception {
135135

136136

137137
public void params(@RequestHeader Map<?, ?> param1,
138-
@RequestHeader MultiValueMap<?, ?> param2,
139-
@RequestHeader HttpHeaders param3,
140-
Map<?,?> unsupported) {
138+
@RequestHeader MultiValueMap<?, ?> param2, @RequestHeader HttpHeaders param3,
139+
Map<?, ?> unsupported) {
141140
}
142141

143142
}

spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import static org.junit.Assert.*;
4545

4646
/**
47-
* Test fixture with {@link org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver}.
47+
* Test fixture with {@link RequestHeaderMethodArgumentResolver}.
4848
*
4949
* @author Arjen Poutsma
5050
* @author Rossen Stoyanchev
@@ -70,7 +70,7 @@ public class RequestHeaderMethodArgumentResolverTests {
7070

7171
@Before
7272
@SuppressWarnings("resource")
73-
public void setUp() throws Exception {
73+
public void setup() throws Exception {
7474
GenericWebApplicationContext context = new GenericWebApplicationContext();
7575
context.refresh();
7676
resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory());
@@ -94,7 +94,7 @@ public void setUp() throws Exception {
9494
}
9595

9696
@After
97-
public void teardown() {
97+
public void reset() {
9898
RequestContextHolder.resetRequestAttributes();
9999
}
100100

spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolverTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,10 +59,10 @@ public class RequestParamMapMethodArgumentResolverTests {
5959

6060

6161
@Before
62-
public void setUp() throws Exception {
62+
public void setup() throws Exception {
6363
resolver = new RequestParamMapMethodArgumentResolver();
6464

65-
Method method = getClass().getMethod("params", Map.class, MultiValueMap.class, Map.class, Map.class);
65+
Method method = getClass().getMethod("handle", Map.class, MultiValueMap.class, Map.class, Map.class);
6666
paramMap = new SynthesizingMethodParameter(method, 0);
6767
paramMultiValueMap = new SynthesizingMethodParameter(method, 1);
6868
paramNamedMap = new SynthesizingMethodParameter(method, 2);
@@ -99,9 +99,9 @@ public void resolveMultiValueMapArgument() throws Exception {
9999
String name = "foo";
100100
String value1 = "bar";
101101
String value2 = "baz";
102-
request.addParameter(name, new String[]{value1, value2});
102+
request.addParameter(name, value1, value2);
103103

104-
MultiValueMap<String, String> expected = new LinkedMultiValueMap<String, String>(1);
104+
MultiValueMap<String, String> expected = new LinkedMultiValueMap<>(1);
105105
expected.add(name, value1);
106106
expected.add(name, value2);
107107

@@ -112,10 +112,11 @@ public void resolveMultiValueMapArgument() throws Exception {
112112
}
113113

114114

115-
public void params(@RequestParam Map<?, ?> param1,
116-
@RequestParam MultiValueMap<?, ?> param2,
117-
@RequestParam("name") Map<?, ?> param3,
118-
Map<?, ?> param4) {
115+
public void handle(
116+
@RequestParam Map<?, ?> param1,
117+
@RequestParam MultiValueMap<?, ?> param2,
118+
@RequestParam("name") Map<?, ?> param3,
119+
Map<?, ?> param4) {
119120
}
120121

121122
}

spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@ public class RequestParamMethodArgumentResolverTests {
9494

9595

9696
@Before
97-
public void setUp() throws Exception {
97+
public void setup() throws Exception {
9898
resolver = new RequestParamMethodArgumentResolver(null, true);
9999
ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
100100
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
@@ -369,7 +369,7 @@ public void missingRequestParamEmptyValueConvertedToNull() throws Exception {
369369
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
370370
given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);
371371

372-
this.request.addParameter("stringNotAnnot", "");
372+
request.addParameter("stringNotAnnot", "");
373373

374374
Object arg = resolver.resolveArgument(paramStringNotAnnot, null, webRequest, binderFactory);
375375
assertNull(arg);
@@ -383,7 +383,7 @@ public void missingRequestParamEmptyValueNotRequired() throws Exception {
383383
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
384384
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
385385

386-
this.request.addParameter("name", "");
386+
request.addParameter("name", "");
387387

388388
Object arg = resolver.resolveArgument(paramNotRequired, null, webRequest, binderFactory);
389389
assertNull(arg);
@@ -406,21 +406,21 @@ public void resolveSimpleTypeParamToNull() throws Exception {
406406

407407
@Test // SPR-10180
408408
public void resolveEmptyValueToDefault() throws Exception {
409-
this.request.addParameter("name", "");
409+
request.addParameter("name", "");
410410
Object result = resolver.resolveArgument(paramNamedDefaultValueString, null, webRequest, null);
411411
assertEquals("bar", result);
412412
}
413413

414414
@Test
415415
public void resolveEmptyValueWithoutDefault() throws Exception {
416-
this.request.addParameter("stringNotAnnot", "");
416+
request.addParameter("stringNotAnnot", "");
417417
Object result = resolver.resolveArgument(paramStringNotAnnot, null, webRequest, null);
418418
assertEquals("", result);
419419
}
420420

421421
@Test
422422
public void resolveEmptyValueRequiredWithoutDefault() throws Exception {
423-
this.request.addParameter("name", "");
423+
request.addParameter("name", "");
424424
Object result = resolver.resolveArgument(paramRequired, null, webRequest, null);
425425
assertEquals("", result);
426426
}
@@ -435,7 +435,7 @@ public void resolveOptionalParamValue() throws Exception {
435435
Object result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
436436
assertEquals(Optional.empty(), result);
437437

438-
this.request.addParameter("name", "123");
438+
request.addParameter("name", "123");
439439
result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
440440
assertEquals(Optional.class, result.getClass());
441441
assertEquals(123, ((Optional) result).get());
@@ -466,7 +466,7 @@ public void resolveOptionalParamArray() throws Exception {
466466
Object result = resolver.resolveArgument(paramOptionalArray, null, webRequest, binderFactory);
467467
assertEquals(Optional.empty(), result);
468468

469-
this.request.addParameter("name", "123", "456");
469+
request.addParameter("name", "123", "456");
470470
result = resolver.resolveArgument(paramOptionalArray, null, webRequest, binderFactory);
471471
assertEquals(Optional.class, result.getClass());
472472
assertArrayEquals(new Integer[] {123, 456}, (Integer[]) ((Optional) result).get());
@@ -497,7 +497,7 @@ public void resolveOptionalParamList() throws Exception {
497497
Object result = resolver.resolveArgument(paramOptionalList, null, webRequest, binderFactory);
498498
assertEquals(Optional.empty(), result);
499499

500-
this.request.addParameter("name", "123", "456");
500+
request.addParameter("name", "123", "456");
501501
result = resolver.resolveArgument(paramOptionalList, null, webRequest, binderFactory);
502502
assertEquals(Optional.class, result.getClass());
503503
assertEquals(Arrays.asList("123", "456"), ((Optional) result).get());

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ protected ModelAndView doResolveException(
7272
}
7373
}
7474
else if (ex.getCause() instanceof Exception) {
75-
ex = (Exception) ex.getCause();
76-
return doResolveException(request, response, handler, ex);
75+
return doResolveException(request, response, handler, (Exception) ex.getCause());
7776
}
7877
return null;
7978
}

0 commit comments

Comments
 (0)