Search in sources :

Example 51 with UrlResource

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);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UrlResource(org.springframework.core.io.UrlResource) JarFile(java.util.jar.JarFile) File(java.io.File) URISyntaxException(java.net.URISyntaxException) ZipException(java.util.zip.ZipException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 52 with UrlResource

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"));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) File(java.io.File) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 53 with UrlResource

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());
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) URL(java.net.URL) Test(org.junit.Test)

Example 54 with UrlResource

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());
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) URI(java.net.URI) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 55 with UrlResource

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;
}
Also used : UrlResource(org.springframework.core.io.UrlResource) AbstractResource(org.springframework.core.io.AbstractResource) IOException(java.io.IOException)

Aggregations

UrlResource (org.springframework.core.io.UrlResource)100 Resource (org.springframework.core.io.Resource)41 URL (java.net.URL)33 Test (org.junit.jupiter.api.Test)30 Test (org.junit.Test)24 ClassPathResource (org.springframework.core.io.ClassPathResource)19 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)14 FileSystemResource (org.springframework.core.io.FileSystemResource)13 MalformedURLException (java.net.MalformedURLException)11 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)10 lombok.val (lombok.val)9 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)9 GenericBean (org.springframework.beans.testfixture.beans.GenericBean)9 File (java.io.File)8 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)8 InputStream (java.io.InputStream)6 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)6 Properties (java.util.Properties)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5