org.resthub.web.springmvc.router
Class RouterHandlerAdapter

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.support.WebContentGenerator
              extended by org.resthub.web.springmvc.router.RouterHandlerAdapter
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.HandlerAdapter

public class RouterHandlerAdapter
extends org.springframework.web.servlet.support.WebContentGenerator
implements org.springframework.web.servlet.HandlerAdapter, org.springframework.core.Ordered

Implementation of the HandlerAdapter interface that maps HTTPServletRequests on Routes defined in route file configuration. The route file name can be configured handler methods based on RoutesHTTP paths, HTTP methods and request parameters expressed through the RequestMapping annotation.

Supports request parameter binding through the RequestParam annotation. Also supports the ModelAttribute annotation for exposing model attribute values to the view, as well as InitBinder for binder initialization methods and SessionAttributes for automatic session management of specific attributes.

This adapter can be customized through various bean properties. A common use case is to apply shared binder initialization logic through a custom WebBindingInitializer.

Author:
Brian Clozel

Nested Class Summary
static class RouterHandlerAdapter.LocalVariablesNamesTracer
          Runtime part.
 class RouterHandlerAdapter.RouterMethodResolver
          Resolve Controller and Action for the given route (that contains the fullAction "controller.action")
 
Field Summary
 
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator
METHOD_GET, METHOD_HEAD, METHOD_POST
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
RouterHandlerAdapter()
           
 
Method Summary
protected  void addReturnValueAsModelAttribute(Method handlerMethod, Class handlerType, Object returnValue, org.springframework.ui.ExtendedModelMap implicitModel)
           
protected  org.springframework.web.bind.ServletRequestDataBinder createBinder(javax.servlet.http.HttpServletRequest request, Object target, String objectName)
          Template method for creating a new ServletRequestDataBinder instance.
protected  org.springframework.http.HttpInputMessage createHttpInputMessage(javax.servlet.http.HttpServletRequest servletRequest)
          Template method for creating a new HttpInputMessage instance.
protected  org.springframework.http.HttpOutputMessage createHttpOutputMessage(javax.servlet.http.HttpServletResponse servletResponse)
          Template method for creating a new HttpOuputMessage instance.
 long getLastModified(javax.servlet.http.HttpServletRequest request, Object handler)
           
 org.springframework.http.converter.HttpMessageConverter<?>[] getMessageConverters()
          Return the message body converters that this adapter has been configured with.
 int getOrder()
          Get the order value for this HandlerAdapter bean.
 org.springframework.web.servlet.ModelAndView handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler)
          Handles a request, calling the matched controller+action.
protected  void initApplicationContext()
          Load and cache @Controller classes at application start.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
           
 void setCustomArgumentResolver(org.springframework.web.bind.support.WebArgumentResolver argumentResolver)
          Set a custom WebArgumentResolvers to use for special method parameter types.
 void setCustomArgumentResolvers(org.springframework.web.bind.support.WebArgumentResolver[] argumentResolvers)
          Set one or more custom WebArgumentResolvers to use for special method parameter types.
 void setCustomModelAndViewResolvers(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver[] customModelAndViewResolvers)
          Set one or more custom ModelAndViewResolvers to use for special method return types.
 void setMessageConverters(org.springframework.http.converter.HttpMessageConverter<?>[] messageConverters)
          Set the message body converters to use.
 void setOrder(int order)
          Specify the order value for this HandlerAdapter bean.
 void setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer)
          Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses.
 boolean supports(Object handler)
          Says wether or not this handlerAdapter supports the given handler, i.e. knows how to handle requests mapped with this handler.
 
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RouterHandlerAdapter

public RouterHandlerAdapter()
Method Detail

getOrder

public int getOrder()
Get the order value for this HandlerAdapter bean.

Default value is Ordered.LOWEST_PRECEDENCE, meaning that it's non-ordered.

Specified by:
getOrder in interface org.springframework.core.Ordered
See Also:
Ordered.getOrder()

setOrder

public void setOrder(int order)
Specify the order value for this HandlerAdapter bean.

Default value is Ordered.LOWEST_PRECEDENCE, meaning that it's non-ordered.

See Also:
Ordered.getOrder()

setWebBindingInitializer

public void setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer)
Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses.


setCustomArgumentResolver

public void setCustomArgumentResolver(org.springframework.web.bind.support.WebArgumentResolver argumentResolver)
Set a custom WebArgumentResolvers to use for special method parameter types.

