use of org.apache.camel.spi.FactoryFinder in project camel by apache.
the class GenericFileEndpoint method createGenericFileStrategy.
/**
* A strategy method to lazily create the file strategy
*/
@SuppressWarnings("unchecked")
protected GenericFileProcessStrategy<T> createGenericFileStrategy() {
Class<?> factory = null;
try {
FactoryFinder finder = getCamelContext().getFactoryFinder("META-INF/services/org/apache/camel/component/");
log.trace("Using FactoryFinder: {}", finder);
factory = finder.findClass(getScheme(), "strategy.factory.", CamelContext.class);
} catch (ClassNotFoundException e) {
log.trace("'strategy.factory.class' not found", e);
} catch (IOException e) {
log.trace("No strategy factory defined in 'META-INF/services/org/apache/camel/component/'", e);
}
if (factory == null) {
// use default
try {
log.trace("Using ClassResolver to resolve class: {}", DEFAULT_STRATEGYFACTORY_CLASS);
factory = this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS);
} catch (Exception e) {
log.trace("Cannot load class: {}", DEFAULT_STRATEGYFACTORY_CLASS, e);
}
// fallback and us this class loader
try {
if (log.isTraceEnabled()) {
log.trace("Using classloader: {} to resolve class: {}", this.getClass().getClassLoader(), DEFAULT_STRATEGYFACTORY_CLASS);
}
factory = this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS, this.getClass().getClassLoader());
} catch (Exception e) {
if (log.isTraceEnabled()) {
log.trace("Cannot load class: {} using classloader: " + this.getClass().getClassLoader(), DEFAULT_STRATEGYFACTORY_CLASS, e);
}
}
if (factory == null) {
throw new TypeNotPresentException(DEFAULT_STRATEGYFACTORY_CLASS + " class not found", null);
}
}
try {
Method factoryMethod = factory.getMethod("createGenericFileProcessStrategy", CamelContext.class, Map.class);
Map<String, Object> params = getParamsAsMap();
log.debug("Parameters for Generic file process strategy {}", params);
return (GenericFileProcessStrategy<T>) ObjectHelper.invokeMethod(factoryMethod, null, getCamelContext(), params);
} catch (NoSuchMethodException e) {
throw new TypeNotPresentException(factory.getSimpleName() + ".createGenericFileProcessStrategy method not found", e);
}
}
use of org.apache.camel.spi.FactoryFinder 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;
}
use of org.apache.camel.spi.FactoryFinder in project camel by apache.
the class DefaultCamelContext method getComponentParameterJsonSchema.
public String getComponentParameterJsonSchema(String componentName) throws IOException {
// use the component factory finder to find the package name of the component class, which is the location
// where the documentation exists as well
FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH);
try {
Class<?> clazz = null;
try {
clazz = finder.findClass(componentName);
} catch (NoFactoryAvailableException e) {
// ignore, i.e. if a component is an auto-configured spring-boot
// component
}
if (clazz == null) {
// fallback and find existing component
Component existing = hasComponent(componentName);
if (existing != null) {
clazz = existing.getClass();
} else {
return null;
}
}
String packageName = clazz.getPackage().getName();
packageName = packageName.replace('.', '/');
String path = packageName + "/" + componentName + ".json";
ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
log.debug("Loading component JSON Schema for: {} using class resolver: {} -> {}", new Object[] { componentName, resolver, inputStream });
if (inputStream != null) {
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
// special for ActiveMQ as it is really just JMS
if ("ActiveMQComponent".equals(clazz.getSimpleName())) {
return getComponentParameterJsonSchema("jms");
} else {
return null;
}
} catch (ClassNotFoundException e) {
return null;
}
}
use of org.apache.camel.spi.FactoryFinder in project camel by apache.
the class DefaultCamelContext method getDataFormatParameterJsonSchema.
public String getDataFormatParameterJsonSchema(String dataFormatName) throws IOException {
// use the dataformat factory finder to find the package name of the dataformat class, which is the location
// where the documentation exists as well
FactoryFinder finder = getFactoryFinder(DefaultDataFormatResolver.DATAFORMAT_RESOURCE_PATH);
try {
Class<?> clazz = null;
try {
clazz = finder.findClass(dataFormatName);
} catch (NoFactoryAvailableException e) {
// ignore, i.e. if a component is an auto-configured spring-boot
// data-formats
}
if (clazz == null) {
return null;
}
String packageName = clazz.getPackage().getName();
packageName = packageName.replace('.', '/');
String path = packageName + "/" + dataFormatName + ".json";
ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
log.debug("Loading dataformat JSON Schema for: {} using class resolver: {} -> {}", new Object[] { dataFormatName, resolver, inputStream });
if (inputStream != null) {
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
return null;
} catch (ClassNotFoundException e) {
return null;
}
}
use of org.apache.camel.spi.FactoryFinder in project camel by apache.
the class DefaultCamelContext method getLanguageParameterJsonSchema.
public String getLanguageParameterJsonSchema(String languageName) throws IOException {
// use the language factory finder to find the package name of the language class, which is the location
// where the documentation exists as well
FactoryFinder finder = getFactoryFinder(DefaultLanguageResolver.LANGUAGE_RESOURCE_PATH);
try {
Class<?> clazz = null;
try {
clazz = finder.findClass(languageName);
} catch (NoFactoryAvailableException e) {
// ignore, i.e. if a component is an auto-configured spring-boot
// languages
}
if (clazz == null) {
return null;
}
String packageName = clazz.getPackage().getName();
packageName = packageName.replace('.', '/');
String path = packageName + "/" + languageName + ".json";
ClassResolver resolver = getClassResolver();
InputStream inputStream = resolver.loadResourceAsStream(path);
log.debug("Loading language JSON Schema for: {} using class resolver: {} -> {}", new Object[] { languageName, resolver, inputStream });
if (inputStream != null) {
try {
return IOHelper.loadText(inputStream);
} finally {
IOHelper.close(inputStream);
}
}
return null;
} catch (ClassNotFoundException e) {
return null;
}
}
Aggregations