return getMethodResolver(handler).hasHandlerMethods();
}
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
ExtendedModelMap implicitModel = new ExtendedModelMap();
SessionAttributes sessionAttributes = handler.getClass().getAnnotation(SessionAttributes.class);
Set<String> sessionAttrNames = null;
if (sessionAttributes != null) {
// Always prevent caching in case of session attribute management.
checkAndPrepare(request, response, 0, true);
// Prepare cached set of session attributes names.
sessionAttrNames = this.sessionAttributeNames.get(handler.getClass());
if (sessionAttrNames == null) {
synchronized (this.sessionAttributeNames) {
sessionAttrNames = this.sessionAttributeNames.get(handler.getClass());
if (sessionAttrNames == null) {
sessionAttrNames = Collections.synchronizedSet(new HashSet<String>(4));
this.sessionAttributeNames.put(handler.getClass(), sessionAttrNames);
}
}
}
}
else {
// Uses configured default cacheSeconds setting.
checkAndPrepare(request, response, true);
}
ServletWebRequest webRequest = new ServletWebRequest(request, response);
HandlerMethodResolver methodResolver = getMethodResolver(handler);
Method handlerMethod = methodResolver.resolveHandlerMethod(request);
ArgumentsResolver argResolver = new ArgumentsResolver(methodResolver.getInitBinderMethods());
for (Method attributeMethod : methodResolver.getModelAttributeMethods()) {
Object[] args = argResolver.resolveArguments(
handler, attributeMethod, request, response, webRequest, implicitModel, sessionAttrNames);
ReflectionUtils.makeAccessible(attributeMethod);
Object attrValue = null;
try {
attrValue = attributeMethod.invoke(handler, args);
}
catch (InvocationTargetException ex) {
ReflectionUtils.handleInvocationTargetException(ex);
}
String attrName = AnnotationUtils.findAnnotation(attributeMethod, ModelAttribute.class).value();
if ("".equals(attrName)) {
attrName = Conventions.getVariableNameForReturnType(attributeMethod, attrValue);
}
implicitModel.addAttribute(attrName, attrValue);
}
Object[] args = argResolver.resolveArguments(
handler, handlerMethod, request, response, webRequest, implicitModel, sessionAttrNames);
ReflectionUtils.makeAccessible(handlerMethod);
Object result = null;
try {
result = handlerMethod.invoke(handler, args);
}
catch (InvocationTargetException ex) {
ReflectionUtils.handleInvocationTargetException(ex);
}
ModelAndView mav = argResolver.getModelAndView(handlerMethod, result, implicitModel, webRequest);
if (sessionAttributes != null) {
if (argResolver.isProcessingComplete()) {
if (sessionAttrNames != null) {
for (String attrName : sessionAttrNames) {
this.sessionAttributeStore.cleanupAttribute(webRequest, attrName);
}
}
}
// Expose model attributes as session attributes, if required.
Map<String, Object> model = (mav != null ? mav.getModel() : implicitModel);
Set<Object> sessionAttributeSet = new HashSet<Object>();
sessionAttributeSet.addAll(Arrays.asList(sessionAttributes.value()));
sessionAttributeSet.addAll(Arrays.asList(sessionAttributes.types()));
for (Map.Entry entry : new HashSet<Map.Entry>(model.entrySet())) {
String attrName = (String) entry.getKey();
Object attrValue = entry.getValue();
if (sessionAttributeSet.contains(attrName) ||
(attrValue != null && sessionAttributeSet.contains(attrValue.getClass()))) {