Merge pull request #59 from gadfly3173/bloom

fix: 布隆过滤器放行不匹配的路径
This commit is contained in:
有来技术 2021-08-17 18:33:59 +08:00 committed by GitHub
commit d9ba8b8621
2 changed files with 9 additions and 2 deletions

View File

@ -18,7 +18,8 @@ public class InterceptorConfiguration implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
//注册拦截器
registry.addInterceptor(bloomInterceptorHandler())
.addPathPatterns("/app-api/v1/goods/**");
.addPathPatterns("/app-api/v1/goods/**")
.excludePathPatterns("/app-api/v1/goods/sku/**");
}
@Bean

View File

@ -34,7 +34,13 @@ public class BloomFilterInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String currentUrl = request.getRequestURI();
PathMatcher matcher = new AntPathMatcher();
Map<String, String> pathVariable = matcher.extractUriTemplateVariables("/app-api/v1/goods/{id}", currentUrl);
Map<String, String> pathVariable;
try {
pathVariable = matcher.extractUriTemplateVariables("/app-api/v1/goods/{id}", currentUrl);
} catch (IllegalStateException e) {
// 路径不匹配则放行
return true;
}
if (bloomRedisService.includeByBloomFilter(PmsConstants.PRODUCT_REDIS_BLOOM_FILTER, pathVariable.get("id"))) {
return true;
}