use of org.apache.camel.Component in project camel by apache.
the class OsgiComponentResolverTest method testOsgiResolverFindLanguageDoubleFallbackTest.
@Test
public void testOsgiResolverFindLanguageDoubleFallbackTest() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.put("allstar", new SampleComponent(false));
registry.put("allstar-component", new SampleComponent(true));
CamelContext camelContext = new DefaultCamelContext(registry);
OsgiComponentResolver resolver = new OsgiComponentResolver(getBundleContext());
Component component = resolver.resolveComponent("allstar", camelContext);
assertNotNull("We should find the super component", component);
assertTrue("We should get the super component here", component instanceof SampleComponent);
assertFalse("We should NOT find the fallback component", ((SampleComponent) component).isFallback());
}
use of org.apache.camel.Component in project camel by apache.
the class OsgiComponentResolverTest method testOsgiResolverFindComponentTest.
@Test
public void testOsgiResolverFindComponentTest() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
OsgiComponentResolver resolver = new OsgiComponentResolver(getBundleContext());
Component component = resolver.resolveComponent("file_test", camelContext);
assertNotNull("We should find file_test component", component);
assertTrue("We should get the file component here", component instanceof FileComponent);
}
use of org.apache.camel.Component in project camel by apache.
the class OsgiComponentResolverTest method testOsgiResolverFindComponentFallbackTest.
@Test
public void testOsgiResolverFindComponentFallbackTest() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.put("allstar-component", new SampleComponent(true));
CamelContext camelContext = new DefaultCamelContext(registry);
OsgiComponentResolver resolver = new OsgiComponentResolver(getBundleContext());
Component component = resolver.resolveComponent("allstar", camelContext);
assertNotNull("We should find the super component", component);
assertTrue("We should get the super component here", component instanceof SampleComponent);
}
use of org.apache.camel.Component in project camel by apache.
the class ManagedCamelContext method componentParameterJsonSchema.
public String componentParameterJsonSchema(String componentName) throws Exception {
// favor using pre generated schema if component has that
String json = context.getComponentParameterJsonSchema(componentName);
if (json == null) {
// okay this requires having the component on the classpath and being instantiated
Component component = context.getComponent(componentName);
if (component != null) {
ComponentConfiguration configuration = component.createComponentConfiguration();
json = configuration.createParameterJsonSchema();
}
}
return json;
}
use of org.apache.camel.Component in project camel by apache.
the class CamelContextHelper method findComponents.
public static SortedMap<String, Properties> findComponents(CamelContext camelContext, Enumeration<URL> componentDescriptionIter) throws LoadPropertiesException {
SortedMap<String, Properties> map = new TreeMap<String, Properties>();
while (componentDescriptionIter != null && componentDescriptionIter.hasMoreElements()) {
URL url = componentDescriptionIter.nextElement();
LOG.trace("Finding components in url: {}", url);
try {
Properties properties = new Properties();
properties.load(url.openStream());
String names = properties.getProperty("components");
if (names != null) {
StringTokenizer tok = new StringTokenizer(names);
while (tok.hasMoreTokens()) {
String name = tok.nextToken();
// try to find the class name for this component
String className = null;
InputStream is = null;
try {
// now load the component name resource so we can grab its properties and the class name
Enumeration<URL> urls = camelContext.getClassResolver().loadAllResourcesAsURL(COMPONENT_BASE + name);
if (urls != null && urls.hasMoreElements()) {
is = urls.nextElement().openStream();
}
if (is != null) {
Properties compProperties = new Properties();
compProperties.load(is);
if (!compProperties.isEmpty()) {
className = compProperties.getProperty("class");
}
}
} catch (Exception e) {
// ignore
} finally {
IOHelper.close(is);
}
// inherit properties we loaded first, as it has maven details
Properties prop = new Properties();
prop.putAll(properties);
if (camelContext.hasComponent(name) != null) {
prop.put("component", camelContext.getComponent(name));
}
if (className != null) {
prop.put("class", className);
}
prop.put("name", name);
map.put(name, prop);
}
}
} catch (IOException e) {
throw new LoadPropertiesException(url, e);
}
}
// lets see what other components are registered on camel context
List<String> names = camelContext.getComponentNames();
for (String name : names) {
if (!map.containsKey(name)) {
Component component = camelContext.getComponent(name);
if (component != null) {
Properties properties = new Properties();
properties.put("component", component);
properties.put("class", component.getClass().getName());
properties.put("name", name);
// override default component if name clash
map.put(name, properties);
}
}
}
// lets see what other components are in the registry
Map<String, Component> beanMap = camelContext.getRegistry().findByTypeWithName(Component.class);
Set<Map.Entry<String, Component>> entries = beanMap.entrySet();
for (Map.Entry<String, Component> entry : entries) {
String name = entry.getKey();
if (!map.containsKey(name)) {
Component component = entry.getValue();
if (component != null) {
Properties properties = new Properties();
properties.put("component", component);
properties.put("class", component.getClass().getName());
properties.put("name", name);
map.put(name, properties);
}
}
}
return map;
}
Aggregations