From 7fdeefec528449a60e53c9514076f770b85882e8 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 23 Aug 2012 12:12:43 +0200 Subject: [PATCH] DATAREST-40 - Added copy constructor to ease setup of HandlerAdapter. ResourceEnricherInvokingHandlerAdapter now has a copy constructor to allow setting it up from a default RequestMappingHandlerAdapter. The reason we introduce this is that WebMvcConfigurationSupport unfortunately does not allow customizing the handler adapter class to be used as its instantiations is buried in a method with more setup code. With the copy constructor introduced one can simply take the configured instance WebMvcConfigurationSupport provides and pipe it into the custom ResourceEnricherInvokingHandlerAdapter. --- ...esourceEnricherInvokingHandlerAdapter.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceEnricherInvokingHandlerAdapter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceEnricherInvokingHandlerAdapter.java index b9f703729..f9056f74c 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceEnricherInvokingHandlerAdapter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ResourceEnricherInvokingHandlerAdapter.java @@ -20,6 +20,10 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.ResourceEnricher; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.util.Assert; +import org.springframework.web.bind.support.WebBindingInitializer; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; import org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; @@ -40,6 +44,29 @@ public class ResourceEnricherInvokingHandlerAdapter extends RequestMappingHandle @Autowired(required = false) private List> resourcesEnrichers = new ArrayList>(); + /** + * Empty constructor to setup a {@link ResourceEnricherInvokingHandlerAdapter}. + */ + public ResourceEnricherInvokingHandlerAdapter() { + + } + + /** + * Copy constructor to copy configuration of {@link HttpMessageConverter}s, {@link WebBindingInitializer}, custom + * {@link HandlerMethodArgumentResolver}s and custom {@link HandlerMethodReturnValueHandler}s. + * + * @param original must not be {@literal null}. + */ + public ResourceEnricherInvokingHandlerAdapter(RequestMappingHandlerAdapter original) { + + Assert.notNull(original); + + setMessageConverters(original.getMessageConverters()); + setWebBindingInitializer(original.getWebBindingInitializer()); + setCustomArgumentResolvers(original.getCustomArgumentResolvers()); + setCustomReturnValueHandlers(original.getCustomReturnValueHandlers()); + } + /* * (non-Javadoc) * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#afterPropertiesSet()