use of org.apache.camel.NoFactoryAvailableException 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.NoFactoryAvailableException 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.NoFactoryAvailableException in project camel by apache.
the class DefaultComponentResolver method resolveComponent.
public Component resolveComponent(String name, CamelContext context) {
// lookup in registry first
Component componentReg = ResolverHelper.lookupComponentInRegistryWithFallback(context, name);
if (componentReg != null) {
return componentReg;
}
// not in registry then use component factory
Class<?> type;
try {
type = findComponent(name, context);
if (type == null) {
// not found
return null;
}
} catch (NoFactoryAvailableException e) {
return null;
} catch (Exception e) {
throw new IllegalArgumentException("Invalid URI, no Component registered for scheme: " + name, e);
}
if (getLog().isDebugEnabled()) {
getLog().debug("Found component: {} via type: {} via: {}{}", new Object[] { name, type.getName(), factoryFinder.getResourcePath(), name });
}
// create the component
if (Component.class.isAssignableFrom(type)) {
return (Component) context.getInjector().newInstance(type);
} else {
throw new IllegalArgumentException("Type is not a Component implementation. Found: " + type.getName());
}
}
use of org.apache.camel.NoFactoryAvailableException in project camel by apache.
the class DefaultDataFormatResolver method createDataFormatFromResource.
private DataFormat createDataFormatFromResource(String name, CamelContext context) {
DataFormat dataFormat = null;
Class<?> type = null;
try {
if (dataformatFactory == null) {
dataformatFactory = context.getFactoryFinder(DATAFORMAT_RESOURCE_PATH);
}
type = dataformatFactory.findClass(name);
} catch (NoFactoryAvailableException e) {
// ignore
} catch (Exception e) {
throw new IllegalArgumentException("Invalid URI, no DataFormat registered for scheme: " + name, e);
}
if (type == null) {
type = context.getClassResolver().resolveClass(name);
}
if (type != null) {
if (DataFormat.class.isAssignableFrom(type)) {
dataFormat = (DataFormat) context.getInjector().newInstance(type);
} else {
throw new IllegalArgumentException("Resolving dataformat: " + name + " detected type conflict: Not a DataFormat implementation. Found: " + type.getName());
}
}
return dataFormat;
}
use of org.apache.camel.NoFactoryAvailableException 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