RequestMappingHandlerAdapter allows for overriding handleInternal

Issue: SPR-12460
(cherry picked from commit ece2c90)
This commit is contained in:
Juergen Hoeller 2014-11-22 17:37:45 +01:00
parent 1f45dd297d
commit f093a5f749
1 changed files with 35 additions and 37 deletions

View File

@ -138,9 +138,9 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
private Long asyncRequestTimeout;
private CallableProcessingInterceptor[] callableInterceptors = new CallableProcessingInterceptor[] {};
private CallableProcessingInterceptor[] callableInterceptors = new CallableProcessingInterceptor[0];
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[] {};
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[0];
private boolean ignoreDefaultModelOnRedirect = false;
@ -169,21 +169,18 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
new LinkedHashMap<ControllerAdviceBean, Set<Method>>();
/**
* Default constructor.
*/
public RequestMappingHandlerAdapter() {
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
stringHttpMessageConverter.setWriteAcceptCharset(false); // See SPR-7316
stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316
this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
this.messageConverters = new ArrayList<HttpMessageConverter<?>>(4);
this.messageConverters.add(new ByteArrayHttpMessageConverter());
this.messageConverters.add(stringHttpMessageConverter);
this.messageConverters.add(new SourceHttpMessageConverter<Source>());
this.messageConverters.add(new AllEncompassingFormHttpMessageConverter());
}
/**
* Provide resolvers for custom argument types. Custom resolvers are ordered
* after built-in ones. To override the built-in support for argument
@ -306,6 +303,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
return modelAndViewResolvers;
}
/**
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
* If not set, the default constructor is used.
*/
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
this.contentNegotiationManager = contentNegotiationManager;
}
/**
* Provide the converters to use in argument resolvers and return value
* handlers that support reading and/or writing to the body of the
@ -315,19 +320,11 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
this.messageConverters = messageConverters;
}
/**
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
* If not set, the default constructor is used.
*/
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
this.contentNegotiationManager = contentNegotiationManager;
}
/**
* Return the configured message body converters.
*/
public List<HttpMessageConverter<?>> getMessageConverters() {
return messageConverters;
return this.messageConverters;
}
/**
@ -339,10 +336,10 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* Return the configured WebBindingInitializer, or {@code null}.
* Return the configured WebBindingInitializer, or {@code null} if none.
*/
public WebBindingInitializer getWebBindingInitializer() {
return webBindingInitializer;
return this.webBindingInitializer;
}
/**
@ -461,9 +458,8 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* {@inheritDoc}
* <p>A {@link ConfigurableBeanFactory} is expected for resolving
* expressions in method argument default values.
* A {@link ConfigurableBeanFactory} is expected for resolving expressions
* in method argument default values.
*/
@Override
public void setBeanFactory(BeanFactory beanFactory) {
@ -473,12 +469,13 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* Return the owning factory of this bean instance, or {@code null}.
* Return the owning factory of this bean instance, or {@code null} if none.
*/
protected ConfigurableBeanFactory getBeanFactory() {
return this.beanFactory;
}
@Override
public void afterPropertiesSet() {
if (this.argumentResolvers == null) {
@ -638,6 +635,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
}
/**
* Always return {@code true} since any method argument and return value
* type will be processed in some way. A method argument not recognized
@ -651,19 +649,8 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
return true;
}
/**
* This implementation always returns -1. An {@code @RequestMapping}
* method can calculate the lastModified value, call
* {@link WebRequest#checkNotModified(long)}, and return {@code null}
* if the result of that call is {@code true}.
*/
@Override
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
return -1;
}
@Override
protected final ModelAndView handleInternal(HttpServletRequest request,
protected ModelAndView handleInternal(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) {
@ -690,8 +677,19 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
}
/**
* Return the {@link SessionAttributesHandler} instance for the given
* handler type, never {@code null}.
* This implementation always returns -1. An {@code @RequestMapping} method can
* calculate the lastModified value, call {@link WebRequest#checkNotModified(long)},
* and return {@code null} if the result of that call is {@code true}.
*/
@Override
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
return -1;
}
/**
* Return the {@link SessionAttributesHandler} instance for the given handler type
* (never {@code null}).
*/
private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handlerMethod) {
Class<?> handlerType = handlerMethod.getBeanType();