org.resthub.web.springmvc.router
Class RouterHandlerMapping
java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.handler.AbstractHandlerMapping
org.resthub.web.springmvc.router.RouterHandlerMapping
- 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.HandlerMapping
public class RouterHandlerMapping
- extends org.springframework.web.servlet.handler.AbstractHandlerMapping
Implementation of the HandlerMapping
interface that maps handlers based on HTTP routes defined in a route
configuration file.
RouterHandlerMapping is not the default HandlerMapping registered in
DispatcherServlet in SpringMVC. You
need to declare and configure it in your DispatcherServlet context, by adding
a RouterHandlerMapping bean explicitly. RouterHandlerMapping needs the name
of the route configuration file (available in the application classpath); it
also allows for registering custom interceptors:
<bean
class="org.resthub.web.springmvc.router.RouterHandlerMapping">
<property name="routeFile" value="routes.conf" /> <property
name="servletPrefix" value="/myservlet" /> <property
name="interceptors" > ... </property> </bean>
Annotated controllers should be marked with the Controller
stereotype at the type level. This is not strictly necessary because the
methodeInvoker will try to map the Controller.invoker anyway using the
current ApplicationContext. The RequestMapping is not taken into
account here.
RouterHandlerMapping loads routes configuration from a file for route
configuration syntax (the Router implementation is adapted from Play!
Framework http://www.playframework.org/documentation/1.0.3/routes#syntax).
Example:
GET /home PageController.showPage(id:'home') GET
/page/{id} PageController.showPage POST /customer/{<[0-9]+>customerid}
CustomerController.createCustomer
The RouterHandlerAdapter is responsible for choosing and
invoking the right controller method, as mapped by this HandlerMapping.
- Author:
- Brian Clozel
- See Also:
AbstractHandlerMapping
| Fields inherited from interface org.springframework.web.servlet.HandlerMapping |
BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE |
| Fields inherited from interface org.springframework.core.Ordered |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE |
| Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping |
adaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initInterceptors, setAlwaysUseFullPath, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setUrlDecode, setUrlPathHelper |
| 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 |
RouterHandlerMapping
public RouterHandlerMapping()
getServletPrefix
public String getServletPrefix()
- Servlet Prefix to be added in front of all routes Injected by bean
configuration (in servlet.xml)
setServletPrefix
public void setServletPrefix(String servletPrefix)
getRouteFile
public String getRouteFile()
- Routes configuration File name< Injected by bean configuration (in
servlet.xml)
setRouteFile
public void setRouteFile(String routeFile)
getHandlerInternal
protected Object getHandlerInternal(javax.servlet.http.HttpServletRequest request)
throws Exception
- Specified by:
getHandlerInternal in class org.springframework.web.servlet.handler.AbstractHandlerMapping
- Parameters:
request - the HTTP Servlet request
- Returns:
- a RouterHandler, containing matching route + wrapped request
- Throws:
Exception
initApplicationContext
protected void initApplicationContext()
throws org.springframework.beans.BeansException
- Inits Routes from route configuration file
- Overrides:
initApplicationContext in class org.springframework.web.servlet.handler.AbstractHandlerMapping
- Throws:
org.springframework.beans.BeansException
Copyright © 2010-2012. All Rights Reserved.