Such a custom WebArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.


setCustomArgumentResolvers

public void setCustomArgumentResolvers(org.springframework.web.bind.support.WebArgumentResolver[] argumentResolvers)
Set one or more custom WebArgumentResolvers to use for special method parameter types.

Any such custom WebArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.


setCustomModelAndViewResolvers

public void setCustomModelAndViewResolvers(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver[] customModelAndViewResolvers)
Set one or more custom ModelAndViewResolvers to use for special method return types.

Any such custom ModelAndViewResolver will kick in first, having a chance to resolve a return value before the standard ModelAndView handling kicks in.


setMessageConverters

public void setMessageConverters(org.springframework.http.converter.HttpMessageConverter<?>[] messageConverters)
Set the message body converters to use.

These converters are used to convert from and to HTTP requests and responses.


getMessageConverters

public org.springframework.http.converter.HttpMessageConverter<?>[] getMessageConverters()
Return the message body converters that this adapter has been configured with.


createBinder

protected org.springframework.web.bind.ServletRequestDataBinder createBinder(javax.servlet.http.HttpServletRequest request,
                                                                             Object target,
                                                                             String objectName)
                                                                      throws Exception
Template method for creating a new ServletRequestDataBinder instance.

The default implementation creates a standard ServletRequestDataBinder. This can be overridden for custom ServletRequestDataBinder subclasses.

Parameters:
request - current HTTP request
target - the target object to bind onto (or null if the binder is just used to convert a plain parameter value)
objectName - the objectName of the target object
Returns:
the ServletRequestDataBinder instance to use
Throws:
Exception - in case of invalid state or arguments
See Also:
ServletRequestDataBinder.bind(javax.servlet.ServletRequest), DataBinder.convertIfNecessary(Object, Class, org.springframework.core.MethodParameter)

createHttpInputMessage

protected org.springframework.http.HttpInputMessage createHttpInputMessage(javax.servlet.http.HttpServletRequest servletRequest)
                                                                    throws Exception
Template method for creating a new HttpInputMessage instance.

The default implementation creates a standard ServletServerHttpRequest. This can be overridden for custom HttpInputMessage implementations

Parameters:
servletRequest - current HTTP request
Returns:
the HttpInputMessage instance to use
Throws:
Exception - in case of errors

createHttpOutputMessage

protected org.springframework.http.HttpOutputMessage createHttpOutputMessage(javax.servlet.http.HttpServletResponse servletResponse)
                                                                      throws Exception
Template method for creating a new HttpOuputMessage instance.

The default implementation creates a standard ServletServerHttpResponse. This can be overridden for custom HttpOutputMessage implementations

Parameters:
servletResponse - current HTTP response
Returns:
the HttpInputMessage instance to use
Throws:
Exception - in case of errors

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)

getLastModified

public long getLastModified(javax.servlet.http.HttpServletRequest request,
                            Object handler)
Specified by:
getLastModified in interface org.springframework.web.servlet.HandlerAdapter

initApplicationContext

protected void initApplicationContext()
                               throws org.springframework.beans.BeansException
Load and cache @Controller classes at application start.

Overrides:
initApplicationContext in class org.springframework.context.support.ApplicationObjectSupport
Throws:
org.springframework.beans.BeansException

supports

public boolean supports(Object handler)
Says wether or not this handlerAdapter supports the given handler, i.e. knows how to handle requests mapped with this handler.

Specified by:
supports in interface org.springframework.web.servlet.HandlerAdapter
Parameters:
handler - the handler to adapt
Returns:
true if the current adapter supports the handler given in parameter.

handle

public org.springframework.web.servlet.ModelAndView handle(javax.servlet.http.HttpServletRequest request,
                                                           javax.servlet.http.HttpServletResponse response,
                                                           Object handler)
                                                    throws Exception
Handles a request, calling the matched controller+action.

Specified by:
handle in interface org.springframework.web.servlet.HandlerAdapter
Parameters:
request - the HTTP request
response - the HTTP response
handler - the handler mapped for this request (should be an instance of RouterHandler)
Returns:
a ModelAndview (ModelMap + ViewName) resulting from the controller.action call.
Throws:
Exception

addReturnValueAsModelAttribute

protected void addReturnValueAsModelAttribute(Method handlerMethod,
                                              Class handlerType,
                                              Object returnValue,
                                              org.springframework.ui.ExtendedModelMap implicitModel)


Copyright © 2010-2012. All Rights Reserved.