private DestinationPatternsMessageCondition(Collection<String> patterns, @Nullable PathMatcher pathMatcher) { this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher()); this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns, this.pathMatcher)); }
/** * Return a global {@link PathMatcher} instance for path matching * patterns in {@link HandlerMapping HandlerMappings}. * This instance can be configured using the {@link PathMatchConfigurer} * in {@link #configurePathMatch(PathMatchConfigurer)}. * @since 4.1 */ @Bean public PathMatcher mvcPathMatcher() { PathMatcher pathMatcher = getPathMatchConfigurer().getPathMatcher(); return (pathMatcher != null ? pathMatcher : new AntPathMatcher()); }
@RequestMapping("/search/**") public Map searchWithSearchTerm(HttpServletRequest request) { // Don't repeat a pattern String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); String searchTerm = new AntPathMatcher().extractPathWithinPattern(pattern, request.getServletPath()); ... }
/** * Private constructor accepting a collection of patterns. */ private PatternsRequestCondition(Collection<String> patterns, @Nullable UrlPathHelper urlPathHelper, @Nullable PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch, @Nullable 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); } } }
protected String getEndpointLocalPath(String pathWithinApplication) { return new AntPathMatcher().extractPathWithinPattern(this.realRequestMappingPath, pathWithinApplication); }
private PathMatcher getDefaultPathMatcher() { try { return context.getBean(SimpAnnotationMethodMessageHandler.class).getPathMatcher(); } catch(NoSuchBeanDefinitionException e) { return new AntPathMatcher(); } }
private boolean isBranchNotExcluded(String branchName) { AntPathMatcher matcher = new AntPathMatcher(); for (String excludePattern : excludedBranches) { if (matcher.match(excludePattern, branchName)) { return false; } } return true; }
@Override protected void configureMessageBroker(MessageBrokerRegistry registry) { registry.setPathMatcher(new AntPathMatcher(".")); }
/** * Return a global {@link PathMatcher} instance for path matching * patterns in {@link HandlerMapping HandlerMappings}. * This instance can be configured using the {@link PathMatchConfigurer} * in {@link #configurePathMatch(PathMatchConfigurer)}. * @since 4.1 */ @Bean public PathMatcher mvcPathMatcher() { PathMatcher pathMatcher = getPathMatchConfigurer().getPathMatcher(); return (pathMatcher != null ? pathMatcher : new AntPathMatcher()); }
@Override protected boolean redirectMatches(String requestedRedirect, String redirectUri) { AntPathMatcher matcher = new AntPathMatcher("/"); if (redirectUri!=null && redirectUri.contains("*") && matcher.match(redirectUri, requestedRedirect)) { return true; } else { return super.redirectMatches(requestedRedirect, redirectUri); } }
@Test public void prependSlashWithCustomPathSeparator() { DestinationPatternsMessageCondition c = new DestinationPatternsMessageCondition(new String[] {"foo"}, new AntPathMatcher(".")); assertEquals("Pre-pending should be disabled when not using '/' as path separator", "foo", c.getPatterns().iterator().next()); }
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) { PathMatcher pathMatcher = new AntPathMatcher(); List<HandlerInterceptor> result = new ArrayList<>(); 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; }
@Before public void setup() { messageBuilder = MessageBuilder.withPayload("M"); matcher = new SimpDestinationMessageMatcher("/**"); pathMatcher = new AntPathMatcher(); }
@Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.setPathMatcher(new AntPathMatcher(".")); registry.enableSimpleBroker("/queue/", "/topic/"); registry.setApplicationDestinationPrefixes("/app"); }
@Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.setPathMatcher(new AntPathMatcher(".")); registry.enableSimpleBroker("/queue/", "/topic/"); registry.setApplicationDestinationPrefixes("/app"); }
@Override protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) { messages .simpDestPathMatcher(new AntPathMatcher()) .simpDestMatchers("/app/a/*").permitAll() .anyMessage().denyAll(); } // @formatter:on
@Test public void dotPathSeparator() { DotPathSeparatorController controller = new DotPathSeparatorController(); this.messageHandler.setPathMatcher(new AntPathMatcher(".")); this.messageHandler.registerHandler(controller); this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/")); Message<?> message = createMessage("/app1/pre.foo"); this.messageHandler.registerHandler(this.testController); this.messageHandler.handleMessage(message); assertEquals("handleFoo", controller.method); message = createMessage("/app2/pre.foo"); this.messageHandler.handleMessage(message); assertEquals("handleFoo", controller.method); }
@Test public void simpDestMatchersCustom() { message = MessageBuilder .withPayload("Hi") .setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "price.stock.1.2").build(); messages.simpDestPathMatcher(new AntPathMatcher(".")) .simpDestMatchers("price.stock.*").permitAll(); assertThat(getAttribute()).isNull(); message = MessageBuilder .withPayload("Hi") .setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "price.stock.1.2").build(); messages.simpDestPathMatcher(new AntPathMatcher(".")) .simpDestMatchers("price.stock.**").permitAll(); assertThat(getAttribute()).isEqualTo("permitAll"); }
assertFalse(new AntPathMatcher().match("/{foo}", "/")); assertTrue(new AntPathMatcher().match("/{foo}", "/a")); assertTrue(new AntPathMatcher().match("/{foo}{bar}", "/a")); assertFalse(new AntPathMatcher().match("/{foo}*", "/")); assertTrue(new AntPathMatcher().match("/*", "/")); assertFalse(new AntPathMatcher().match("/*{foo}", "/")); Map<String, String> vars = new AntPathMatcher().extractUriTemplateVariables("/{foo}{bar}", "/a"); assertEquals("a",vars.get("foo")); assertEquals("",vars.get("bar"));
@Override protected void configureMessageBroker(MessageBrokerRegistry registry) { registry.configureBrokerChannel().interceptors(this.interceptor, this.interceptor, this.interceptor); registry.configureBrokerChannel().taskExecutor() .corePoolSize(31).maxPoolSize(32).keepAliveSeconds(33).queueCapacity(34); registry.setPathMatcher(new AntPathMatcher(".")).enableSimpleBroker("/topic", "/queue"); registry.setCacheLimit(8192); registry.setPreservePublishOrder(true); registry.setUserRegistryOrder(99); } }