Class<?> handlerType = ClassUtils.getUserClass(handler);
HandlerMethodResolver resolver = new HandlerMethodResolver();
resolver.init(handlerType);
String[] typeMappings = null;
RequestMapping typeMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
if (typeMapping != null) {
typeMappings = typeMapping.value();
}
Set<Method> handlerMethods = resolver.getHandlerMethods();
for (Method method : handlerMethods) {
RequestMapping mapping = method.getAnnotation(RequestMapping.class);
Collection<String> computedMappings = new HashSet<String>();
if (typeMappings != null) {
computedMappings.addAll(Arrays.asList(typeMappings));
}
for (String path : mapping.value()) {
if (typeMappings != null) {
for (String parent : computedMappings) {
if (parent.endsWith("/")) {
parent = parent.substring(0, parent.length() - 1);
}
computedMappings.add(parent + path);
}
}
else {
computedMappings.add(path);
}
}
logger.debug("Analysing mappings for method:" + method.getName() + ", key:" + key
+ ", computed mappings: " + computedMappings);
if (computedMappings.contains(key)) {
RequestMethod[] methods = mapping.method();
if (methods != null && methods.length > 0) {
for (RequestMethod requestMethod : methods) {
logger.debug("Added explicit mapping for path=" + key + "to RequestMethod=" + requestMethod);
result.add(new ResourceInfo(key, requestMethod));
}