@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.hateoas.server.core;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static java.util.Optional.*;
|
||||
import static org.springframework.core.annotation.AnnotatedElementUtils.*;
|
||||
import static org.springframework.core.annotation.AnnotationUtils.*;
|
||||
|
||||
@@ -169,8 +169,13 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer {
|
||||
: Arrays.stream(mediaTypes).map(MediaType::parseMediaType).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getParams(java.lang.reflect.Method)
|
||||
*/
|
||||
@Override
|
||||
public String[] getParams(Method method) {
|
||||
|
||||
Annotation annotation = findMergedAnnotation(method, annotationType);
|
||||
String[] params = (String[]) getValue(annotation, "params");
|
||||
|
||||
|
||||
@@ -105,6 +105,10 @@ public class CachingMappingDiscoverer implements MappingDiscoverer {
|
||||
return delegate.getConsumes(method);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getParams(java.lang.reflect.Method)
|
||||
*/
|
||||
@Override
|
||||
public String[] getParams(Method method) {
|
||||
return delegate.getParams(method);
|
||||
|
||||
@@ -82,8 +82,11 @@ public interface MappingDiscoverer {
|
||||
List<MediaType> getConsumes(Method method);
|
||||
|
||||
/**
|
||||
* @param method - must not be null.
|
||||
* Returns the statically declared request parameters.
|
||||
*
|
||||
* @param method must not be {@literal null}.
|
||||
* @return the parameters of the mapped request, narrowing the primary mapping.
|
||||
* @since 1.4
|
||||
*/
|
||||
String[] getParams(Method method);
|
||||
}
|
||||
|
||||
@@ -92,6 +92,10 @@ class PropertyResolvingMappingDiscoverer implements MappingDiscoverer {
|
||||
return delegate.getConsumes(method);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.server.core.MappingDiscoverer#getParams(java.lang.reflect.Method)
|
||||
*/
|
||||
@Override
|
||||
public String[] getParams(Method method) {
|
||||
return delegate.getParams(method);
|
||||
|
||||
@@ -24,7 +24,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
@@ -124,14 +126,19 @@ public class WebMvcLinkBuilderFactory implements MethodLinkBuilderFactory<WebMvc
|
||||
|
||||
String[] primaryParams = SpringAffordanceBuilder.DISCOVERER.getParams(invocation.getMethod());
|
||||
ParamsRequestCondition paramsRequestCondition = new ParamsRequestCondition(primaryParams);
|
||||
for (NameValueExpression<String> expression: paramsRequestCondition.getExpressions()) {
|
||||
|
||||
for (NameValueExpression<String> expression : paramsRequestCondition.getExpressions()) {
|
||||
|
||||
if (expression.isNegated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String value = expression.getValue();
|
||||
if (value == null){
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.queryParam(expression.getName(), value);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,13 +114,6 @@ class WebMvcLinkBuilderFactoryUnitTest extends TestUtils {
|
||||
assertThat(link.getHref()).endsWith("/something/with%20blank/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void linksToMethodWithPrimaryParam(){
|
||||
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPrimaryParams()).withSelfRel();
|
||||
assertThat(link.getRel()).isEqualTo(IanaLinkRelations.SELF);
|
||||
assertThat(link.getHref()).endsWith("/something/foo?a=1&b=2");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #96
|
||||
*/
|
||||
@@ -182,6 +175,15 @@ class WebMvcLinkBuilderFactoryUnitTest extends TestUtils {
|
||||
assertThat(link.getHref()).endsWith("/people/17/addresses");
|
||||
}
|
||||
|
||||
@Test // #467
|
||||
void linksToMethodWithPrimaryParam() {
|
||||
|
||||
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPrimaryParams()).withSelfRel();
|
||||
|
||||
assertThat(link.getRel()).isEqualTo(IanaLinkRelations.SELF);
|
||||
assertThat(link.getHref()).endsWith("/something/foo?a=1&b=2");
|
||||
}
|
||||
|
||||
interface SampleController {
|
||||
|
||||
@RequestMapping("/sample/{id}")
|
||||
|
||||
@@ -667,8 +667,8 @@ class WebMvcLinkBuilderUnitTest extends TestUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/foo", params = {"a=1", "b=2", "c!=4", "!d"})
|
||||
HttpEntity<Void> methodWithPrimaryParams(){
|
||||
@RequestMapping(path = "/foo", params = { "a=1", "b=2", "c!=4", "!d" })
|
||||
HttpEntity<Void> methodWithPrimaryParams() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user