use of javax.enterprise.inject.UnsatisfiedResolutionException in project camel by apache.
the class CdiCamelBeanPostProcessor method getPostProcessorHelper.
private CamelPostProcessorHelper getPostProcessorHelper(String contextName) {
CamelPostProcessorHelper helper = postProcessorHelpers.get(contextName);
if (helper == null) {
CamelContext context = getOrLookupCamelContext(contextName);
if (context == null) {
throw new UnsatisfiedResolutionException("No Camel context with name [" + contextName + "] is deployed!");
}
helper = new CamelPostProcessorHelper(context);
postProcessorHelpers.put(contextName, helper);
}
return helper;
}
use of javax.enterprise.inject.UnsatisfiedResolutionException in project camel by apache.
the class XmlErrorHandlerFactoryBean method setProperties.
private void setProperties(DefaultErrorHandlerBuilder builder) throws Exception {
if (nonNull(handler.getDeadLetterHandleNewException())) {
builder.setDeadLetterHandleNewException(handler.getDeadLetterHandleNewException());
}
builder.setDeadLetterUri(handler.getDeadLetterUri());
builder.setExecutorServiceRef(handler.getExecutorServiceRef());
builder.setRetryWhileRef(handler.getRetryWhileRef());
if (nonNull(handler.getUseOriginalMessage())) {
builder.setUseOriginalMessage(handler.getUseOriginalMessage());
}
if (isNotEmpty(handler.getOnExceptionOccurredRef())) {
Processor processor = getReferenceByName(manager, handler.getOnExceptionOccurredRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onExceptionOccurredRef")));
builder.setOnExceptionOccurred(processor);
}
if (isNotEmpty(handler.getOnPrepareFailureRef())) {
Processor processor = getReferenceByName(manager, handler.getOnPrepareFailureRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onPrepareFailureRef")));
builder.setOnPrepareFailure(processor);
}
if (isNotEmpty(handler.getOnRedeliveryRef())) {
Processor processor = getReferenceByName(manager, handler.getOnRedeliveryRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onRedeliveryRef")));
builder.setOnRedelivery(processor);
}
if (nonNull(handler.getRedeliveryPolicy())) {
RedeliveryPolicyFactoryBean policy = handler.getRedeliveryPolicy();
policy.setBeanManager(manager);
builder.setRedeliveryPolicy(policy.getObject());
}
if (isNotEmpty(handler.getRedeliveryPolicyRef())) {
RedeliveryPolicy policy = getReferenceByName(manager, handler.getRedeliveryPolicyRef(), RedeliveryPolicy.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getRedeliveryPolicyRef(), "redeliveryPolicyRef")));
builder.setRedeliveryPolicy(policy);
}
}
use of javax.enterprise.inject.UnsatisfiedResolutionException 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.UnsatisfiedResolutionException in project tomee by apache.
the class WebappBeanManager method getInjectableReference.
@Override
public Object getInjectableReference(final InjectionPoint injectionPoint, final CreationalContext<?> ctx) {
Asserts.assertNotNull(injectionPoint, "injectionPoint parameter");
if (injectionPoint == null) {
return null;
}
final BeanManagerImpl parentBm = getParentBm();
final Boolean existing = USE_PARENT_BM.get();
if (existing != null && existing) {
// shortcut the whole logic to keep the threadlocal set up correctly
if (parentBm == null) {
return null;
}
return parentBm.getInjectableReference(injectionPoint, ctx);
}
// we can do it cause there is caching but we shouldn't - easy way to overide OWB actually
final Bean<Object> injectedBean = (Bean<Object>) getInjectionResolver().getInjectionPointBean(injectionPoint);
try {
if (parentBm != null && injectedBean != null && injectedBean == parentBm.getInjectionResolver().getInjectionPointBean(injectionPoint)) {
USE_PARENT_BM.set(true);
try {
return parentBm.getInjectableReference(injectionPoint, ctx);
} finally {
USE_PARENT_BM.remove();
}
}
} catch (final UnsatisfiedResolutionException ure) {
// skip, use this bean
}
return super.getInjectableReference(injectionPoint, ctx);
}
use of javax.enterprise.inject.UnsatisfiedResolutionException 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