use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.
the class PathMatchingResourcePatternResolver method addClassPathManifestEntries.
/**
* Determine jar file references from the "java.class.path." manifest property and add them
* to the given set of resources in the form of pointers to the root of the jar file content.
* @param result the set of resources to add jar roots to
* @since 4.3
*/
protected void addClassPathManifestEntries(Set<Resource> result) {
try {
String javaClassPathProperty = System.getProperty("java.class.path");
for (String path : StringUtils.delimitedListToStringArray(javaClassPathProperty, System.getProperty("path.separator"))) {
try {
File file = new File(path);
UrlResource jarResource = new UrlResource(ResourceUtils.JAR_URL_PREFIX + ResourceUtils.FILE_URL_PREFIX + file.getAbsolutePath() + ResourceUtils.JAR_URL_SEPARATOR);
if (jarResource.exists()) {
result.add(jarResource);
}
} catch (MalformedURLException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Cannot search for matching files underneath [" + path + "] because it cannot be converted to a valid 'jar:' URL: " + ex.getMessage());
}
}
}
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to evaluate 'java.class.path' manifest entries: " + ex);
}
}
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class FasterFilesystemForeignSourceRepositoryTest method testImportHttpSource.
@Test
@JUnitHttpServer(port = 9162)
public void testImportHttpSource() throws Exception {
FileSystemBuilder bldr = new FileSystemBuilder("target", "testGetForeignSource");
File fsDir = bldr.dir("foreignSource").file("test.xml", fs("test")).file("noreq.xml", fs("noreq")).pop();
File reqDir = bldr.dir("requisitions").file("test.xml", req("test")).file("pending.xml", req("pending")).pop();
FasterFilesystemForeignSourceRepository repo = repo(fsDir, reqDir);
Resource resource = new UrlResource("http://localhost:9162/requisition-test.xml");
Requisition req = repo.importResourceRequisition(resource);
assertNotNull(req);
System.err.println(JaxbUtils.marshal(req));
assertNotNull(req.getNode("4243"));
assertNotNull(req.getNode("4244"));
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class FusedForeignSourceRepositoryTest method testSpc674RaceCondition.
@Test
public void testSpc674RaceCondition() throws Exception {
final String foreignSource = "spc674";
System.err.println("=== create a requisition like the ReST service does, import it immediately ===");
final Requisition initial = new Requisition(foreignSource);
initial.putNode(createNode("1"));
initial.updateDateStamp();
m_pending.save(initial);
final URL node1Snapshot = createSnapshot(foreignSource);
Resource resource = new UrlResource(node1Snapshot);
doImport(resource);
Thread.sleep(5);
List<String> files = getImports(foreignSource);
assertEquals(1, files.size());
System.err.println("=== create another snapshot, but don't import it yet ===");
initial.putNode(createNode("2"));
initial.updateDateStamp();
m_pending.save(initial);
final URL node2Snapshot = createSnapshot(foreignSource);
Thread.sleep(5);
files = getImports(foreignSource);
assertEquals(3, files.size());
System.err.println("=== create yet another snapshot, and don't import it yet ===");
initial.putNode(createNode("3"));
initial.updateDateStamp();
m_pending.save(initial);
final URL node3Snapshot = createSnapshot(foreignSource);
Thread.sleep(5);
files = getImports(foreignSource);
assertEquals(4, files.size());
System.err.println("=== import of the second file finishes ===");
doImport(new UrlResource(node2Snapshot));
Thread.sleep(5);
files = getImports(foreignSource);
assertEquals(2, files.size());
System.err.println("=== fourth node is sent to the ReST interface ===");
final Requisition currentPending = RequisitionFileUtils.getLatestPendingOrSnapshotRequisition(m_pending, foreignSource);
assertNotNull(currentPending);
assertEquals(initial.getDate(), currentPending.getDate());
currentPending.putNode(createNode("4"));
currentPending.updateDateStamp();
m_pending.save(currentPending);
final URL node4Snapshot = createSnapshot(foreignSource);
Thread.sleep(5);
files = getImports(foreignSource);
assertEquals(4, files.size());
System.err.println("=== import of the third file finishes ===");
doImport(new UrlResource(node3Snapshot));
Thread.sleep(5);
files = getImports(foreignSource);
assertEquals(2, files.size());
System.err.println("=== import of the fourth file finishes ===");
doImport(new UrlResource(node4Snapshot));
Thread.sleep(5);
files = getImports(foreignSource);
assertEquals(1, files.size());
}
use of org.springframework.core.io.UrlResource in project ratpack by ratpack.
the class RatpackPropertiesTests method defaultBaseDirIsAbsoluteWhenInJar.
@Test
public void defaultBaseDirIsAbsoluteWhenInJar() throws Exception {
Resource basedir = new ClassPathResource("META-INF/io.netty.versions.properties");
URI uri = basedir.getURI();
assertTrue(uri.toString().startsWith("jar:file"));
basedir = new UrlResource(uri.toString().replace("META-INF/io.netty.versions.properties", ""));
ratpack.setBasedir(basedir);
assertTrue(ratpack.getBasepath().isAbsolute());
}
use of org.springframework.core.io.UrlResource in project cas by apereo.
the class UrlResourceMetadataResolver method supports.
@Override
public boolean supports(final SamlRegisteredService service) {
try {
final String metadataLocation = service.getMetadataLocation();
final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
return metadataResource instanceof UrlResource;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
Aggregations