Search in sources :

Example 1 with ServiceFilterFactory

use of org.apache.camel.cloud.ServiceFilterFactory in project camel by apache.

the class ServiceCallServiceFilterConfiguration method newInstance.

// *************************************************************************
// Factory
// *************************************************************************
@Override
public ServiceFilter newInstance(CamelContext camelContext) throws Exception {
    ObjectHelper.notNull(factoryKey, "ServiceFilter factoryKey");
    ServiceFilter answer;
    // First try to find the factory from the registry.
    ServiceFilterFactory factory = CamelContextHelper.lookup(camelContext, factoryKey, ServiceFilterFactory.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 (ServiceFilterFactory.class.isAssignableFrom(type)) {
                factory = (ServiceFilterFactory) camelContext.getInjector().newInstance(type);
            } else {
                throw new NoFactoryAvailableException("Resolving ServiceFilter: " + factoryKey + " detected type conflict: Not a ServiceFilterFactory 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 : ServiceFilter(org.apache.camel.cloud.ServiceFilter) ServiceFilterFactory(org.apache.camel.cloud.ServiceFilterFactory) HashMap(java.util.HashMap) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException)

Aggregations

HashMap (java.util.HashMap)1 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)1 ServiceFilter (org.apache.camel.cloud.ServiceFilter)1 ServiceFilterFactory (org.apache.camel.cloud.ServiceFilterFactory)1