Skip to content

Commit 10a2f50

Browse files
committed
Overridable invokeHandlerMethod and createInvocableHandlerMethod hooks
Issue: SPR-13293
1 parent b1d6ae7 commit 10a2f50

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
* {@link #setArgumentResolvers} and {@link #setReturnValueHandlers(List)}.
110110
*
111111
* @author Rossen Stoyanchev
112+
* @author Juergen Hoeller
112113
* @since 3.1
113114
* @see HandlerMethodArgumentResolver
114115
* @see HandlerMethodReturnValueHandler
@@ -720,12 +721,12 @@ protected ModelAndView handleInternal(HttpServletRequest request,
720721
if (session != null) {
721722
Object mutex = WebUtils.getSessionMutex(session);
722723
synchronized (mutex) {
723-
return invokeHandleMethod(request, response, handlerMethod);
724+
return invokeHandlerMethod(request, response, handlerMethod);
724725
}
725726
}
726727
}
727728

728-
return invokeHandleMethod(request, response, handlerMethod);
729+
return invokeHandlerMethod(request, response, handlerMethod);
729730
}
730731

731732
/**
@@ -761,25 +762,32 @@ private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handl
761762
/**
762763
* Invoke the {@link RequestMapping} handler method preparing a {@link ModelAndView}
763764
* if view resolution is required.
765+
* @since 4.2
766+
* @see #createInvocableHandlerMethod(HandlerMethod)
764767
*/
765-
private ModelAndView invokeHandleMethod(HttpServletRequest request,
768+
protected ModelAndView invokeHandlerMethod(HttpServletRequest request,
766769
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
767770

768771
ServletWebRequest webRequest = new ServletWebRequest(request, response);
769772

770773
WebDataBinderFactory binderFactory = getDataBinderFactory(handlerMethod);
771774
ModelFactory modelFactory = getModelFactory(handlerMethod, binderFactory);
772-
ServletInvocableHandlerMethod requestMappingMethod = createRequestMappingMethod(handlerMethod, binderFactory);
775+
776+
ServletInvocableHandlerMethod invocableMethod = createInvocableHandlerMethod(handlerMethod);
777+
invocableMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
778+
invocableMethod.setHandlerMethodReturnValueHandlers(this.returnValueHandlers);
779+
invocableMethod.setDataBinderFactory(binderFactory);
780+
invocableMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
773781

774782
ModelAndViewContainer mavContainer = new ModelAndViewContainer();
775783
mavContainer.addAllAttributes(RequestContextUtils.getInputFlashMap(request));
776-
modelFactory.initModel(webRequest, mavContainer, requestMappingMethod);
784+
modelFactory.initModel(webRequest, mavContainer, invocableMethod);
777785
mavContainer.setIgnoreDefaultModelOnRedirect(this.ignoreDefaultModelOnRedirect);
778786

779787
AsyncWebRequest asyncWebRequest = WebAsyncUtils.createAsyncWebRequest(request, response);
780788
asyncWebRequest.setTimeout(this.asyncRequestTimeout);
781789

782-
final WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
790+
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
783791
asyncManager.setTaskExecutor(this.taskExecutor);
784792
asyncManager.setAsyncWebRequest(asyncWebRequest);
785793
asyncManager.registerCallableInterceptors(this.callableInterceptors);
@@ -789,32 +797,28 @@ private ModelAndView invokeHandleMethod(HttpServletRequest request,
789797
Object result = asyncManager.getConcurrentResult();
790798
mavContainer = (ModelAndViewContainer) asyncManager.getConcurrentResultContext()[0];
791799
asyncManager.clearConcurrentResult();
792-
793800
if (logger.isDebugEnabled()) {
794801
logger.debug("Found concurrent result value [" + result + "]");
795802
}
796-
requestMappingMethod = requestMappingMethod.wrapConcurrentResult(result);
803+
invocableMethod = invocableMethod.wrapConcurrentResult(result);
797804
}
798805

799-
requestMappingMethod.invokeAndHandle(webRequest, mavContainer);
800-
806+
invocableMethod.invokeAndHandle(webRequest, mavContainer);
801807
if (asyncManager.isConcurrentHandlingStarted()) {
802808
return null;
803809
}
804810

805811
return getModelAndView(mavContainer, modelFactory, webRequest);
806812
}
807813

808-
private ServletInvocableHandlerMethod createRequestMappingMethod(
809-
HandlerMethod handlerMethod, WebDataBinderFactory binderFactory) {
810-
811-
ServletInvocableHandlerMethod requestMethod;
812-
requestMethod = new ServletInvocableHandlerMethod(handlerMethod);
813-
requestMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
814-
requestMethod.setHandlerMethodReturnValueHandlers(this.returnValueHandlers);
815-
requestMethod.setDataBinderFactory(binderFactory);
816-
requestMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
817-
return requestMethod;
814+
/**
815+
* Create a {@link ServletInvocableHandlerMethod} from the given {@link HandlerMethod} definition.
816+
* @param handlerMethod the {@link HandlerMethod} definition
817+
* @return the corresponding {@link ServletInvocableHandlerMethod} (or custom subclass thereof)
818+
* @since 4.2
819+
*/
820+
protected ServletInvocableHandlerMethod createInvocableHandlerMethod(HandlerMethod handlerMethod) {
821+
return new ServletInvocableHandlerMethod(handlerMethod);
818822
}
819823

820824
private ModelFactory getModelFactory(HandlerMethod handlerMethod, WebDataBinderFactory binderFactory) {

0 commit comments

Comments
 (0)