|
|
|
@ -21,6 +21,7 @@ import java.util.Arrays; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
|
|
|
|
@ -49,6 +50,7 @@ import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.PathMatcher; |
|
|
|
import org.springframework.util.PathMatcher; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
import org.springframework.util.ReflectionUtils.MethodFilter; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
@ -56,6 +58,7 @@ import org.springframework.web.context.request.RequestAttributes; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
import org.springframework.web.method.HandlerMethod; |
|
|
|
import org.springframework.web.method.HandlerMethod; |
|
|
|
|
|
|
|
import org.springframework.web.method.HandlerMethodSelector; |
|
|
|
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver; |
|
|
|
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver; |
|
|
|
import org.springframework.web.method.support.CompositeUriComponentsContributor; |
|
|
|
import org.springframework.web.method.support.CompositeUriComponentsContributor; |
|
|
|
import org.springframework.web.servlet.DispatcherServlet; |
|
|
|
import org.springframework.web.servlet.DispatcherServlet; |
|
|
|
@ -412,25 +415,28 @@ public class MvcUriComponentsBuilder { |
|
|
|
return paths[0]; |
|
|
|
return paths[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Method getMethod(Class<?> controllerType, final String methodName, final Object... args) { |
|
|
|
private static Method getMethod(Class<?> controllerType, String methodName, Object... args) { |
|
|
|
MethodFilter selector = new MethodFilter() { |
|
|
|
Method match = null; |
|
|
|
@Override |
|
|
|
for (Method method : controllerType.getDeclaredMethods()) { |
|
|
|
public boolean matches(Method method) { |
|
|
|
if (method.getName().equals(methodName) && method.getParameterTypes().length == args.length) { |
|
|
|
String name = method.getName(); |
|
|
|
if (match != null) { |
|
|
|
int argLength = method.getParameterTypes().length; |
|
|
|
throw new IllegalArgumentException(String.format( |
|
|
|
return (name.equals(methodName) && argLength == args.length); |
|
|
|
"Found two methods named '%s' accepting arguments %s in controller %s: [%s] and [%s]", |
|
|
|
|
|
|
|
methodName, Arrays.asList(args), controllerType.getName(), match.toGenericString(), |
|
|
|
|
|
|
|
method.toGenericString())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
match = method; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
Set<Method> methods = HandlerMethodSelector.selectMethods(controllerType, selector); |
|
|
|
|
|
|
|
if (methods.size() == 1) { |
|
|
|
|
|
|
|
return methods.iterator().next(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (match == null) { |
|
|
|
else if (methods.size() > 1) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException(String.format( |
|
|
|
|
|
|
|
"Found two methods named '%s' accepting arguments %s in controller %s: [%s]", |
|
|
|
|
|
|
|
methodName, Arrays.asList(args), controllerType.getName(), methods)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
throw new IllegalArgumentException("No method named '" + methodName + "' with " + args.length + |
|
|
|
throw new IllegalArgumentException("No method named '" + methodName + "' with " + args.length + |
|
|
|
" arguments found in controller " + controllerType.getName()); |
|
|
|
" arguments found in controller " + controllerType.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
return match; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) { |
|
|
|
private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) { |
|
|
|
|