DATACMNS-419 - PagedResourceAssemblerArgumentResolver now works with templated URIs.
We now handle an IllegalArgumentException being thrown in case we deal with a templated request mapping. We simply skip the attempt to eagerly resolve the base URI for the request and rely on the assembler being capable of resolving it itself or the user effectively providing a Link instances to one of the toResource(…) overloads.
This commit is contained in:
@@ -82,9 +82,7 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
Link linkToMethod = linkBuilderFactory.linkTo(parameter.getMethod(), new Object[0]).withSelfRel();
|
||||
UriComponents fromUriString = UriComponentsBuilder.fromUriString(linkToMethod.getHref()).build();
|
||||
|
||||
UriComponents fromUriString = resolveBaseUri(parameter);
|
||||
MethodParameter pageableParameter = findMatchingPageableParameter(parameter);
|
||||
|
||||
if (pageableParameter != null) {
|
||||
@@ -94,6 +92,22 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Eagerly resolve a base URI for the given {@link MethodParameter} to be handed to the assembler.
|
||||
*
|
||||
* @param parameter must not be {@literal null}.
|
||||
* @return the {@link UriComponents} representing the base URI, or {@literal null} if it can't be resolved eagerly.
|
||||
*/
|
||||
private UriComponents resolveBaseUri(MethodParameter parameter) {
|
||||
|
||||
try {
|
||||
Link linkToMethod = linkBuilderFactory.linkTo(parameter.getMethod(), new Object[0]).withSelfRel();
|
||||
return UriComponentsBuilder.fromUriString(linkToMethod.getHref()).build();
|
||||
} catch (IllegalArgumentException o_O) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns finds the {@link MethodParameter} for a {@link Pageable} instance matching the given
|
||||
* {@link MethodParameter} requesting a {@link PagedResourcesAssembler}.
|
||||
|
||||
Reference in New Issue
Block a user