|
1 | 1 | package io.github.polysantiago.spring.rest; |
2 | 2 |
|
| 3 | +import static java.util.Collections.emptyMap; |
| 4 | +import static java.util.Collections.singletonList; |
| 5 | +import static java.util.stream.Collectors.toList; |
| 6 | +import static java.util.stream.Collectors.toMap; |
| 7 | +import static org.apache.commons.lang3.ArrayUtils.isNotEmpty; |
| 8 | +import static org.apache.commons.lang3.StringUtils.substringAfter; |
| 9 | +import static org.apache.commons.lang3.StringUtils.substringBefore; |
| 10 | +import static org.springframework.http.MediaType.parseMediaType; |
| 11 | +import static org.springframework.util.CollectionUtils.isEmpty; |
| 12 | + |
3 | 13 | import io.github.polysantiago.spring.rest.support.MethodParameters; |
| 14 | +import java.lang.reflect.Method; |
| 15 | +import java.net.URI; |
| 16 | +import java.util.Collection; |
| 17 | +import java.util.List; |
| 18 | +import java.util.Map; |
| 19 | +import java.util.stream.Stream; |
4 | 20 | import lombok.NonNull; |
5 | 21 | import lombok.Setter; |
6 | 22 | import lombok.experimental.Accessors; |
|
16 | 32 | import org.springframework.http.RequestEntity.BodyBuilder; |
17 | 33 | import org.springframework.util.LinkedMultiValueMap; |
18 | 34 | import org.springframework.util.MultiValueMap; |
19 | | -import org.springframework.web.bind.annotation.*; |
| 35 | +import org.springframework.web.bind.annotation.PathVariable; |
| 36 | +import org.springframework.web.bind.annotation.RequestBody; |
| 37 | +import org.springframework.web.bind.annotation.RequestHeader; |
| 38 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 39 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 40 | +import org.springframework.web.bind.annotation.RequestParam; |
20 | 41 | import org.springframework.web.util.UriComponentsBuilder; |
21 | 42 |
|
22 | | -import java.lang.reflect.Method; |
23 | | -import java.net.URI; |
24 | | -import java.util.Collection; |
25 | | -import java.util.List; |
26 | | -import java.util.stream.Stream; |
27 | | - |
28 | | -import static java.util.Collections.singletonList; |
29 | | -import static java.util.stream.Collectors.toList; |
30 | | -import static java.util.stream.Collectors.toMap; |
31 | | -import static org.apache.commons.lang3.ArrayUtils.isNotEmpty; |
32 | | -import static org.apache.commons.lang3.StringUtils.substringAfter; |
33 | | -import static org.apache.commons.lang3.StringUtils.substringBefore; |
34 | | -import static org.springframework.http.MediaType.parseMediaType; |
35 | | -import static org.springframework.util.CollectionUtils.isEmpty; |
36 | | - |
37 | 43 | class RestClientInterceptorHelper { |
38 | 44 |
|
39 | 45 | private static final TypeDescriptor STRING_TYPE_DESCRIPTOR = TypeDescriptor.valueOf(String.class); |
@@ -121,14 +127,15 @@ private String convertToString(TypeDescriptor sourceType, Object value) { |
121 | 127 | return value.toString(); |
122 | 128 | } |
123 | 129 |
|
124 | | - private Object[] getPathParameters(List<MethodParameter> parameters, Object[] arguments) { |
| 130 | + private Map<String, Object> getPathParameters(List<MethodParameter> parameters, Object[] arguments) { |
125 | 131 | if (!isEmpty(parameters)) { |
126 | 132 | return parameters.stream() |
127 | 133 | .filter(parameter -> parameter.hasParameterAnnotation(PathVariable.class)) |
128 | | - .map(parameter -> arguments[parameter.getParameterIndex()]) |
129 | | - .toArray(Object[]::new); |
| 134 | + .collect(toMap( |
| 135 | + parameter -> parameter.getParameterAnnotation(PathVariable.class).value(), |
| 136 | + parameter -> arguments[parameter.getParameterIndex()])); |
130 | 137 | } |
131 | | - return new Object[]{}; |
| 138 | + return emptyMap(); |
132 | 139 | } |
133 | 140 |
|
134 | 141 | private static HttpMethod toHttpMethod(RequestMethod requestMethod) { |
|
0 commit comments