public abstract class AbstractHandlerMapping extends ApplicationObjectSupport implements HandlerMapping, Ordered
HandlerMapping
implementations. Supports ordering, a
default handler, and handler interceptors.getHandlerInternal(javax.portlet.PortletRequest)
,
setDefaultHandler(java.lang.Object)
,
setInterceptors(java.lang.Object[])
,
HandlerInterceptor
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
AbstractHandlerMapping() |
Modifier and Type | Method and Description |
---|---|
protected HandlerInterceptor |
adaptInterceptor(Object interceptor)
Adapt the given interceptor object to the HandlerInterceptor interface.
|
protected void |
extendInterceptors(List<?> interceptors)
Extension hook that subclasses can override to register additional interceptors, given the configured
interceptors (see
setInterceptors(java.lang.Object[]) ). |
protected HandlerInterceptor[] |
getAdaptedInterceptors()
Return the adapted interceptors as HandlerInterceptor array.
|
Object |
getDefaultHandler()
Return the default handler for this handler mapping, or
null if none. |
HandlerExecutionChain |
getHandler(javax.portlet.PortletRequest request)
Look up a handler for the given request, falling back to the default handler if no specific one is found.
|
protected HandlerExecutionChain |
getHandlerExecutionChain(Object handler,
javax.portlet.PortletRequest request)
Build a HandlerExecutionChain for the given handler, including applicable interceptors.
|
protected abstract Object |
getHandlerInternal(javax.portlet.PortletRequest request)
Look up a handler for the given request, returning
null if no specific one is found. |
int |
getOrder() |
protected void |
initApplicationContext()
Initializes the interceptors.
|
protected void |
initInterceptors()
Initialize the specified interceptors, adapting them where necessary.
|
void |
setApplyWebRequestInterceptorsToRenderPhaseOnly(boolean applyWebRequestInterceptorsToRenderPhaseOnly)
Specify whether to apply WebRequestInterceptors to the Portlet render phase only ("true", or whether to apply
them to the Portlet action phase as well ("false").
|
void |
setDefaultHandler(Object defaultHandler)
Set the default handler for this handler mapping.
|
void |
setInterceptors(Object[] interceptors)
Set the interceptors to apply for all handlers mapped by this handler mapping.
|
void |
setOrder(int order)
Specify the order value for this HandlerMapping bean.
|
getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext
public Object getDefaultHandler()
null
if none.public final HandlerExecutionChain getHandler(javax.portlet.PortletRequest request) throws Exception
getHandler
in interface HandlerMapping
request
- current portlet requestException
- if there is an internal errorgetHandlerInternal(javax.portlet.PortletRequest)
public void setApplyWebRequestInterceptorsToRenderPhaseOnly(boolean applyWebRequestInterceptorsToRenderPhaseOnly)
Default is "true", since WebRequestInterceptors are usually built for MVC-style handler execution plus rendering process (which is, for example, the primary target scenario for "Open Session in View" interceptors, offering lazy loading of persistent objects during view rendering). Set this to "false" to have WebRequestInterceptors apply to the action phase as well (for example, in case of an "Open Session in View" interceptor, to allow for lazy loading outside of a transaction during the action phase).
public void setDefaultHandler(Object defaultHandler)
Default is null
, indicating no default handler.
public void setInterceptors(Object[] interceptors)
Supported interceptor types are HandlerInterceptor and WebRequestInterceptor. Each given WebRequestInterceptor will be wrapped in a WebRequestHandlerInterceptorAdapter.
interceptors
- array of handler interceptors, or null
if noneadaptInterceptor(java.lang.Object)
,
HandlerInterceptor
,
WebRequestInterceptor
public final void setOrder(int order)
Default value is Integer.MAX_VALUE
, meaning that it's non-ordered.
Ordered.getOrder()
protected abstract Object getHandlerInternal(javax.portlet.PortletRequest request) throws Exception
null
if no specific one is found. This method is
called by getHandler(javax.portlet.PortletRequest)
; a null
return value will lead to the default handler, if one is set.
Note: This method may also return a pre-built HandlerExecutionChain
, combining a handler object with
dynamically determined interceptors. Statically specified interceptors will get merged into such an existing
chain.
request
- current portlet requestnull
if none foundException
- if there is an internal errorgetHandler(javax.portlet.PortletRequest)
protected HandlerInterceptor adaptInterceptor(Object interceptor)
Supported interceptor types are HandlerInterceptor and WebRequestInterceptor. Each given WebRequestInterceptor will be wrapped in a WebRequestHandlerInterceptorAdapter. Can be overridden in subclasses.
interceptor
- the specified interceptor objectsetApplyWebRequestInterceptorsToRenderPhaseOnly(boolean)
,
HandlerInterceptor
,
WebRequestInterceptor
,
WebRequestHandlerInterceptorAdapter
protected void extendInterceptors(List<?> interceptors)
setInterceptors(java.lang.Object[])
).
Will be invoked before initInterceptors()
adapts the specified interceptors into HandlerInterceptor
instances.
The default implementation is empty.
interceptors
- the configured interceptor List (never null
), allowing to add further interceptors
before as well as after the existing interceptorsprotected final HandlerInterceptor[] getAdaptedInterceptors()
null
if noneprotected HandlerExecutionChain getHandlerExecutionChain(Object handler, javax.portlet.PortletRequest request)
The default implementation simply builds a standard HandlerExecutionChain with the given handler and this handler mapping's common interceptors. Subclasses may override this in order to extend/rearrange the list of interceptors.
NOTE: The passed-in handler object may be a raw handler or a pre-built HandlerExecutionChain. This method should handle those two cases explicitly, either building a new HandlerExecutionChain or extending the existing chain.
For simply adding an interceptor, consider calling super.getHandlerExecutionChain
and invoking HandlerExecutionChain.addInterceptor(com.liferay.portletmvc4spring.HandlerInterceptor)
on the returned chain object.
handler
- the resolved handler instance (never null
)request
- current portlet requestnull
)getAdaptedInterceptors()
protected void initApplicationContext() throws BeansException
initApplicationContext
in class ApplicationObjectSupport
BeansException
extendInterceptors(java.util.List)
,
initInterceptors()
protected void initInterceptors()
Copyright © 2019 Liferay, Inc.. All rights reserved.