Skip to content

Commit f093a5f

Browse files
committed
RequestMappingHandlerAdapter allows for overriding handleInternal
Issue: SPR-12460 (cherry picked from commit ece2c90)
1 parent 1f45dd2 commit f093a5f

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

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

+35-37
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
138138

139139
private Long asyncRequestTimeout;
140140

141-
private CallableProcessingInterceptor[] callableInterceptors = new CallableProcessingInterceptor[] {};
141+
private CallableProcessingInterceptor[] callableInterceptors = new CallableProcessingInterceptor[0];
142142

143-
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[] {};
143+
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[0];
144144

145145
private boolean ignoreDefaultModelOnRedirect = false;
146146

@@ -169,21 +169,18 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
169169
new LinkedHashMap<ControllerAdviceBean, Set<Method>>();
170170

171171

172-
/**
173-
* Default constructor.
174-
*/
175172
public RequestMappingHandlerAdapter() {
176-
177173
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
178-
stringHttpMessageConverter.setWriteAcceptCharset(false); // See SPR-7316
174+
stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316
179175

180-
this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
176+
this.messageConverters = new ArrayList<HttpMessageConverter<?>>(4);
181177
this.messageConverters.add(new ByteArrayHttpMessageConverter());
182178
this.messageConverters.add(stringHttpMessageConverter);
183179
this.messageConverters.add(new SourceHttpMessageConverter<Source>());
184180
this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
185181
}
186182

183+
187184
/**
188185
* Provide resolvers for custom argument types. Custom resolvers are ordered
189186
* after built-in ones. To override the built-in support for argument
@@ -306,6 +303,14 @@ public List<ModelAndViewResolver> getModelAndViewResolvers() {
306303
return modelAndViewResolvers;
307304
}
308305

306+
/**
307+
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
308+
* If not set, the default constructor is used.
309+
*/
310+
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
311+
this.contentNegotiationManager = contentNegotiationManager;
312+
}
313+
309314
/**
310315
* Provide the converters to use in argument resolvers and return value
311316
* handlers that support reading and/or writing to the body of the
@@ -315,19 +320,11 @@ public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters
315320
this.messageConverters = messageConverters;
316321
}
317322

318-
/**
319-
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
320-
* If not set, the default constructor is used.
321-
*/
322-
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
323-
this.contentNegotiationManager = contentNegotiationManager;
324-
}
325-
326323
/**
327324
* Return the configured message body converters.
328325
*/
329326
public List<HttpMessageConverter<?>> getMessageConverters() {
330-
return messageConverters;
327+
return this.messageConverters;
331328
}
332329

333330
/**
@@ -339,10 +336,10 @@ public void setWebBindingInitializer(WebBindingInitializer webBindingInitializer
339336
}
340337

341338
/**
342-
* Return the configured WebBindingInitializer, or {@code null}.
339+
* Return the configured WebBindingInitializer, or {@code null} if none.
343340
*/
344341
public WebBindingInitializer getWebBindingInitializer() {
345-
return webBindingInitializer;
342+
return this.webBindingInitializer;
346343
}
347344

348345
/**
@@ -461,9 +458,8 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc
461458
}
462459

463460
/**
464-
* {@inheritDoc}
465-
* <p>A {@link ConfigurableBeanFactory} is expected for resolving
466-
* expressions in method argument default values.
461+
* A {@link ConfigurableBeanFactory} is expected for resolving expressions
462+
* in method argument default values.
467463
*/
468464
@Override
469465
public void setBeanFactory(BeanFactory beanFactory) {
@@ -473,12 +469,13 @@ public void setBeanFactory(BeanFactory beanFactory) {
473469
}
474470

475471
/**
476-
* Return the owning factory of this bean instance, or {@code null}.
472+
* Return the owning factory of this bean instance, or {@code null} if none.
477473
*/
478474
protected ConfigurableBeanFactory getBeanFactory() {
479475
return this.beanFactory;
480476
}
481477

478+
482479
@Override
483480
public void afterPropertiesSet() {
484481
if (this.argumentResolvers == null) {
@@ -638,6 +635,7 @@ private void initControllerAdviceCache() {
638635
}
639636
}
640637

638+
641639
/**
642640
* Always return {@code true} since any method argument and return value
643641
* type will be processed in some way. A method argument not recognized
@@ -651,19 +649,8 @@ protected boolean supportsInternal(HandlerMethod handlerMethod) {
651649
return true;
652650
}
653651

654-
/**
655-
* This implementation always returns -1. An {@code @RequestMapping}
656-
* method can calculate the lastModified value, call
657-
* {@link WebRequest#checkNotModified(long)}, and return {@code null}
658-
* if the result of that call is {@code true}.
659-
*/
660-
@Override
661-
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
662-
return -1;
663-
}
664-
665652
@Override
666-
protected final ModelAndView handleInternal(HttpServletRequest request,
653+
protected ModelAndView handleInternal(HttpServletRequest request,
667654
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
668655

669656
if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) {
@@ -690,8 +677,19 @@ protected final ModelAndView handleInternal(HttpServletRequest request,
690677
}
691678

692679
/**
693-
* Return the {@link SessionAttributesHandler} instance for the given
694-
* handler type, never {@code null}.
680+
* This implementation always returns -1. An {@code @RequestMapping} method can
681+
* calculate the lastModified value, call {@link WebRequest#checkNotModified(long)},
682+
* and return {@code null} if the result of that call is {@code true}.
683+
*/
684+
@Override
685+
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
686+
return -1;
687+
}
688+
689+
690+
/**
691+
* Return the {@link SessionAttributesHandler} instance for the given handler type
692+
* (never {@code null}).
695693
*/
696694
private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handlerMethod) {
697695
Class<?> handlerType = handlerMethod.getBeanType();

0 commit comments

Comments
 (0)