use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method testInvalidPath.
private void testInvalidPath(HttpMethod httpMethod) throws Exception {
Resource location = new ClassPathResource("test/", getClass());
this.handler.setLocations(Collections.singletonList(location));
testInvalidPath(httpMethod, "../testsecret/secret.txt", location);
testInvalidPath(httpMethod, "test/../../testsecret/secret.txt", location);
testInvalidPath(httpMethod, ":/../../testsecret/secret.txt", location);
location = new UrlResource(getClass().getResource("./test/"));
this.handler.setLocations(Collections.singletonList(location));
Resource secretResource = new UrlResource(getClass().getResource("testsecret/secret.txt"));
String secretPath = secretResource.getURL().getPath();
testInvalidPath(httpMethod, "file:" + secretPath, location);
testInvalidPath(httpMethod, "/file:" + secretPath, location);
testInvalidPath(httpMethod, "url:" + secretPath, location);
testInvalidPath(httpMethod, "/url:" + secretPath, location);
testInvalidPath(httpMethod, "////../.." + secretPath, location);
testInvalidPath(httpMethod, "/%2E%2E/testsecret/secret.txt", location);
testInvalidPath(httpMethod, "url:" + secretPath, location);
// The following tests fail with a MalformedURLException on Windows
// testInvalidPath(location, "/" + secretPath);
// testInvalidPath(location, "/ " + secretPath);
}
use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.
the class PathResourceResolverTests method checkResource.
@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);
}
use of org.springframework.core.io.UrlResource in project grails-core by grails.
the class StaticResourceLoaderTests method testGetResource.
public void testGetResource() throws Exception {
StaticResourceLoader srl = new StaticResourceLoader();
srl.setBaseResource(new UrlResource("http://grails.org"));
Resource r = srl.getResource("/Home");
assertEquals("http://grails.org/Home", r.getURL().toString());
}
use of org.springframework.core.io.UrlResource in project grails-core by grails.
the class BinaryGrailsPlugin method initializeViewMap.
protected void initializeViewMap(BinaryGrailsPluginDescriptor descriptor) {
final Resource descriptorResource = descriptor.getResource();
Resource viewsPropertiesResource = null;
try {
viewsPropertiesResource = descriptorResource.createRelative(VIEWS_PROPERTIES);
} catch (IOException e) {
// ignore
}
if (viewsPropertiesResource == null || !viewsPropertiesResource.exists()) {
try {
String urlString = descriptorResource.getURL().toString();
if (urlString.endsWith(PLUGIN_DESCRIPTOR_PATH)) {
urlString = urlString.substring(0, urlString.length() - PLUGIN_DESCRIPTOR_PATH.length());
URL newUrl = new URL(urlString + RELATIVE_VIEWS_PROPERTIES);
viewsPropertiesResource = new UrlResource(newUrl);
}
} catch (IOException e) {
// ignore
}
}
if (viewsPropertiesResource == null || !viewsPropertiesResource.exists()) {
return;
}
Properties viewsProperties = new Properties();
InputStream input = null;
try {
input = viewsPropertiesResource.getInputStream();
viewsProperties.load(input);
for (Object view : viewsProperties.keySet()) {
String viewName = view.toString();
final String viewClassName = viewsProperties.getProperty(viewName);
try {
final Class<?> viewClass = grailsApplication.getClassLoader().loadClass(viewClassName);
precompiledViewMap.put(viewName, viewClass);
} catch (Throwable e) {
throw new PluginException("Failed to initialize view [" + viewName + "] from plugin [" + getName() + "] : " + e.getMessage(), e);
}
}
} catch (IOException e) {
LOG.error("Error loading views for binary plugin [" + this + "]: " + e.getMessage(), e);
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {
// ignore
}
}
}
use of org.springframework.core.io.UrlResource in project grails-core by grails.
the class CorePluginFinder method resolvePluginResources.
private Resource[] resolvePluginResources() throws IOException {
Enumeration<URL> resources = application.getClassLoader().getResources(CORE_PLUGIN_PATTERN);
List<Resource> resourceList = new ArrayList<>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
resourceList.add(new UrlResource(url));
}
return resourceList.toArray(new Resource[resourceList.size()]);
}
Aggregations