use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method urlResourceWithImport.
@Test
void urlResourceWithImport() {
URL url = getClass().getResource(RESOURCE_CONTEXT.getPath());
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new UrlResource(url));
// comes from "resourceImport.xml"
xbf.getBean("resource1", ResourceTestBean.class);
// comes from "resource.xml"
xbf.getBean("resource2", ResourceTestBean.class);
}
use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method testResolvePathWithTraversal.
private void testResolvePathWithTraversal(HttpMethod httpMethod) throws Exception {
Resource location = new ClassPathResource("test/", getClass());
this.handler.setLocations(Collections.singletonList(location));
testResolvePathWithTraversal(httpMethod, "../testsecret/secret.txt", location);
testResolvePathWithTraversal(httpMethod, "test/../../testsecret/secret.txt", location);
testResolvePathWithTraversal(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();
testResolvePathWithTraversal(httpMethod, "file:" + secretPath, location);
testResolvePathWithTraversal(httpMethod, "/file:" + secretPath, location);
testResolvePathWithTraversal(httpMethod, "url:" + secretPath, location);
testResolvePathWithTraversal(httpMethod, "/url:" + secretPath, location);
testResolvePathWithTraversal(httpMethod, "////../.." + secretPath, location);
testResolvePathWithTraversal(httpMethod, "/%2E%2E/testsecret/secret.txt", location);
testResolvePathWithTraversal(httpMethod, "%2F%2F%2E%2E%2F%2Ftestsecret/secret.txt", location);
testResolvePathWithTraversal(httpMethod, "url:" + secretPath, location);
// The following tests fail with a MalformedURLException on Windows
// testResolvePathWithTraversal(location, "/" + secretPath);
// testResolvePathWithTraversal(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 spring-framework by spring-projects.
the class PersistenceXmlParsingTests method testPersistenceUnitRootUrlWithJar.
@Test
public void testPersistenceUnitRootUrlWithJar() throws Exception {
ClassPathResource archive = new ClassPathResource("/org/springframework/orm/jpa/jpa-archive.jar");
String newRoot = "jar:" + archive.getURL().toExternalForm() + "!/META-INF/persist.xml";
Resource insideArchive = new UrlResource(newRoot);
// make sure the location actually exists
assertThat(insideArchive.exists()).isTrue();
URL url = PersistenceUnitReader.determinePersistenceUnitRootUrl(insideArchive);
assertThat(archive.getURL().sameFile(url)).as("the archive location should have been returned").isTrue();
}
use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.
the class CachingMetadataReaderLeakTests method significantLoad.
@Test
void significantLoad() throws Exception {
// the biggest public class in the JDK (>60k)
URL url = getClass().getResource("/java/awt/Component.class");
assertThat(url).isNotNull();
// look at a LOT of items
for (int i = 0; i < ITEMS_TO_LOAD; i++) {
Resource resource = new UrlResource(url) {
@Override
public boolean equals(Object obj) {
return (obj == this);
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
};
MetadataReader reader = mrf.getMetadataReader(resource);
assertThat(reader).isNotNull();
}
// useful for profiling to take snapshots
// System.in.read();
}
Aggregations