Search in sources :

Example 1 with PathMatcher

use of org.springframework.util.PathMatcher in project spring-framework by spring-projects.

the class AbstractMessageBrokerConfiguration method simpAnnotationMethodMessageHandler.

@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
    SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler();
    handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
    handler.setMessageConverter(brokerMessageConverter());
    handler.setValidator(simpValidator());
    List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
    addArgumentResolvers(argumentResolvers);
    handler.setCustomArgumentResolvers(argumentResolvers);
    List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>();
    addReturnValueHandlers(returnValueHandlers);
    handler.setCustomReturnValueHandlers(returnValueHandlers);
    PathMatcher pathMatcher = getBrokerRegistry().getPathMatcher();
    if (pathMatcher != null) {
        handler.setPathMatcher(pathMatcher);
    }
    return handler;
}
Also used : HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler) PathMatcher(org.springframework.util.PathMatcher) ArrayList(java.util.ArrayList) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) Bean(org.springframework.context.annotation.Bean)

Example 2 with PathMatcher

use of org.springframework.util.PathMatcher in project spring-framework by spring-projects.

the class DelegatingWebMvcConfigurationTests method configurePathMatch.

@Test
public void configurePathMatch() throws Exception {
    final PathMatcher pathMatcher = mock(PathMatcher.class);
    final UrlPathHelper pathHelper = mock(UrlPathHelper.class);
    List<WebMvcConfigurer> configurers = new ArrayList<>();
    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());
}
Also used : PathMatcher(org.springframework.util.PathMatcher) ArrayList(java.util.ArrayList) UrlPathHelper(org.springframework.web.util.UrlPathHelper) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) Test(org.junit.Test)

Example 3 with PathMatcher

use of org.springframework.util.PathMatcher in project spring-framework by spring-projects.

the class InterceptorRegistryTests method getInterceptorsForPath.

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;
}
Also used : MappedInterceptor(org.springframework.web.servlet.handler.MappedInterceptor) PathMatcher(org.springframework.util.PathMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) ArrayList(java.util.ArrayList) AntPathMatcher(org.springframework.util.AntPathMatcher)

Example 4 with PathMatcher

use of org.springframework.util.PathMatcher in project spring-framework by spring-projects.

the class InterceptorRegistryTests method addInterceptorsWithCustomPathMatcher.

@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());
}
Also used : MappedInterceptor(org.springframework.web.servlet.handler.MappedInterceptor) PathMatcher(org.springframework.util.PathMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.Test)

Example 5 with PathMatcher

use of org.springframework.util.PathMatcher in project AJSC by att.

the class InterceptorFilter method urlMappingResolver.

private ArrayList<String> urlMappingResolver(Map<String, String> p, String pathinfo) {
    ArrayList<String> interceptorClasses = new ArrayList<String>();
    PathMatcher pathMatcher = new AntPathMatcher();
    for (Map.Entry<String, String> entry : p.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        String[] valueArray = value.split(",");
        if (pathMatcher.match(key, pathinfo)) {
            for (String val : valueArray) {
                if (!interceptorClasses.contains(val)) {
                    interceptorClasses.add(val);
                }
            }
        }
    }
    return interceptorClasses;
}
Also used : PathMatcher(org.springframework.util.PathMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ArrayList(java.util.ArrayList) AntPathMatcher(org.springframework.util.AntPathMatcher) AJSCPropertiesMap(com.att.ajsc.filemonitor.AJSCPropertiesMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PathMatcher (org.springframework.util.PathMatcher)13 AntPathMatcher (org.springframework.util.AntPathMatcher)8 ArrayList (java.util.ArrayList)5 UrlPathHelper (org.springframework.web.util.UrlPathHelper)5 Test (org.junit.jupiter.api.Test)4 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)4 Bean (org.springframework.context.annotation.Bean)3 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)3 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)3 Collections (java.util.Collections)2 List (java.util.List)2 BiConsumer (java.util.function.BiConsumer)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Test (org.junit.Test)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 BDDMockito.given (org.mockito.BDDMockito.given)2 Captor (org.mockito.Captor)2 Mock (org.mockito.Mock)2 Mockito.mock (org.mockito.Mockito.mock)2