use of org.apache.camel.NoFactoryAvailableException in project camel by apache.
the class OsgiFactoryFinderTest method testFindClass.
@Test
public void testFindClass() throws Exception {
OsgiFactoryFinder finder = new OsgiFactoryFinder(getBundleContext(), new DefaultClassResolver(), "META-INF/services/org/apache/camel/component/");
Class<?> clazz = finder.findClass("file_test", "strategy.factory.");
assertNotNull("We should get the file strategy factory here", clazz);
try {
clazz = finder.findClass("nofile", "strategy.factory.");
fail("We should get exception here");
} catch (Exception ex) {
assertTrue("Should get NoFactoryAvailableException", ex instanceof NoFactoryAvailableException);
}
try {
clazz = finder.findClass("file_test", "nostrategy.factory.");
fail("We should get exception here");
} catch (Exception ex) {
assertTrue("Should get IOException", ex instanceof IOException);
}
}
use of org.apache.camel.NoFactoryAvailableException in project camel by apache.
the class ServiceCallExpressionConfiguration method newInstance.
// *************************************************************************
// Factory
// *************************************************************************
@Override
public Expression newInstance(CamelContext camelContext) throws Exception {
ObjectHelper.notNull(factoryKey, "Expression factoryKey");
Expression answer;
// First try to find the factory from the registry.
ServiceExpressionFactory factory = CamelContextHelper.lookup(camelContext, factoryKey, ServiceExpressionFactory.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 (ServiceExpressionFactory.class.isAssignableFrom(type)) {
factory = (ServiceExpressionFactory) camelContext.getInjector().newInstance(type);
} else {
throw new IllegalArgumentException("Resolving Expression: " + factoryKey + " detected type conflict: Not a ExpressionFactory 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;
}
use of org.apache.camel.NoFactoryAvailableException in project camel by apache.
the class ServiceCallLoadBalancerConfiguration method newInstance.
// *************************************************************************
// Factory
// *************************************************************************
@Override
public LoadBalancer newInstance(CamelContext camelContext) throws Exception {
ObjectHelper.notNull(factoryKey, "LoadBalancer factoryKey");
LoadBalancer answer;
// First try to find the factory from the registry.
LoadBalancerFactory factory = CamelContextHelper.lookup(camelContext, factoryKey, LoadBalancerFactory.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 (LoadBalancerFactory.class.isAssignableFrom(type)) {
factory = (LoadBalancerFactory) camelContext.getInjector().newInstance(type);
} else {
throw new IllegalArgumentException("Resolving LoadBalancer: " + factoryKey + " detected type conflict: Not a LoadBalancerFactory 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;
}
use of org.apache.camel.NoFactoryAvailableException 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;
}
use of org.apache.camel.NoFactoryAvailableException in project camel by apache.
the class DefaultProcessorFactory method createChildProcessor.
@Override
public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) 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.createChildProcessor(routeContext, definition, mandatory);
}
}
} catch (NoFactoryAvailableException e) {
// ignore there is no custom factory
}
return null;
}
Aggregations