Search in sources :

Example 31 with AntPathMatcher

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

the class RSocketMessageHandlerTests method testHandleNoMatch.

private static void testHandleNoMatch(FrameType frameType) {
    RSocketMessageHandler handler = new RSocketMessageHandler();
    handler.setDecoders(Collections.singletonList(StringDecoder.allMimeTypes()));
    handler.setEncoders(Collections.singletonList(CharSequenceEncoder.allMimeTypes()));
    handler.afterPropertiesSet();
    RouteMatcher matcher = new SimpleRouteMatcher(new AntPathMatcher("."));
    RouteMatcher.Route route = matcher.parseRoute("path");
    MessageHeaderAccessor headers = new MessageHeaderAccessor();
    headers.setHeader(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER, frameType);
    Message<Object> message = MessageBuilder.createMessage("", headers.getMessageHeaders());
    handler.handleNoMatch(route, message);
}
Also used : RouteMatcher(org.springframework.util.RouteMatcher) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher)

Example 32 with AntPathMatcher

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

the class DefaultRSocketStrategiesTests method explicitValues.

@Test
void explicitValues() {
    SimpleRouteMatcher matcher = new SimpleRouteMatcher(new AntPathMatcher());
    DefaultMetadataExtractor extractor = new DefaultMetadataExtractor();
    ReactiveAdapterRegistry registry = new ReactiveAdapterRegistry();
    RSocketStrategies strategies = RSocketStrategies.builder().encoders(encoders -> {
        encoders.clear();
        encoders.add(new ByteArrayEncoder());
    }).decoders(decoders -> {
        decoders.clear();
        decoders.add(new ByteArrayDecoder());
    }).routeMatcher(matcher).metadataExtractor(extractor).reactiveAdapterStrategy(registry).build();
    assertThat(strategies.encoders()).hasSize(1);
    assertThat(strategies.decoders()).hasSize(1);
    assertThat(strategies.routeMatcher()).isSameAs(matcher);
    assertThat(strategies.metadataExtractor()).isSameAs(extractor);
    assertThat(strategies.reactiveAdapterRegistry()).isSameAs(registry);
}
Also used : CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) StringDecoder(org.springframework.core.codec.StringDecoder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.times(org.mockito.Mockito.times) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) DataBufferEncoder(org.springframework.core.codec.DataBufferEncoder) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) AntPathMatcher(org.springframework.util.AntPathMatcher) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) Mockito.mock(org.mockito.Mockito.mock) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Example 33 with AntPathMatcher

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

the class SimpAnnotationMethodMessageHandlerTests method dotPathSeparator.

@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);
    assertThat(controller.method).isEqualTo("handleFoo");
    message = createMessage("/app2/pre.foo");
    this.messageHandler.handleMessage(message);
    assertThat(controller.method).isEqualTo("handleFoo");
}
Also used : AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.jupiter.api.Test)

Example 34 with AntPathMatcher

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

the class SimpDestinationMessageMatcherTests method setup.

@BeforeEach
public void setup() {
    this.messageBuilder = MessageBuilder.withPayload("M");
    this.matcher = new SimpDestinationMessageMatcher("/**");
    this.pathMatcher = new AntPathMatcher();
}
Also used : AntPathMatcher(org.springframework.util.AntPathMatcher) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with AntPathMatcher

use of org.springframework.util.AntPathMatcher in project grails-core by grails.

the class ClosureClassIgnoringComponentScanBeanDefinitionParser method configureScanner.

@Override
protected ClassPathBeanDefinitionScanner configureScanner(ParserContext parserContext, Element element) {
    final ClassPathBeanDefinitionScanner scanner = super.configureScanner(parserContext, element);
    final ResourceLoader originalResourceLoader = parserContext.getReaderContext().getResourceLoader();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Scanning only this classloader:" + originalResourceLoader.getClassLoader());
    }
    ResourceLoader parentOnlyResourceLoader;
    try {
        parentOnlyResourceLoader = new ResourceLoader() {

            ClassLoader parentOnlyGetResourcesClassLoader = new ParentOnlyGetResourcesClassLoader(originalResourceLoader.getClassLoader());

            public Resource getResource(String location) {
                return originalResourceLoader.getResource(location);
            }

            public ClassLoader getClassLoader() {
                return parentOnlyGetResourcesClassLoader;
            }
        };
    } catch (Throwable t) {
        // restrictive classloading environment, use the original
        parentOnlyResourceLoader = originalResourceLoader;
    }
    final PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(parentOnlyResourceLoader) {

        @Override
        protected Resource[] findAllClassPathResources(String location) throws IOException {
            Set<Resource> result = new LinkedHashSet<Resource>(16);
            if (BuildSettings.CLASSES_DIR != null) {
                @SuppressWarnings("unused") URL classesDir = BuildSettings.CLASSES_DIR.toURI().toURL();
                // only scan classes from project classes directory
                String path = location;
                if (path.startsWith("/")) {
                    path = path.substring(1);
                }
                Enumeration<URL> resourceUrls = getClassLoader().getResources(path);
                while (resourceUrls.hasMoreElements()) {
                    URL url = resourceUrls.nextElement();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Scanning URL " + url.toExternalForm() + " while searching for '" + location + "'");
                    }
                    /*
                    if (!warDeployed && classesDir!= null && url.equals(classesDir)) {
                        result.add(convertClassLoaderURL(url));
                    }
                    else if (warDeployed) {
                        result.add(convertClassLoaderURL(url));
                    }
                    */
                    result.add(convertClassLoaderURL(url));
                }
            }
            return result.toArray(new Resource[result.size()]);
        }
    };
    resourceResolver.setPathMatcher(new AntPathMatcher() {

        @Override
        public boolean match(String pattern, String path) {
            if (path.endsWith(".class")) {
                String filename = GrailsStringUtils.getFileBasename(path);
                if (filename.contains("$"))
                    return false;
            }
            return super.match(pattern, path);
        }
    });
    scanner.setResourceLoader(resourceResolver);
    return scanner;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResourceLoader(org.springframework.core.io.ResourceLoader) Resource(org.springframework.core.io.Resource) URL(java.net.URL) ClassPathBeanDefinitionScanner(org.springframework.context.annotation.ClassPathBeanDefinitionScanner) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) AntPathMatcher(org.springframework.util.AntPathMatcher)

Aggregations

AntPathMatcher (org.springframework.util.AntPathMatcher)36 Test (org.junit.jupiter.api.Test)13 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)11 Test (org.junit.Test)5 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)5 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)4 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 Message (org.springframework.messaging.Message)3 DefaultMetadataExtractor (org.springframework.messaging.rsocket.DefaultMetadataExtractor)3 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 PathMatcher (org.springframework.util.PathMatcher)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)2