Skip to content

Commit

Permalink
Let DelegatingHandlerMapping implement HandlerMapping directly.
Browse files Browse the repository at this point in the history
We actually do not want to inherit all the functionality implemented in AbstractHandlerMapping. The sole reason we did so before was to override the method to propagate the PathPatternResolver to the downstream HandlerMappings. We now just declare the method on DHM directly.

Fixes GH-1955.
  • Loading branch information
odrotbohm committed Jan 14, 2021
1 parent 72ff0c7 commit b9c0293
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Expand Up @@ -41,8 +41,8 @@
* @author Oliver Gierke
* @soundtrack Benny Greb - Stabila (Moving Parts)
*/
class DelegatingHandlerMapping extends AbstractHandlerMapping
implements org.springframework.data.rest.webmvc.support.DelegatingHandlerMapping {
class DelegatingHandlerMapping
implements org.springframework.data.rest.webmvc.support.DelegatingHandlerMapping, Ordered {

private final List<HandlerMapping> delegates;

Expand All @@ -58,22 +58,19 @@ public DelegatingHandlerMapping(List<HandlerMapping> delegates) {
this.delegates = delegates;
}

@java.lang.SuppressWarnings("all")
public List<HandlerMapping> getDelegates() {
return this.delegates;
}

@Override
public void setPatternParser(PathPatternParser parser) {

super.setPatternParser(parser);
void setPatternParser(PathPatternParser parser) {

delegates.stream() //
.filter(AbstractHandlerMapping.class::isInstance) //
.map(AbstractHandlerMapping.class::cast) //
.forEach(it -> it.setPatternParser(parser));
}

@SuppressWarnings("all")
public List<HandlerMapping> getDelegates() {
return this.delegates;
}

/*
* (non-Javadoc)
* @see java.lang.Iterable#iterator()
Expand All @@ -94,10 +91,10 @@ public int getOrder() {

/*
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.AbstractHandlerMapping#getHandlerInternal(javax.servlet.http.HttpServletRequest)
* @see org.springframework.web.servlet.HandlerMapping#getHandler(javax.servlet.http.HttpServletRequest)
*/
@Override
protected Object getHandlerInternal(HttpServletRequest request) throws Exception {
public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
return HandlerSelectionResult.from(request, delegates).resultOrException();
}

Expand Down
Expand Up @@ -183,7 +183,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
private Lazy<BaseUri> baseUri;
private Lazy<RepositoryResourceMappings> resourceMappings;
private Lazy<Repositories> repositories;
private Lazy<AbstractHandlerMapping> restHandlerMapping;
private Lazy<DelegatingHandlerMapping> restHandlerMapping;
private Lazy<ResourceMetadataHandlerMethodArgumentResolver> resourceMetadataHandlerMethodArgumentResolver;
private Lazy<ExcerptProjector> excerptProjector;
private Lazy<PersistentEntities> persistentEntities;
Expand Down Expand Up @@ -241,7 +241,7 @@ public RepositoryRestMvcConfiguration( //
this.baseUri = Lazy.of(() -> context.getBean(BaseUri.class));
this.resourceMappings = Lazy.of(() -> context.getBean(RepositoryResourceMappings.class));
this.repositories = Lazy.of(() -> context.getBean(Repositories.class));
this.restHandlerMapping = Lazy.of(() -> context.getBean("restHandlerMapping", AbstractHandlerMapping.class));
this.restHandlerMapping = Lazy.of(() -> context.getBean("restHandlerMapping", DelegatingHandlerMapping.class));
this.resourceMetadataHandlerMethodArgumentResolver = Lazy
.of(() -> context.getBean(ResourceMetadataHandlerMethodArgumentResolver.class));
this.excerptProjector = Lazy.of(() -> context.getBean(ExcerptProjector.class));
Expand Down Expand Up @@ -638,7 +638,7 @@ public RequestMappingHandlerAdapter repositoryExporterHandlerAdapter(
* @return
*/
@Bean
public AbstractHandlerMapping restHandlerMapping(Repositories repositories,
public DelegatingHandlerMapping restHandlerMapping(Repositories repositories,
RepositoryResourceMappings resourceMappings, Optional<JpaHelper> jpaHelper,
RepositoryRestConfiguration repositoryRestConfiguration, CorsConfigurationAware corsRestConfiguration) {

Expand Down

0 comments on commit b9c0293

Please sign in to comment.