Search in sources :

Example 81 with UrlResource

use of org.springframework.core.io.UrlResource in project spring-boot by spring-projects.

the class AutoConfigurationMetadataLoader method loadMetadata.

static AutoConfigurationMetadata loadMetadata(ClassLoader classLoader, String path) {
    try {
        Enumeration<URL> urls = (classLoader != null) ? classLoader.getResources(path) : ClassLoader.getSystemResources(path);
        Properties properties = new Properties();
        while (urls.hasMoreElements()) {
            properties.putAll(PropertiesLoaderUtils.loadProperties(new UrlResource(urls.nextElement())));
        }
        return loadMetadata(properties);
    } catch (IOException ex) {
        throw new IllegalArgumentException("Unable to load @ConditionalOnClass location [" + path + "]", ex);
    }
}
Also used : UrlResource(org.springframework.core.io.UrlResource) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL)

Example 82 with UrlResource

use of org.springframework.core.io.UrlResource in project Activiti by Activiti.

the class SpringConfigurationHelper method buildProcessEngine.

public static ProcessEngine buildProcessEngine(URL resource) {
    log.debug("==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE =========================================");
    ApplicationContext applicationContext = new GenericXmlApplicationContext(new UrlResource(resource));
    Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class);
    if ((beansOfType == null) || (beansOfType.isEmpty())) {
        throw new ActivitiException("no " + ProcessEngine.class.getName() + " defined in the application context " + resource.toString());
    }
    ProcessEngine processEngine = beansOfType.values().iterator().next();
    log.debug("==== SPRING PROCESS ENGINE CREATED ==================================================================");
    return processEngine;
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ActivitiException(org.activiti.engine.ActivitiException) UrlResource(org.springframework.core.io.UrlResource) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 83 with UrlResource

use of org.springframework.core.io.UrlResource in project cas by apereo.

the class DynamicMetadataResolverAdapter method getResourceInputStream.

@Override
protected InputStream getResourceInputStream(final Resource resource, final String entityId) throws IOException {
    if (resource instanceof UrlResource && resource.getURL().toExternalForm().toLowerCase().endsWith("/entities/")) {
        HttpResponse response = null;
        try {
            val encodedId = EncodingUtils.urlEncode(entityId);
            val url = resource.getURL().toExternalForm().concat(encodedId);
            LOGGER.debug("Locating metadata input stream for [{}] via [{}]", encodedId, url);
            val exec = HttpUtils.HttpExecutionRequest.builder().method(HttpMethod.GET).url(url).headers(Map.of("Accept", "*/*")).build();
            response = HttpUtils.execute(exec);
            if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                val result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
                return new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8));
            }
        } catch (final Exception e) {
            LoggingUtils.error(LOGGER, e);
        } finally {
            HttpUtils.close(response);
        }
    }
    return ClosedInputStream.CLOSED_INPUT_STREAM;
}
Also used : lombok.val(lombok.val) UrlResource(org.springframework.core.io.UrlResource) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 84 with UrlResource

use of org.springframework.core.io.UrlResource in project cas by apereo.

the class DynamicMetadataResolverAdapterTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val resource = new UrlResource(new URI("http://localhost:6622/entities/"));
    val adapter = new DynamicMetadataResolverAdapter(Map.of(resource, new MetadataFilterChain()));
    adapter.setConfigBean(configBean);
    val entity = IOUtils.toString(new ClassPathResource("metadata.xml").getInputStream(), StandardCharsets.UTF_8);
    try (val webServer = new MockWebServer(6622, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        assertNotNull(adapter.getEntityDescriptorForEntityId("https://carmenwiki.osu.edu/shibboleth"));
    }
}
Also used : lombok.val(lombok.val) UrlResource(org.springframework.core.io.UrlResource) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MetadataFilterChain(org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain) URI(java.net.URI) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 85 with UrlResource

use of org.springframework.core.io.UrlResource in project cas by apereo.

the class ResourceUtilsTests method verifyPrepareDir.

@Test
public void verifyPrepareDir() {
    val url = getClass().getClassLoader().getResource("META-INF");
    assertNotNull(url);
    val resource = ResourceUtils.prepareClasspathResourceIfNeeded(new UrlResource(url), true, "MANIFEST");
    assertNotNull(resource);
}
Also used : lombok.val(lombok.val) UrlResource(org.springframework.core.io.UrlResource) Test(org.junit.jupiter.api.Test)

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