use of org.apache.camel.component.cache.CacheComponent in project camel by apache.
the class CacheComponentAutoConfiguration method configureCacheComponent.
@Lazy
@Bean(name = "cache-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(CacheComponent.class)
public CacheComponent configureCacheComponent(CamelContext camelContext, CacheComponentConfiguration configuration) throws Exception {
CacheComponent component = new CacheComponent();
component.setCamelContext(camelContext);
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
Class<?> paramClass = value.getClass();
if (paramClass.getName().endsWith("NestedConfiguration")) {
Class nestedClass = null;
try {
nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
HashMap<String, Object> nestedParameters = new HashMap<>();
IntrospectionSupport.getProperties(value, nestedParameters, null, false);
Object nestedProperty = nestedClass.newInstance();
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
entry.setValue(nestedProperty);
} catch (NoSuchFieldException e) {
}
}
}
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
return component;
}
use of org.apache.camel.component.cache.CacheComponent in project camel by apache.
the class BaseCacheTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
// use a file cache manager factory to load out test configuration
cache = new CacheComponent();
cache.setCacheManagerFactory(new FileCacheManagerFactory("src/test/resources/test-ehcache.xml"));
jndi.bind("cache", cache);
return jndi;
}
Aggregations