use of org.apache.camel.Component in project camel by apache.
the class RouteBuilder method propertyInject.
/**
* Injects a property placeholder value with the given key converted to the given type.
*
* @param key the property key
* @param type the type to convert the value as
* @return the value, or <tt>null</tt> if value is empty
* @throws Exception is thrown if property with key not found or error converting to the given type.
*/
public <T> T propertyInject(String key, Class<T> type) throws Exception {
ObjectHelper.notEmpty(key, "key");
ObjectHelper.notNull(type, "Class type");
// the properties component is mandatory
Component component = getContext().hasComponent("properties");
if (component == null) {
throw new IllegalArgumentException("PropertiesComponent with name properties must be defined" + " in CamelContext to support property placeholders in expressions");
}
PropertiesComponent pc = getContext().getTypeConverter().mandatoryConvertTo(PropertiesComponent.class, component);
// enclose key with {{ }} to force parsing
Object value = pc.parseUri(pc.getPrefixToken() + key + pc.getSuffixToken());
if (value != null) {
return getContext().getTypeConverter().mandatoryConvertTo(type, value);
} else {
return null;
}
}
use of org.apache.camel.Component in project camel by apache.
the class BlueprintComponentResolverTest 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);
BlueprintComponentResolver resolver = new BlueprintComponentResolver(null);
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 BlueprintComponentResolverTest method testOsgiResolverFindComponentFallbackTest.
@Test
public void testOsgiResolverFindComponentFallbackTest() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.put("allstar-component", new SampleComponent(true));
CamelContext camelContext = new DefaultCamelContext(registry);
BlueprintComponentResolver resolver = new BlueprintComponentResolver(null);
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 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);
}
Aggregations