Search in sources :

Example 6 with PathMatcher

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

the class AbstractMessageBrokerConfiguration method simpAnnotationMethodMessageHandler.

@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpMessagingTemplate brokerMessagingTemplate, CompositeMessageConverter brokerMessageConverter) {
    SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler(clientInboundChannel, clientOutboundChannel, brokerMessagingTemplate);
    MessageBrokerRegistry brokerRegistry = getBrokerRegistry(clientInboundChannel, clientOutboundChannel);
    handler.setDestinationPrefixes(brokerRegistry.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 = brokerRegistry.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 7 with PathMatcher

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

the class MessageBrokerConfigurationTests method customPathMatcher.

@Test
public void customPathMatcher() {
    ApplicationContext context = loadConfig(CustomConfig.class);
    SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class);
    DefaultSubscriptionRegistry registry = (DefaultSubscriptionRegistry) broker.getSubscriptionRegistry();
    assertThat(registry.getPathMatcher().combine("a", "a")).isEqualTo("a.a");
    PathMatcher pathMatcher = context.getBean(SimpAnnotationMethodMessageHandler.class).getPathMatcher();
    assertThat(pathMatcher.combine("a", "a")).isEqualTo("a.a");
    DefaultUserDestinationResolver resolver = context.getBean(DefaultUserDestinationResolver.class);
    assertThat(resolver).isNotNull();
    assertThat(resolver.isRemoveLeadingSlash()).isFalse();
}
Also used : DefaultSubscriptionRegistry(org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AntPathMatcher(org.springframework.util.AntPathMatcher) PathMatcher(org.springframework.util.PathMatcher) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) DefaultUserDestinationResolver(org.springframework.messaging.simp.user.DefaultUserDestinationResolver) Test(org.junit.jupiter.api.Test)

Example 8 with PathMatcher

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

the class WebMvcConfigurationSupport method requestMappingHandlerMapping.

/**
	 * Return a {@link RequestMappingHandlerMapping} ordered at 0 for mapping
	 * requests to annotated controllers.
	 */
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
    RequestMappingHandlerMapping handlerMapping = createRequestMappingHandlerMapping();
    handlerMapping.setOrder(0);
    handlerMapping.setInterceptors(getInterceptors());
    handlerMapping.setContentNegotiationManager(mvcContentNegotiationManager());
    handlerMapping.setCorsConfigurations(getCorsConfigurations());
    PathMatchConfigurer configurer = getPathMatchConfigurer();
    if (configurer.isUseSuffixPatternMatch() != null) {
        handlerMapping.setUseSuffixPatternMatch(configurer.isUseSuffixPatternMatch());
    }
    if (configurer.isUseRegisteredSuffixPatternMatch() != null) {
        handlerMapping.setUseRegisteredSuffixPatternMatch(configurer.isUseRegisteredSuffixPatternMatch());
    }
    if (configurer.isUseTrailingSlashMatch() != null) {
        handlerMapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch());
    }
    UrlPathHelper pathHelper = configurer.getUrlPathHelper();
    if (pathHelper != null) {
        handlerMapping.setUrlPathHelper(pathHelper);
    }
    PathMatcher pathMatcher = configurer.getPathMatcher();
    if (pathMatcher != null) {
        handlerMapping.setPathMatcher(pathMatcher);
    }
    return handlerMapping;
}
Also used : AntPathMatcher(org.springframework.util.AntPathMatcher) PathMatcher(org.springframework.util.PathMatcher) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Bean(org.springframework.context.annotation.Bean)

Example 9 with PathMatcher

use of org.springframework.util.PathMatcher in project commons by terran4j.

the class Strings method match.

/**
 * 检测指定的 path 是否匹配 regexPaths 。
 *
 * @param path 路径。
 * @param regexPaths 需要匹配的路径。
 * @return 匹配的路径。
 */
public static boolean match(String path, String... regexPaths) {
    PathMatcher pathMatch = new AntPathMatcher();
    if (path == null || regexPaths == null) {
        return false;
    }
    for (String regexPath : regexPaths) {
        if (regexPath == null) {
            continue;
        }
        regexPath = regexPath.trim();
        path = path.trim();
        if (pathMatch.match(regexPath, path)) {
            return true;
        }
    }
    return false;
}
Also used : PathMatcher(org.springframework.util.PathMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher)

Example 10 with PathMatcher

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

the class AbstractSecurityWebSocketMessageBrokerConfigurer method afterSingletonsInstantiated.

@Override
public void afterSingletonsInstantiated() {
    if (sameOriginDisabled()) {
        return;
    }
    String beanName = "stompWebSocketHandlerMapping";
    SimpleUrlHandlerMapping mapping = this.context.getBean(beanName, SimpleUrlHandlerMapping.class);
    Map<String, Object> mappings = mapping.getHandlerMap();
    for (Object object : mappings.values()) {
        if (object instanceof SockJsHttpRequestHandler) {
            setHandshakeInterceptors((SockJsHttpRequestHandler) object);
        } else if (object instanceof WebSocketHttpRequestHandler) {
            setHandshakeInterceptors((WebSocketHttpRequestHandler) object);
        } else {
            throw new IllegalStateException("Bean " + beanName + " is expected to contain mappings to either a " + "SockJsHttpRequestHandler or a WebSocketHttpRequestHandler but got " + object);
        }
    }
    if (this.inboundRegistry.containsMapping() && !this.inboundRegistry.isSimpDestPathMatcherConfigured()) {
        PathMatcher pathMatcher = getDefaultPathMatcher();
        this.inboundRegistry.simpDestPathMatcher(pathMatcher);
    }
}
Also used : SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) AntPathMatcher(org.springframework.util.AntPathMatcher) PathMatcher(org.springframework.util.PathMatcher) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)

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