use of org.springframework.core.io.UrlResource in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method loadAsResource.
@Override
public Resource loadAsResource(DocumentObject documentObject) {
String filename = documentObject.getReferenceDocumentFile();
try {
Path file = load(filename);
Resource resource = new UrlResource(file.toUri());
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
throw new StorageFileNotFoundException("Could not read file: " + filename);
}
} catch (MalformedURLException e) {
throw new StorageFileNotFoundException("Could not read file: " + filename);
}
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class ProvisionServiceIT method dwLoadRequisition.
/**
* This test should be set to Ignore until a DNS server can be integrated into unit tests
*
* @throws MalformedURLException
*/
@Test
@Ignore
public void dwLoadRequisition() throws MalformedURLException {
String nodeLabel = "localhost";
int nhash = nodeLabel.hashCode();
int chash = "localhost".hashCode();
Assert.assertEquals(nhash, chash);
Resource resource = new UrlResource("dns://localhost/localhost");
Requisition r = m_provService.loadRequisition(resource);
Assert.assertNotNull(r);
Assert.assertEquals(1, r.getNodeCount());
String foreignId = String.valueOf("localhost".hashCode());
RequisitionNode node = r.getNode(foreignId);
Assert.assertNotNull(node);
RequisitionInterface inf = node.getInterface("127.0.0.1");
Assert.assertNotNull(inf);
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoUrlAsResourceUsingMatchingExpression.
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", data = "72.14.204.99"), @DNSEntry(hostname = "monkey", data = "72.14.204.99") }) })
public void dwoUrlAsResourceUsingMatchingExpression() throws IOException, JAXBException {
String urlString = "dns://localhost:9153/example.com/?expression=[Ww]ww.*";
Resource resource = new UrlResource(urlString);
Assert.assertEquals(urlString, resource.getURL().toString());
Requisition req = null;
Assert.assertNotNull(resource);
InputStream resourceStream = resource.getInputStream();
JAXBContext context = JAXBContext.newInstance(Requisition.class);
Unmarshaller um = context.createUnmarshaller();
um.setSchema(null);
req = (Requisition) um.unmarshal(resourceStream);
Assert.assertEquals(1, req.getNodeCount());
resourceStream.close();
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoUrlAsResourceUsingComplexMatchingExpression.
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", data = "72.14.204.99") }) })
public void dwoUrlAsResourceUsingComplexMatchingExpression() throws IOException, JAXBException {
String urlString = "dns://localhost:9153/example.com/?expression=(%3Fi)^WWW.EXAM.*";
Resource resource = new UrlResource(urlString);
Assert.assertEquals(urlString, resource.getURL().toString());
Requisition req = null;
Assert.assertNotNull(resource);
InputStream resourceStream = resource.getInputStream();
JAXBContext context = JAXBContext.newInstance(Requisition.class);
Unmarshaller um = context.createUnmarshaller();
um.setSchema(null);
req = (Requisition) um.unmarshal(resourceStream);
Assert.assertEquals(1, req.getNodeCount());
resourceStream.close();
}
use of org.springframework.core.io.UrlResource in project activemq-artemis by apache.
the class ResourceLoadingSslContext method resourceFromString.
public static Resource resourceFromString(String uri) throws MalformedURLException {
Resource resource;
File file = new File(uri);
if (file.exists()) {
resource = new FileSystemResource(uri);
} else if (ResourceUtils.isUrl(uri)) {
resource = new UrlResource(uri);
} else {
resource = new ClassPathResource(uri);
}
return resource;
}
Aggregations