Skip to content

Commit

Permalink
feat: add RestInterceptorRegistry to manage RestInterceptor registrat…
Browse files Browse the repository at this point in the history
…ion - #1

- RestInterceptorRegistry allows registration and configuration of multiple RestInterceptor instances.
- Provides addInterceptor() method to register RestInterceptor and its associated RestfulPattern mappings.
- Supports ordering of interceptors through order configuration.
- build method applies all registered interceptors to the InterceptorRegistry.
- Facilitates cleaner configuration of interceptors with path patterns and order management.

**NOTE**: The `build` method must be called after all interceptors are registered to apply the configurations correctly. This behavior will be refactored in a future update to avoid manual `build` invocation.
  • Loading branch information
Dh3356 committed Nov 27, 2024
1 parent 5ad9b4e commit 99265f2
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.restful_spring.rest_interceptor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

public class RestInterceptorRegistry {

private final InterceptorRegistry registry;
private final List<RestInterceptorRegistration> registrations = new ArrayList<>();

public RestInterceptorRegistry(InterceptorRegistry registry) {
this.registry = registry;
}

public RestInterceptorRegistration addInterceptor(RestInterceptor restInterceptor) {
RestInterceptorRegistration registration = new RestInterceptorRegistration(restInterceptor);
registrations.add(registration);
return registration;
}

public void build() {
this.registrations.forEach(registration -> {
RestInterceptor restInterceptor = registration.getRestInterceptor();

registry.addInterceptor(restInterceptor)
.addPathPatterns(restInterceptor.restfulPatterns.stream()
.map(RestfulPattern::getPath)
.collect(Collectors.toList()))
.order(registration.getOrder());
});
}
}

0 comments on commit 99265f2

Please sign in to comment.