Search in sources :

Example 11 with ClassResolver

use of org.apache.camel.spi.ClassResolver in project camel by apache.

the class DefaultFactoryFinderTest method shouldComplainIfClassResolverCannotResolveClass.

@Test
public void shouldComplainIfClassResolverCannotResolveClass() throws IOException {
    final ClassResolver classResolver = mock(ClassResolver.class);
    final String properties = "class=" + TestImplA.class.getName();
    expect(classResolver.loadResourceAsStream("/org/apache/camel/impl/TestImplA")).andReturn(new ByteArrayInputStream(properties.getBytes()));
    expect(classResolver.resolveClass(TestImplA.class.getName())).andReturn(null);
    replay(classResolver);
    final DefaultFactoryFinder factoryFinder = new DefaultFactoryFinder(classResolver, TEST_RESOURCE_PATH);
    try {
        factoryFinder.findClass("TestImplA", null);
        fail("Should have thrown ClassNotFoundException");
    } catch (final ClassNotFoundException e) {
        verify(classResolver);
        assertEquals(TestImplA.class.getName(), e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClassResolver(org.apache.camel.spi.ClassResolver) Test(org.junit.Test)

Example 12 with ClassResolver

use of org.apache.camel.spi.ClassResolver in project camel by apache.

the class AbstractCamelContextFactoryBean method setupCustomServices.

private void setupCustomServices() {
    ModelJAXBContextFactory modelJAXBContextFactory = getBeanForType(ModelJAXBContextFactory.class);
    if (modelJAXBContextFactory != null) {
        LOG.info("Using custom ModelJAXBContextFactory: {}", modelJAXBContextFactory);
        getContext().setModelJAXBContextFactory(modelJAXBContextFactory);
    }
    ClassResolver classResolver = getBeanForType(ClassResolver.class);
    if (classResolver != null) {
        LOG.info("Using custom ClassResolver: {}", classResolver);
        getContext().setClassResolver(classResolver);
    }
    FactoryFinderResolver factoryFinderResolver = getBeanForType(FactoryFinderResolver.class);
    if (factoryFinderResolver != null) {
        LOG.info("Using custom FactoryFinderResolver: {}", factoryFinderResolver);
        getContext().setFactoryFinderResolver(factoryFinderResolver);
    }
    ExecutorServiceManager executorServiceStrategy = getBeanForType(ExecutorServiceManager.class);
    if (executorServiceStrategy != null) {
        LOG.info("Using custom ExecutorServiceStrategy: {}", executorServiceStrategy);
        getContext().setExecutorServiceManager(executorServiceStrategy);
    }
    ThreadPoolFactory threadPoolFactory = getBeanForType(ThreadPoolFactory.class);
    if (threadPoolFactory != null) {
        LOG.info("Using custom ThreadPoolFactory: {}", threadPoolFactory);
        getContext().getExecutorServiceManager().setThreadPoolFactory(threadPoolFactory);
    }
    ProcessorFactory processorFactory = getBeanForType(ProcessorFactory.class);
    if (processorFactory != null) {
        LOG.info("Using custom ProcessorFactory: {}", processorFactory);
        getContext().setProcessorFactory(processorFactory);
    }
    Debugger debugger = getBeanForType(Debugger.class);
    if (debugger != null) {
        LOG.info("Using custom Debugger: {}", debugger);
        getContext().setDebugger(debugger);
    }
    UuidGenerator uuidGenerator = getBeanForType(UuidGenerator.class);
    if (uuidGenerator != null) {
        LOG.info("Using custom UuidGenerator: {}", uuidGenerator);
        getContext().setUuidGenerator(uuidGenerator);
    }
    NodeIdFactory nodeIdFactory = getBeanForType(NodeIdFactory.class);
    if (nodeIdFactory != null) {
        LOG.info("Using custom NodeIdFactory: {}", nodeIdFactory);
        getContext().setNodeIdFactory(nodeIdFactory);
    }
    StreamCachingStrategy streamCachingStrategy = getBeanForType(StreamCachingStrategy.class);
    if (streamCachingStrategy != null) {
        LOG.info("Using custom StreamCachingStrategy: {}", streamCachingStrategy);
        getContext().setStreamCachingStrategy(streamCachingStrategy);
    }
    MessageHistoryFactory messageHistoryFactory = getBeanForType(MessageHistoryFactory.class);
    if (messageHistoryFactory != null) {
        LOG.info("Using custom MessageHistoryFactory: {}", messageHistoryFactory);
        getContext().setMessageHistoryFactory(messageHistoryFactory);
    }
}
Also used : Debugger(org.apache.camel.spi.Debugger) FactoryFinderResolver(org.apache.camel.spi.FactoryFinderResolver) MessageHistoryFactory(org.apache.camel.spi.MessageHistoryFactory) NodeIdFactory(org.apache.camel.spi.NodeIdFactory) UuidGenerator(org.apache.camel.spi.UuidGenerator) ExecutorServiceManager(org.apache.camel.spi.ExecutorServiceManager) ThreadPoolFactory(org.apache.camel.spi.ThreadPoolFactory) ModelJAXBContextFactory(org.apache.camel.spi.ModelJAXBContextFactory) ClassResolver(org.apache.camel.spi.ClassResolver) PackageScanClassResolver(org.apache.camel.spi.PackageScanClassResolver) StreamCachingStrategy(org.apache.camel.spi.StreamCachingStrategy) ProcessorFactory(org.apache.camel.spi.ProcessorFactory)

Example 13 with ClassResolver

use of org.apache.camel.spi.ClassResolver in project camel by apache.

the class OsgiClassResolverTest method testResolverResource.

@Test
public void testResolverResource() {
    ClassResolver classResolver = getClassResolver();
    InputStream is = classResolver.loadResourceAsStream("META-INF/services/org/apache/camel/TypeConverter");
    assertNotNull("The InputStream should not be null.", is);
}
Also used : InputStream(java.io.InputStream) ClassResolver(org.apache.camel.spi.ClassResolver) Test(org.junit.Test)

Aggregations

ClassResolver (org.apache.camel.spi.ClassResolver)13 InputStream (java.io.InputStream)6 PackageScanClassResolver (org.apache.camel.spi.PackageScanClassResolver)5 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)3 FactoryFinder (org.apache.camel.spi.FactoryFinder)3 Test (org.junit.Test)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 Properties (java.util.Properties)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 CamelContext (org.apache.camel.CamelContext)1 Component (org.apache.camel.Component)1 XsltBuilder (org.apache.camel.builder.xml.XsltBuilder)1 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)1