Search in sources :

Example 6 with AntPathMatcher

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

the class DestinationPatternsMessageConditionTests method prependSlashWithCustomPathSeparator.

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

Example 7 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)

Example 8 with AntPathMatcher

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

the class DefaultUserDestinationResolverTests method handleSubscribeForDestinationWithoutLeadingSlash.

// SPR-14044
@Test
public void handleSubscribeForDestinationWithoutLeadingSlash() {
    AntPathMatcher pathMatcher = new AntPathMatcher();
    pathMatcher.setPathSeparator(".");
    this.resolver.setPathMatcher(pathMatcher);
    TestPrincipal user = new TestPrincipal("joe");
    String destination = "/user/jms.queue.call";
    Message<?> message = createMessage(SimpMessageType.SUBSCRIBE, user, "123", destination);
    UserDestinationResult actual = this.resolver.resolveDestination(message);
    assertEquals(1, actual.getTargetDestinations().size());
    assertEquals("jms.queue.call-user123", actual.getTargetDestinations().iterator().next());
    assertEquals(destination, actual.getSubscribeDestination());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) AntPathMatcher(org.springframework.util.AntPathMatcher) Test(org.junit.Test)

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

Example 10 with AntPathMatcher

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

the class SimpDestinationMessageMatcherTests method setup.

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

Aggregations

AntPathMatcher (org.springframework.util.AntPathMatcher)11 Test (org.junit.Test)7 TestPrincipal (org.springframework.messaging.simp.TestPrincipal)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Before (org.junit.Before)1 ClassPathBeanDefinitionScanner (org.springframework.context.annotation.ClassPathBeanDefinitionScanner)1 Resource (org.springframework.core.io.Resource)1 ResourceLoader (org.springframework.core.io.ResourceLoader)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 PathMatcher (org.springframework.util.PathMatcher)1 HandlerInterceptor (org.springframework.web.servlet.HandlerInterceptor)1 MappedInterceptor (org.springframework.web.servlet.handler.MappedInterceptor)1