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