use of javax.enterprise.inject.InjectionException in project camel by apache.
the class CamelContextOsgiProducer method produce.
@Override
public T produce(CreationalContext<T> ctx) {
T context = super.produce(ctx);
// Register the context in the OSGi registry
BundleContext bundle = BundleContextUtils.getBundleContext(getClass());
context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle));
if (!(context instanceof DefaultCamelContext)) {
// Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface
throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
}
DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle));
CamelContextNameStrategy strategy = context.getNameStrategy();
OsgiCamelContextHelper.osgiUpdate(adapted, bundle);
// FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely
if (!(strategy instanceof DefaultCamelContextNameStrategy)) {
context.setNameStrategy(strategy);
}
return context;
}
use of javax.enterprise.inject.InjectionException in project camel by apache.
the class CamelContextProducer method produce.
@Override
public T produce(CreationalContext<T> ctx) {
T context = super.produce(ctx);
// Do not override the name if it's been already set (in the bean constructor for example)
if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy) {
context.setNameStrategy(nameStrategy(annotated));
}
// Add bean registry and Camel injector
if (context instanceof DefaultCamelContext) {
DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
adapted.setRegistry(new CdiCamelRegistry(manager));
adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
} else {
// Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
}
// Add event notifier if at least one observer is present
Set<Annotation> qualifiers = annotated.getAnnotations().stream().filter(isAnnotationType(Named.class).negate().and(q -> manager.isQualifier(q.annotationType()))).collect(toSet());
qualifiers.add(ANY);
if (qualifiers.size() == 1) {
qualifiers.add(DEFAULT);
}
qualifiers.retainAll(extension.getObserverEvents());
if (!qualifiers.isEmpty()) {
context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));
}
return context;
}
use of javax.enterprise.inject.InjectionException in project camel by apache.
the class CdiCamelFactory method producerTemplateFromUri.
private static ProducerTemplate producerTemplateFromUri(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension, Uri uri) {
try {
CamelContext context = uri.context().isEmpty() ? selectContext(ip, instance, extension) : selectContext(uri.context(), instance);
ProducerTemplate producerTemplate = context.createProducerTemplate();
Endpoint endpoint = context.getEndpoint(uri.value(), Endpoint.class);
producerTemplate.setDefaultEndpoint(endpoint);
return producerTemplate;
} catch (Exception cause) {
throw new InjectionException("Error injecting producer template annotated with " + uri + " into " + ip, cause);
}
}
use of javax.enterprise.inject.InjectionException in project camel by apache.
the class CdiCamelFactory method fluentProducerTemplateFromUri.
private static FluentProducerTemplate fluentProducerTemplateFromUri(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension, Uri uri) {
try {
CamelContext context = uri.context().isEmpty() ? selectContext(ip, instance, extension) : selectContext(uri.context(), instance);
FluentProducerTemplate producerTemplate = context.createFluentProducerTemplate();
Endpoint endpoint = context.getEndpoint(uri.value(), Endpoint.class);
producerTemplate.setDefaultEndpoint(endpoint);
return producerTemplate;
} catch (Exception cause) {
throw new InjectionException("Error injecting fluent producer template annotated with " + uri + " into " + ip, cause);
}
}
use of javax.enterprise.inject.InjectionException in project camel by apache.
the class SyntheticBean method destroy.
@Override
public void destroy(T instance, CreationalContext<T> creationalContext) {
try {
target.preDestroy(instance);
target.dispose(instance);
} catch (Exception cause) {
throw new InjectionException("Error while destroying " + this, cause);
} finally {
creationalContext.release();
}
}
Aggregations