use of javax.enterprise.inject.CreationException in project camel by apache.
the class SyntheticBean method create.
@Override
public T create(CreationalContext<T> creationalContext) {
try {
T instance = target.produce(creationalContext);
target.inject(instance, creationalContext);
target.postConstruct(instance);
return instance;
} catch (Exception cause) {
throw new CreationException("Error while instantiating " + this, cause);
}
}
use of javax.enterprise.inject.CreationException in project camel by apache.
the class XmlCdiBeanFactory method camelContextBean.
private SyntheticBean<?> camelContextBean(CamelContextFactoryBean factory, URL url) {
Set<Annotation> annotations = new HashSet<>();
annotations.add(ANY);
if (hasId(factory)) {
addAll(annotations, ContextName.Literal.of(factory.getId()), NamedLiteral.of(factory.getId()));
} else {
annotations.add(DEFAULT);
factory.setImplicitId(true);
factory.setId(new CdiCamelContextNameStrategy().getNextName());
}
annotations.add(APPLICATION_SCOPED);
SyntheticAnnotated annotated = new SyntheticAnnotated(DefaultCamelContext.class, manager.createAnnotatedType(DefaultCamelContext.class).getTypeClosure(), annotations);
return new SyntheticBean<>(manager, annotated, DefaultCamelContext.class, environment.camelContextInjectionTarget(new SyntheticInjectionTarget<>(() -> {
DefaultCamelContext context = new DefaultCamelContext();
factory.setContext(context);
factory.setBeanManager(manager);
return context;
}, context -> {
try {
factory.afterPropertiesSet();
} catch (Exception cause) {
throw new CreationException(cause);
}
}), annotated, manager, extension), bean -> "imported Camel context with " + (factory.isImplicitId() ? "implicit " : "") + "id [" + factory.getId() + "] " + "from resource [" + url + "] " + "with qualifiers " + bean.getQualifiers());
}
use of javax.enterprise.inject.CreationException in project camel by apache.
the class XmlServiceExporterBean method create.
@Override
public T create(CreationalContext<T> creationalContext) {
try {
CamelContext context = isNotEmpty(exporter.getCamelContextId()) ? getReferenceByName(manager, exporter.getCamelContextId(), CamelContext.class).get() : getReference(manager, CamelContext.class, this.context);
Bean<?> bean = manager.resolve(manager.getBeans(exporter.getServiceRef()));
if (bean == null) {
throw new UnsatisfiedResolutionException("No bean with name [" + exporter.getServiceRef() + "] is deployed!");
}
@SuppressWarnings("unchecked") T service = (T) manager.getReference(bean, type, manager.createCreationalContext(bean));
Endpoint endpoint = getMandatoryEndpoint(context, exporter.getUri());
try {
// need to start endpoint before we create consumer
startService(endpoint);
Consumer consumer = endpoint.createConsumer(new BeanProcessor(service, context));
// add and start consumer
context.addService(consumer, true, true);
} catch (Exception cause) {
throw new FailedToCreateConsumerException(endpoint, cause);
}
return service;
} catch (Exception cause) {
throw new CreationException("Error while creating instance for " + this, cause);
}
}
use of javax.enterprise.inject.CreationException in project camel by apache.
the class XmlProxyFactoryBean method create.
@Override
public T create(CreationalContext<T> creationalContext) {
try {
CamelContext context = isNotEmpty(proxy.getCamelContextId()) ? getReferenceByName(manager, proxy.getCamelContextId(), CamelContext.class).get() : getReference(manager, CamelContext.class, this.context);
Endpoint endpoint;
if (isNotEmpty(proxy.getServiceRef())) {
endpoint = context.getRegistry().lookupByNameAndType(proxy.getServiceRef(), Endpoint.class);
} else {
if (isNotEmpty(proxy.getServiceUrl())) {
endpoint = context.getEndpoint(proxy.getServiceUrl());
} else {
throw new IllegalStateException("serviceUrl or serviceRef must not be empty!");
}
}
if (endpoint == null) {
throw new UnsatisfiedResolutionException("Could not resolve endpoint: " + (isNotEmpty(proxy.getServiceRef()) ? proxy.getServiceRef() : proxy.getServiceUrl()));
}
// binding is enabled by default
boolean bind = proxy.getBinding() != null ? proxy.getBinding() : true;
try {
// Start the endpoint before we create the producer
startService(endpoint);
Producer producer = endpoint.createProducer();
// Add and start the producer
context.addService(producer, true, true);
return createProxy(endpoint, bind, producer, (Class<T>) proxy.getServiceInterface());
} catch (Exception cause) {
throw new FailedToCreateProducerException(endpoint, cause);
}
} catch (Exception cause) {
throw new CreationException("Error while creating instance for " + this, cause);
}
}
Aggregations