@Bean public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() { SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler(); handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes()); handler.setMessageConverter(brokerMessageConverter()); handler.setValidator(simpValidator()); List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>(); addArgumentResolvers(argumentResolvers); handler.setCustomArgumentResolvers(argumentResolvers); List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>(); addReturnValueHandlers(returnValueHandlers); handler.setCustomReturnValueHandlers(returnValueHandlers); PathMatcher pathMatcher = this.getBrokerRegistry().getPathMatcher(); if (pathMatcher != null) { handler.setPathMatcher(pathMatcher); } return handler; }
private static Set<String> prependLeadingSlash(Collection<String> patterns, PathMatcher pathMatcher) { if (patterns == null) { return Collections.emptySet(); } boolean slashSeparator = pathMatcher.combine("a", "a").equals("a/a"); Set<String> result = new LinkedHashSet<String>(patterns.size()); for (String pattern : patterns) { if (slashSeparator) { if (StringUtils.hasLength(pattern) && !pattern.startsWith("/")) { pattern = "/" + pattern; } } result.add(pattern); } return result; }
/** * Private constructor accepting a collection of patterns. */ private PatternsRequestCondition(Collection<String> patterns, UrlPathHelper urlPathHelper, PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch, List<String> fileExtensions) { this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns)); this.pathHelper = (urlPathHelper != null ? urlPathHelper : new UrlPathHelper()); this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher()); this.useSuffixPatternMatch = useSuffixPatternMatch; this.useTrailingSlashMatch = useTrailingSlashMatch; if (fileExtensions != null) { for (String fileExtension : fileExtensions) { if (fileExtension.charAt(0) != '.') { fileExtension = "." + fileExtension; } this.fileExtensions.add(fileExtension); } } }
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) { PathMatcher pathMatcher = new AntPathMatcher(); List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>(); for (Object interceptor : this.registry.getInterceptors()) { if (interceptor instanceof MappedInterceptor) { MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor; if (mappedInterceptor.matches(lookupPath, pathMatcher)) { result.add(mappedInterceptor.getInterceptor()); } } else if (interceptor instanceof HandlerInterceptor) { result.add((HandlerInterceptor) interceptor); } else { fail("Unexpected interceptor type: " + interceptor.getClass().getName()); } } return result; }
@Autowired @Qualifier("simpleBrokerMessageHandler") public void onSimpleBrockedMessageChannel(AbstractBrokerMessageHandler handler) { // here we try to inherit matcher from subscription registry if (!(handler instanceof SimpleBrokerMessageHandler)) { return; } SubscriptionRegistry registry = ((SimpleBrokerMessageHandler) handler).getSubscriptionRegistry(); if (!(registry instanceof DefaultSubscriptionRegistry)) { return; } PathMatcher pathMatcher = ((DefaultSubscriptionRegistry) registry).getPathMatcher(); if(pathMatcher != null) { this.pathMatcher = pathMatcher; } }
/** * Private constructor accepting a collection of patterns. */ private PatternsRequestCondition(Collection<String> patterns, UrlPathHelper urlPathHelper, PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch, List<String> fileExtensions) { this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns)); this.pathHelper = urlPathHelper != null ? urlPathHelper : new UrlPathHelper(); this.pathMatcher = pathMatcher != null ? pathMatcher : new AntPathMatcher(); this.useSuffixPatternMatch = useSuffixPatternMatch; this.useTrailingSlashMatch = useTrailingSlashMatch; if (fileExtensions != null) { for (String fileExtension : fileExtensions) { if (fileExtension.charAt(0) != '.') { fileExtension = "." + fileExtension; } this.fileExtensions.add(fileExtension); } } }
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) { PathMatcher pathMatcher = new AntPathMatcher(); List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>(); for (Object i : registry.getInterceptors()) { if (i instanceof MappedInterceptor) { MappedInterceptor mappedInterceptor = (MappedInterceptor) i; if (mappedInterceptor.matches(lookupPath, pathMatcher)) { result.add(mappedInterceptor.getInterceptor()); } } else if (i instanceof HandlerInterceptor){ result.add((HandlerInterceptor) i); } else { fail("Unexpected interceptor type: " + i.getClass().getName()); } } return result; }
private boolean hasMatch(PathMatcher pathMatcher, String path, List<String> patterns) { for (String pattern : patterns) { if (pathMatcher.match(pattern, path)) { return true; } } return false; }
public static Set<Resource> findMatchingResources( Resource rootResource, String locationPattern, PathMatcher pathMatcher) throws IOException { Object root = VfsPatternUtils.findRoot(rootResource.getURL()); PatternVirtualFileVisitor visitor = new PatternVirtualFileVisitor(VfsPatternUtils.getPath(root), locationPattern, pathMatcher); VfsPatternUtils.visit(root, visitor); return visitor.getResources(); }
@Bean public ResourceUrlProvider mvcResourceUrlProvider() { ResourceUrlProvider urlProvider = new ResourceUrlProvider(); UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper(); if (pathHelper != null) { urlProvider.setUrlPathHelper(pathHelper); } PathMatcher pathMatcher = getPathMatchConfigurer().getPathMatcher(); if (pathMatcher != null) { urlProvider.setPathMatcher(pathMatcher); } return urlProvider; }
/** * Return a global {@link PathMatcher} instance for path matching * patterns in {@link HandlerMapping}s. * This instance can be configured using the {@link PathMatchConfigurer} * in {@link #configurePathMatch(PathMatchConfigurer)}. * @since 4.1 */ @Bean public PathMatcher mvcPathMatcher() { if (getPathMatchConfigurer().getPathMatcher() != null) { return getPathMatchConfigurer().getPathMatcher(); } else { return new AntPathMatcher(); } }
@Test public void addInterceptorsWithCustomPathMatcher() { PathMatcher pathMatcher = Mockito.mock(PathMatcher.class); this.registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher); MappedInterceptor mappedInterceptor = (MappedInterceptor) this.registry.getInterceptors().get(0); assertSame(pathMatcher, mappedInterceptor.getPathMatcher()); }
@Test public void defaultPathMatchConfiguration() throws Exception { ApplicationContext context = initContext(WebConfig.class); UrlPathHelper urlPathHelper = context.getBean(UrlPathHelper.class); PathMatcher pathMatcher = context.getBean(PathMatcher.class); assertNotNull(urlPathHelper); assertNotNull(pathMatcher); assertEquals(AntPathMatcher.class, pathMatcher.getClass()); }
@Test public void configurePathMatch() throws Exception { final PathMatcher pathMatcher = mock(PathMatcher.class); final UrlPathHelper pathHelper = mock(UrlPathHelper.class); List<WebMvcConfigurer> configurers = new ArrayList<WebMvcConfigurer>(); configurers.add(new WebMvcConfigurerAdapter() { @Override public void configurePathMatch(PathMatchConfigurer configurer) { configurer.setUseRegisteredSuffixPatternMatch(true) .setUseTrailingSlashMatch(false) .setUrlPathHelper(pathHelper) .setPathMatcher(pathMatcher); } }); delegatingConfig.setConfigurers(configurers); RequestMappingHandlerMapping handlerMapping = delegatingConfig.requestMappingHandlerMapping(); assertNotNull(handlerMapping); assertEquals("PathMatchConfigurer should configure RegisteredSuffixPatternMatch", true, handlerMapping.useRegisteredSuffixPatternMatch()); assertEquals("PathMatchConfigurer should configure SuffixPatternMatch", true, handlerMapping.useSuffixPatternMatch()); assertEquals("PathMatchConfigurer should configure TrailingSlashMatch", false, handlerMapping.useTrailingSlashMatch()); assertEquals("PathMatchConfigurer should configure UrlPathHelper", pathHelper, handlerMapping.getUrlPathHelper()); assertEquals("PathMatchConfigurer should configure PathMatcher", pathMatcher, handlerMapping.getPathMatcher()); }
public static Set<Resource> findMatchingResources( URL rootDirURL, String locationPattern, PathMatcher pathMatcher) throws IOException { Object root = VfsPatternUtils.findRoot(rootDirURL); PatternVirtualFileVisitor visitor = new PatternVirtualFileVisitor(VfsPatternUtils.getPath(root), locationPattern, pathMatcher); VfsPatternUtils.visit(root, visitor); return visitor.getResources(); }
boolean matchPath(Set<PathMatcher> matchers, HttpServletRequest request) { for (PathMatcher matcher : matchers) { if (matcher.isPattern(request.getPathInfo())) { return true; } } return false; }
@BusPathMatcher // There is a @Bean of type PathMatcher coming from Spring MVC @ConditionalOnMissingBean(name = BusAutoConfiguration.BUS_PATH_MATCHER_NAME) @Bean(name = BusAutoConfiguration.BUS_PATH_MATCHER_NAME) public PathMatcher busPathMatcher() { return new DefaultBusPathMatcher(new AntPathMatcher(":")); }
/** * Returns an instance of a {@link PathMatcher}. Used by the messageHandlers for * matching the topicURI to a destination */ protected PathMatcher pathMatcher() { if (this.internalPathMatcher == null) { this.internalPathMatcher = new AntPathMatcher(); } return this.internalPathMatcher; }
public WampAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, EventMessenger eventMessenger, ConversionService conversionService, MethodParameterConverter methodParameterConverter, PathMatcher pathMatcher, WampMessageSelector wampMessageSelector, MessageConverter messageConverter) { this.clientInboundChannel = clientInboundChannel; this.clientOutboundChannel = clientOutboundChannel; this.eventMessenger = eventMessenger; this.conversionService = conversionService; this.methodParameterConverter = methodParameterConverter; this.pathMatcher = pathMatcher; this.wampMessageSelector = wampMessageSelector; this.messageConverter = messageConverter; }
private DestinationPatternsMessageCondition(Collection<String> patterns, PathMatcher pathMatcher) { Assert.notNull(pathMatcher, "pathMatcher is required"); this.pathMatcher = pathMatcher; this.patterns = Collections.unmodifiableSet(new LinkedHashSet<>(patterns)); }
@Test public void testWithCustomPathMatcher() throws Exception { AmazonS3 amazonS3 = mock(AmazonS3.class); PathMatcher pathMatcher = mock(PathMatcher.class); PathMatchingSimpleStorageResourcePatternResolver patternResolver = new PathMatchingSimpleStorageResourcePatternResolver(amazonS3, new SimpleStorageResourceLoader(amazonS3), new PathMatchingResourcePatternResolver()); patternResolver.setPathMatcher(pathMatcher); patternResolver.getResources("s3://foo/bar"); verify(pathMatcher, times(1)).isPattern("foo/bar"); }
private boolean isAllowed(String resourcePath) { if (resourcePath.matches(PROTECTED_PATH)) { return false; } PathMatcher pathMatcher = new AntPathMatcher(); for (String pattern : allowedResourcePaths) { if (pathMatcher.match(pattern, resourcePath)) { return true; } } return false; }
private boolean isAllowed(String resourcePath) { if (resourcePath.matches(PROTECTED_PATH)) { return false; } PathMatcher pathMatcher = new AntPathMatcher(); for (String pattern : (allowedResourcePaths == null ? ALLOWED_RESOURCE_PATHS : allowedResourcePaths)) { if (pathMatcher.match(pattern, resourcePath)) { return true; } } return false; }
/** * 발생한 Exception 에 따라 후처리 로직이 실행할 수 있도록 연결하는 역할을 수행한다. * * @param clazz Exception 발생 클래스 * @param methodName Exception 발생 메소드명 * @param exception 발생한 Exception * @param pm 발생한 PathMatcher(default : AntPathMatcher) * @param exceptionHandlerServices[] 등록되어 있는 ExceptionHandlerService 리스트 */ protected void processHandling(Class clazz, String methodName, Exception exception, PathMatcher pm, ExceptionHandlerService[] exceptionHandlerServices) { try { for (ExceptionHandlerService ehm : exceptionHandlerServices) { if (!ehm.hasReqExpMatcher()) ehm.setReqExpMatcher(pm); ehm.setPackageName(clazz.getCanonicalName()+"."+methodName); ehm.run(exception); } } catch (Exception e) { } }
public PathMatcher getPathMatcher() { return pathMatcher; }
public void setPathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; }
/** * Searches for the given pattern inside the imported bundle. This translates to pattern matching on the imported * packages. * * @param importedBundle imported bundle * @param path path used for pattern matching * @param foundPaths collection of found results */ @SuppressWarnings("unchecked") private void findImportedBundleMatchingResource(final ImportedBundle importedBundle, String rootPath, String path, final Collection<String> foundPaths) throws IOException { final boolean trace = logger.isTraceEnabled(); String[] packages = importedBundle.getImportedPackages(); if (trace) logger.trace("Searching path [" + path + "] on imported pkgs " + ObjectUtils.nullSafeToString(packages) + "..."); final boolean startsWithSlash = rootPath.startsWith(FOLDER_SEPARATOR); for (int i = 0; i < packages.length; i++) { // transform the package name into a path String pkg = packages[i].replace(DOT, SLASH) + SLASH; if (startsWithSlash) { pkg = FOLDER_SEPARATOR + pkg; } final PathMatcher matcher = getPathMatcher(); // if the imported package matches the path if (matcher.matchStart(path, pkg)) { Bundle bundle = importedBundle.getBundle(); // 1. look at the Bundle jar root Enumeration<String> entries = bundle.getEntryPaths(pkg); while (entries != null && entries.hasMoreElements()) { String entry = entries.nextElement(); if (startsWithSlash) entry = FOLDER_SEPARATOR + entry; if (matcher.match(path, entry)) { if (trace) logger.trace("Found entry [" + entry + "]"); foundPaths.add(entry); } } // 2. Do a Bundle-Classpath lookup (since the jar might use a different classpath) Collection<String> cpMatchingPaths = findBundleClassPathMatchingPaths(bundle, path); foundPaths.addAll(cpMatchingPaths); } } }
public void setPathMatcher(PathMatcher pathMatcher) { Assert.notNull(pathMatcher, "pathMatcher cannot be null"); this.pathMatcher = pathMatcher; }
public static boolean matcherAnt(String reg,String str){ PathMatcher matcher = new AntPathMatcher(); return matcher.match(reg, str); }
public PathMatcher getPathMatcher() { return this.pathMatcher; }
/** * Set the PathMatcher implementation to use for matching destinations * against configured destination patterns. * <p>By default, {@link AntPathMatcher} is used. */ public void setPathMatcher(PathMatcher pathMatcher) { Assert.notNull(pathMatcher, "PathMatcher must not be null"); this.pathMatcher = pathMatcher; this.slashPathSeparator = this.pathMatcher.combine("a", "a").equals("a/a"); }
/** * Return the PathMatcher implementation to use for matching destinations. */ public PathMatcher getPathMatcher() { return this.pathMatcher; }
/** * Specify the {@link PathMatcher} to use. */ public void setPathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; }
/** * Return the configured {@link PathMatcher}. */ public PathMatcher getPathMatcher() { return this.pathMatcher; }
/** * When configured, the given PathMatcher is passed down to the * SubscriptionRegistry to use for matching destination to subscriptions. */ public void setPathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; initPathMatcherToUse(); }
protected PathMatcher getPathMatcher() { return this.pathMatcher; }
private DestinationPatternsMessageCondition(Collection<String> patterns, PathMatcher pathMatcher) { this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher()); this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns, this.pathMatcher)); }
/** * Return the PathMatcher that this resource pattern resolver uses. */ public PathMatcher getPathMatcher() { return this.pathMatcher; }