Search in sources :

Example 16 with NoFactoryAvailableException

use of org.apache.camel.NoFactoryAvailableException in project camel by apache.

the class DefaultProcessorFactory method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
    String name = definition.getClass().getSimpleName();
    FactoryFinder finder = routeContext.getCamelContext().getFactoryFinder(RESOURCE_PATH);
    try {
        if (finder != null) {
            Object object = finder.newInstance(name);
            if (object != null && object instanceof ProcessorFactory) {
                ProcessorFactory pc = (ProcessorFactory) object;
                return pc.createProcessor(routeContext, definition);
            }
        }
    } catch (NoFactoryAvailableException e) {
    // ignore there is no custom factory
    }
    return null;
}
Also used : NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FactoryFinder(org.apache.camel.spi.FactoryFinder) ProcessorFactory(org.apache.camel.spi.ProcessorFactory)

Example 17 with NoFactoryAvailableException

use of org.apache.camel.NoFactoryAvailableException in project camel by apache.

the class ServiceCallServiceChooserConfiguration method newInstance.

// *************************************************************************
// Factory
// *************************************************************************
@Override
public ServiceChooser newInstance(CamelContext camelContext) throws Exception {
    ObjectHelper.notNull(factoryKey, "ServiceChooser factoryKey");
    ServiceChooser answer;
    // First try to find the factory from the registry.
    ServiceChooserFactory factory = CamelContextHelper.lookup(camelContext, factoryKey, ServiceChooserFactory.class);
    if (factory != null) {
        // If a factory is found in the registry do not re-configure it as
        // it should be pre-configured.
        answer = factory.newInstance(camelContext);
    } else {
        Class<?> type;
        try {
            // Then use Service factory.
            type = camelContext.getFactoryFinder(RESOURCE_PATH).findClass(factoryKey);
        } catch (Exception e) {
            throw new NoFactoryAvailableException(RESOURCE_PATH + factoryKey, e);
        }
        if (type != null) {
            if (ServiceChooserFactory.class.isAssignableFrom(type)) {
                factory = (ServiceChooserFactory) camelContext.getInjector().newInstance(type);
            } else {
                throw new NoFactoryAvailableException("Resolving ServiceChooser: " + factoryKey + " detected type conflict: Not a ServiceChooserFactory implementation. Found: " + type.getName());
            }
        }
        try {
            Map<String, Object> parameters = new HashMap<>();
            IntrospectionSupport.getProperties(this, parameters, null, false);
            parameters.put("properties", getPropertiesAsMap(camelContext));
            IntrospectionSupport.setProperties(factory, parameters);
            answer = factory.newInstance(camelContext);
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }
    return answer;
}
Also used : ServiceChooser(org.apache.camel.cloud.ServiceChooser) HashMap(java.util.HashMap) ServiceChooserFactory(org.apache.camel.cloud.ServiceChooserFactory) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException)

Example 18 with NoFactoryAvailableException

use of org.apache.camel.NoFactoryAvailableException in project camel by apache.

the class ServiceCallServiceDiscoveryConfiguration method newInstance.

// *************************************************************************
// Factory
// *************************************************************************
@Override
public ServiceDiscovery newInstance(CamelContext camelContext) throws Exception {
    ObjectHelper.notNull(factoryKey, "ServiceDiscovery factoryKey");
    ServiceDiscovery answer;
    // First try to find the factory from the registry.
    ServiceDiscoveryFactory factory = CamelContextHelper.lookup(camelContext, factoryKey, ServiceDiscoveryFactory.class);
    if (factory != null) {
        // If a factory is found in the registry do not re-configure it as
        // it should be pre-configured.
        answer = factory.newInstance(camelContext);
    } else {
        Class<?> type;
        try {
            // Then use Service factory.
            type = camelContext.getFactoryFinder(RESOURCE_PATH).findClass(factoryKey);
        } catch (Exception e) {
            throw new NoFactoryAvailableException(RESOURCE_PATH + factoryKey, e);
        }
        if (type != null) {
            if (ServiceDiscoveryFactory.class.isAssignableFrom(type)) {
                factory = (ServiceDiscoveryFactory) camelContext.getInjector().newInstance(type);
            } else {
                throw new IllegalArgumentException("Resolving ServiceDiscovery: " + factoryKey + " detected type conflict: Not a ServiceDiscoveryFactory implementation. Found: " + type.getName());
            }
        }
        try {
            Map<String, Object> parameters = new HashMap<>();
            IntrospectionSupport.getProperties(this, parameters, null, false);
            parameters.put("properties", getPropertiesAsMap(camelContext));
            postProcessFactoryParameters(camelContext, parameters);
            IntrospectionSupport.setProperties(factory, parameters);
            answer = factory.newInstance(camelContext);
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }
    return answer;
}
Also used : ServiceDiscoveryFactory(org.apache.camel.cloud.ServiceDiscoveryFactory) HashMap(java.util.HashMap) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) ServiceDiscovery(org.apache.camel.cloud.ServiceDiscovery)

Aggregations

NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)18 FactoryFinder (org.apache.camel.spi.FactoryFinder)7 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 IOException (java.io.IOException)3 Component (org.apache.camel.Component)3 ClassResolver (org.apache.camel.spi.ClassResolver)3 PackageScanClassResolver (org.apache.camel.spi.PackageScanClassResolver)3 BufferedInputStream (java.io.BufferedInputStream)2 Properties (java.util.Properties)2 ProcessorFactory (org.apache.camel.spi.ProcessorFactory)2 RestConfiguration (org.apache.camel.spi.RestConfiguration)2 URL (java.net.URL)1 Expression (org.apache.camel.Expression)1 NoSuchBeanException (org.apache.camel.NoSuchBeanException)1 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)1 Processor (org.apache.camel.Processor)1 Producer (org.apache.camel.Producer)1 LoadBalancer (org.apache.camel.cloud.LoadBalancer)1 LoadBalancerFactory (org.apache.camel.cloud.LoadBalancerFactory)1