Search in sources :

Example 26 with UrlResource

use of org.springframework.core.io.UrlResource in project cxf by apache.

the class ExternalAttachmentProviderTest method testReadDocumentAttachmentElementWithoutAppliesTo.

@Test
public void testReadDocumentAttachmentElementWithoutAppliesTo() throws MalformedURLException {
    ExternalAttachmentProvider eap = new ExternalAttachmentProvider();
    URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments2.xml");
    String uri = url.toExternalForm();
    eap.setLocation(new UrlResource(uri));
    eap.readDocument();
    assertTrue(eap.getAttachments().isEmpty());
}
Also used : UrlResource(org.springframework.core.io.UrlResource) URL(java.net.URL) Test(org.junit.Test)

Example 27 with UrlResource

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

Example 28 with UrlResource

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();
}
Also used : UrlResource(org.springframework.core.io.UrlResource) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 29 with UrlResource

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();
}
Also used : UrlResource(org.springframework.core.io.UrlResource) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 30 with UrlResource

use of org.springframework.core.io.UrlResource in project jetty.project by eclipse.

the class SpringConfigurationProcessor method init.

@Override
public void init(URL url, XmlParser.Node config, XmlConfiguration configuration) {
    try {
        _configuration = configuration;
        Resource resource = url != null ? new UrlResource(url) : new ByteArrayResource(("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" + config).getBytes(StandardCharsets.UTF_8));
        _beanFactory = new DefaultListableBeanFactory() {

            @Override
            protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs) {
                _configuration.initializeDefaults(bw.getWrappedInstance());
                super.applyPropertyValues(beanName, mbd, bw, pvs);
            }
        };
        new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(resource);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) PropertyValues(org.springframework.beans.PropertyValues) UrlResource(org.springframework.core.io.UrlResource) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) UrlResource(org.springframework.core.io.UrlResource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ByteArrayResource(org.springframework.core.io.ByteArrayResource) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

UrlResource (org.springframework.core.io.UrlResource)68 Test (org.junit.Test)36 Resource (org.springframework.core.io.Resource)31 URL (java.net.URL)25 ArrayList (java.util.ArrayList)10 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)10 ClassPathResource (org.springframework.core.io.ClassPathResource)10 GenericBean (org.springframework.tests.sample.beans.GenericBean)9 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)8 InputStream (java.io.InputStream)6 FileSystemResource (org.springframework.core.io.FileSystemResource)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 JUnitDNSServer (org.opennms.core.test.dns.annotations.JUnitDNSServer)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 JAXBContext (javax.xml.bind.JAXBContext)4 Unmarshaller (javax.xml.bind.Unmarshaller)4 BeansException (org.springframework.beans.BeansException)4