Search in sources :

Example 61 with UrlResource

use of org.springframework.core.io.UrlResource in project spring-cloud-stream by spring-cloud.

the class BinderFactoryConfiguration method binderTypeRegistry.

@Bean
@ConditionalOnMissingBean(BinderTypeRegistry.class)
public BinderTypeRegistry binderTypeRegistry(ConfigurableApplicationContext configurableApplicationContext) {
    Map<String, BinderType> binderTypes = new HashMap<>();
    ClassLoader classLoader = configurableApplicationContext.getClassLoader();
    // the above can never be null since it will default to ClassUtils.getDefaultClassLoader(..)
    try {
        Enumeration<URL> resources = classLoader.getResources("META-INF/spring.binders");
        if (!Boolean.valueOf(this.selfContained) && (resources == null || !resources.hasMoreElements())) {
            throw new BeanCreationException("Cannot create binder factory, no `META-INF/spring.binders` " + "resources found on the classpath");
        }
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            UrlResource resource = new UrlResource(url);
            for (BinderType binderType : parseBinderConfigurations(classLoader, resource)) {
                binderTypes.put(binderType.getDefaultName(), binderType);
            }
        }
    } catch (IOException | ClassNotFoundException e) {
        throw new BeanCreationException("Cannot create binder factory:", e);
    }
    return new DefaultBinderTypeRegistry(binderTypes);
}
Also used : DefaultBinderTypeRegistry(org.springframework.cloud.stream.binder.DefaultBinderTypeRegistry) BeanCreationException(org.springframework.beans.factory.BeanCreationException) HashMap(java.util.HashMap) IOException(java.io.IOException) URL(java.net.URL) UrlResource(org.springframework.core.io.UrlResource) BinderType(org.springframework.cloud.stream.binder.BinderType) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 62 with UrlResource

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

the class ParserUnitTests method testInTcp.

@Test
public void testInTcp() {
    DirectFieldAccessor dfa = new DirectFieldAccessor(tcpIn);
    assertSame(cfS1, dfa.getPropertyValue("serverConnectionFactory"));
    assertEquals("testInTcp", tcpIn.getComponentName());
    assertEquals("ip:tcp-inbound-channel-adapter", tcpIn.getComponentType());
    assertEquals(errorChannel, dfa.getPropertyValue("errorChannel"));
    assertFalse(cfS1.isLookupHost());
    assertFalse(tcpIn.isAutoStartup());
    assertEquals(124, tcpIn.getPhase());
    TcpMessageMapper cfS1Mapper = TestUtils.getPropertyValue(cfS1, "mapper", TcpMessageMapper.class);
    assertSame(mapper, cfS1Mapper);
    assertTrue(TestUtils.getPropertyValue(cfS1Mapper, "applySequence", Boolean.class));
    Object socketSupport = TestUtils.getPropertyValue(cfS1, "tcpSocketFactorySupport");
    assertTrue(socketSupport instanceof DefaultTcpNetSSLSocketFactorySupport);
    assertNotNull(TestUtils.getPropertyValue(socketSupport, "sslContext"));
    TcpSSLContextSupport tcpSSLContextSupport = new DefaultTcpSSLContextSupport("http:foo", "file:bar", "", "");
    assertTrue(TestUtils.getPropertyValue(tcpSSLContextSupport, "keyStore") instanceof UrlResource);
    assertTrue(TestUtils.getPropertyValue(tcpSSLContextSupport, "trustStore") instanceof UrlResource);
}
Also used : TcpMessageMapper(org.springframework.integration.ip.tcp.connection.TcpMessageMapper) UrlResource(org.springframework.core.io.UrlResource) DefaultTcpNetSSLSocketFactorySupport(org.springframework.integration.ip.tcp.connection.DefaultTcpNetSSLSocketFactorySupport) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) DefaultTcpSSLContextSupport(org.springframework.integration.ip.tcp.connection.DefaultTcpSSLContextSupport) TcpSSLContextSupport(org.springframework.integration.ip.tcp.connection.TcpSSLContextSupport) DefaultTcpSSLContextSupport(org.springframework.integration.ip.tcp.connection.DefaultTcpSSLContextSupport) Test(org.junit.Test)

Example 63 with UrlResource

use of org.springframework.core.io.UrlResource in project camunda-bpm-platform by camunda.

the class SpringConfigurationHelper method buildProcessEngine.

public static ProcessEngine buildProcessEngine(URL resource) {
    log.fine("==== 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 ProcessEngineException("no " + ProcessEngine.class.getName() + " defined in the application context " + resource.toString());
    }
    ProcessEngine processEngine = beansOfType.values().iterator().next();
    log.fine("==== SPRING PROCESS ENGINE CREATED ==================================================================");
    return processEngine;
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) UrlResource(org.springframework.core.io.UrlResource) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 64 with UrlResource

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

the class CandidateComponentsIndexLoader method doLoadIndex.

@Nullable
private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) {
    if (shouldIgnoreIndex) {
        return null;
    }
    try {
        Enumeration<URL> urls = classLoader.getResources(COMPONENTS_RESOURCE_LOCATION);
        if (!urls.hasMoreElements()) {
            return null;
        }
        List<Properties> result = new ArrayList<>();
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));
            result.add(properties);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Loaded " + result.size() + " index(es)");
        }
        int totalCount = result.stream().mapToInt(Properties::size).sum();
        return (totalCount > 0 ? new CandidateComponentsIndex(result) : null);
    } catch (IOException ex) {
        throw new IllegalStateException("Unable to load indexes from location [" + COMPONENTS_RESOURCE_LOCATION + "]", ex);
    }
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) SpringProperties(org.springframework.core.SpringProperties) URL(java.net.URL) Nullable(org.springframework.lang.Nullable)

Example 65 with UrlResource

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

the class BeanWrapperGenericsTests method testGenericListElement.

@Test
void testGenericListElement() throws Exception {
    GenericBean<?> gb = new GenericBean<>();
    gb.setResourceList(new ArrayList<>());
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.setPropertyValue("resourceList[0]", "http://localhost:8080");
    assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) GenericBean(org.springframework.beans.testfixture.beans.GenericBean) 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