* annotation on the handler class and on any of its methods.
*/
protected String[] determineUrlsForHandler(String beanName) {
ApplicationContext context = getApplicationContext();
Class<?> handlerType = context.getType(beanName);
RequestMapping mapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
if (mapping == null && context instanceof ConfigurableApplicationContext &&
context.containsBeanDefinition(beanName)) {
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
BeanDefinition bd = cac.getBeanFactory().getMergedBeanDefinition(beanName);
if (bd instanceof AbstractBeanDefinition) {
AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
if (abd.hasBeanClass()) {
Class<?> beanClass = abd.getBeanClass();
mapping = AnnotationUtils.findAnnotation(beanClass, RequestMapping.class);
}
}
}
if (mapping != null) {
if (mapping.method().length > 0 || mapping.params().length > 0) {
throw new IllegalStateException("Only path value supported for RequestMapping annotation " +
"at the type level - map HTTP method and/or parameters at the method level! " +
"Offending type: " + handlerType);
}
final Set<String> urls = new LinkedHashSet<String>();
String[] paths = mapping.value();
for (String path : paths) {
addUrlsForPath(urls, path);
}
return StringUtils.toStringArray(urls);
}
else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) {
final Set<String> urls = new LinkedHashSet<String>();
ReflectionUtils.doWithMethods(handlerType, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
RequestMapping mapping = method.getAnnotation(RequestMapping.class);
if (mapping != null) {
String[] mappedPaths = mapping.value();
for (int i = 0; i < mappedPaths.length; i++) {
addUrlsForPath(urls, mappedPaths[i]);
}
}
}