use of org.apache.camel.CamelContextAware in project camel by apache.
the class JohnzonDataFormatAutoConfiguration method configureJohnzonDataFormatFactory.
@Bean(name = "json-johnzon-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JohnzonDataFormat.class)
public DataFormatFactory configureJohnzonDataFormatFactory(final CamelContext camelContext, final JohnzonDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
JohnzonDataFormat dataformat = new JohnzonDataFormat();
if (CamelContextAware.class.isAssignableFrom(JohnzonDataFormat.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
try {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
return dataformat;
}
};
}
use of org.apache.camel.CamelContextAware in project camel by apache.
the class SqlLanguageAutoConfiguration method configureSqlLanguage.
@Bean(name = "sql-language")
@Scope("prototype")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SqlLanguage.class)
public SqlLanguage configureSqlLanguage(CamelContext camelContext, SqlLanguageConfiguration configuration) throws Exception {
SqlLanguage language = new SqlLanguage();
if (CamelContextAware.class.isAssignableFrom(SqlLanguage.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(language);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), language, parameters);
return language;
}
use of org.apache.camel.CamelContextAware in project camel by apache.
the class JsonPathLanguageAutoConfiguration method configureJsonPathLanguage.
@Bean(name = "jsonpath-language")
@Scope("prototype")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JsonPathLanguage.class)
public JsonPathLanguage configureJsonPathLanguage(CamelContext camelContext, JsonPathLanguageConfiguration configuration) throws Exception {
JsonPathLanguage language = new JsonPathLanguage();
if (CamelContextAware.class.isAssignableFrom(JsonPathLanguage.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(language);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), language, parameters);
return language;
}
use of org.apache.camel.CamelContextAware in project camel by apache.
the class DefaultManagementStrategy method doStartManagementStrategy.
protected void doStartManagementStrategy() throws Exception {
ObjectHelper.notNull(camelContext, "CamelContext");
if (eventNotifiers != null) {
for (EventNotifier notifier : eventNotifiers) {
// inject CamelContext if the service is aware
if (notifier instanceof CamelContextAware) {
CamelContextAware aware = (CamelContextAware) notifier;
aware.setCamelContext(camelContext);
}
ServiceHelper.startService(notifier);
}
}
if (managementAgent != null) {
ServiceHelper.startService(managementAgent);
// set the naming strategy using the domain name from the agent
if (managementNamingStrategy == null) {
setManagementNamingStrategy(new DefaultManagementNamingStrategy(managementAgent.getMBeanObjectDomainName()));
}
}
if (managementNamingStrategy instanceof CamelContextAware) {
((CamelContextAware) managementNamingStrategy).setCamelContext(getCamelContext());
}
}
use of org.apache.camel.CamelContextAware in project camel by apache.
the class AggregateDefinition method createAggregationStrategy.
private AggregationStrategy createAggregationStrategy(RouteContext routeContext) {
AggregationStrategy strategy = getAggregationStrategy();
if (strategy == null && strategyRef != null) {
Object aggStrategy = routeContext.lookup(strategyRef, Object.class);
if (aggStrategy instanceof AggregationStrategy) {
strategy = (AggregationStrategy) aggStrategy;
} else if (aggStrategy != null) {
AggregationStrategyBeanAdapter adapter = new AggregationStrategyBeanAdapter(aggStrategy, getAggregationStrategyMethodName());
if (getStrategyMethodAllowNull() != null) {
adapter.setAllowNullNewExchange(getStrategyMethodAllowNull());
adapter.setAllowNullOldExchange(getStrategyMethodAllowNull());
}
strategy = adapter;
} else {
throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef);
}
}
if (groupExchanges != null && groupExchanges) {
if (strategy != null || strategyRef != null) {
throw new IllegalArgumentException("Options groupExchanges and AggregationStrategy cannot be enabled at the same time");
}
if (eagerCheckCompletion != null && !eagerCheckCompletion) {
throw new IllegalArgumentException("Option eagerCheckCompletion cannot be false when groupExchanges has been enabled");
}
// set eager check to enabled by default when using grouped exchanges
setEagerCheckCompletion(true);
// if grouped exchange is enabled then use special strategy for that
strategy = new GroupedExchangeAggregationStrategy();
}
if (strategy == null) {
throw new IllegalArgumentException("AggregationStrategy or AggregationStrategyRef must be set on " + this);
}
if (strategy instanceof CamelContextAware) {
((CamelContextAware) strategy).setCamelContext(routeContext.getCamelContext());
}
return strategy;
}
Aggregations