@Test // SPR-12624 public void checkRelativeLocation() throws Exception { String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm(); Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework")); List<Resource> locations = singletonList(location); assertNotNull(this.resolver.resolveResource(null, "main.css", locations, null).block(TIMEOUT)); }
@Test public void checkRelativeLocation() throws Exception { String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm(); Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework")); assertNotNull(this.resolver.resolveResource(null, "main.css", Collections.singletonList(location), null)); }
@Test public void urlResourceWithCharset() throws Exception { this.registration.addResourceLocations("[charset=ISO-8859-1]file:///tmp"); this.registration.resourceChain(true); ResourceHttpRequestHandler handler = getHandler("/resources/**"); UrlResource resource = (UrlResource) handler.getLocations().get(1); assertEquals("file:/tmp", resource.getURL().toString()); assertNotNull(handler.getUrlPathHelper()); List<ResourceResolver> resolvers = handler.getResourceResolvers(); PathResourceResolver resolver = (PathResourceResolver) resolvers.get(resolvers.size()-1); Map<Resource, Charset> locationCharsets = resolver.getLocationCharsets(); assertEquals(1, locationCharsets.size()); assertEquals(StandardCharsets.ISO_8859_1, locationCharsets.values().iterator().next()); }
@Test public void checkResource() throws IOException { Resource location = new ClassPathResource("test/", PathResourceResolver.class); testCheckResource(location, "../testsecret/secret.txt"); testCheckResource(location, "test/../../testsecret/secret.txt"); location = new UrlResource(getClass().getResource("./test/")); String secretPath = new UrlResource(getClass().getResource("testsecret/secret.txt")).getURL().getPath(); testCheckResource(location, "file:" + secretPath); testCheckResource(location, "/file:" + secretPath); testCheckResource(location, "/" + secretPath); testCheckResource(location, "////../.." + secretPath); testCheckResource(location, "/%2E%2E/testsecret/secret.txt"); testCheckResource(location, "/%2e%2e/testsecret/secret.txt"); testCheckResource(location, " " + secretPath); testCheckResource(location, "/ " + secretPath); testCheckResource(location, "url:" + secretPath); }
@Test public void checkResource() throws IOException { Resource location = new ClassPathResource("test/", PathResourceResolver.class); testCheckResource(location, "../testsecret/secret.txt"); testCheckResource(location, "test/../../testsecret/secret.txt"); location = new UrlResource(getClass().getResource("./test/")); String secretPath = new UrlResource(getClass().getResource("testsecret/secret.txt")).getURL().getPath(); testCheckResource(location, "file:" + secretPath); testCheckResource(location, "/file:" + secretPath); testCheckResource(location, "/" + secretPath); testCheckResource(location, "////../.." + secretPath); testCheckResource(location, "/%2E%2E/testsecret/secret.txt"); testCheckResource(location, "/%2e%2e/testsecret/secret.txt"); testCheckResource(location, " " + secretPath); testCheckResource(location, "/ " + secretPath); testCheckResource(location, "url:" + secretPath); }
public String asUrl(String filePath) throws IOException { UrlResource urlResource = new UrlResource("file:" + filePath); return urlResource.getURL().toExternalForm(); }
public static List<URL> nestedClasses(Archive archive, String... paths) { List<URL> extras = new ArrayList<>(); try { for (String path : paths) { UrlResource classes = new UrlResource(archive.getUrl().toString() + path); if (classes.exists()) { extras.add(classes.getURL()); } } } catch (Exception e) { throw new IllegalStateException("Cannot create urls for resources", e); } return extras; }
public static List<URL> nestedClasses(Archive archive, String... paths) { List<URL> extras = new ArrayList<>(); try { for (String path : paths) { UrlResource classes = new UrlResource(archive.getUrl().toString() + path); if (classes.exists()) { extras.add(classes.getURL()); } } } catch (Exception e) { throw new IllegalStateException("Cannot create urls for resources", e); } return extras; }
private static File getFileForLastModifiedCheck(UrlResource resource) throws IOException { URL url = resource.getURL(); if (ResourceUtils.isJarURL(url)) { URL actualUrl = ResourceUtils.extractJarFileURL(url); return ResourceUtils.getFile(actualUrl); } else { return resource.getFile(); } }
basePath = removeClasspathScheme(basePath); try { filePath = truncateFilePath(((UrlResource) flowResource).getURL().getPath(), basePath); } catch (IOException e) { throw new IllegalArgumentException("Unable to obtain path: " + e.getMessage());