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());
}
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;
}
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());
}
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);
}
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();
}
Aggregations