Search in sources :

Example 1 with UnsatisfiedResolutionException

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelPostProcessorHelper(org.apache.camel.impl.CamelPostProcessorHelper) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException)

Example 2 with UnsatisfiedResolutionException

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);
    }
}
Also used : Processor(org.apache.camel.Processor) RedeliveryPolicyFactoryBean(org.apache.camel.cdi.xml.RedeliveryPolicyFactoryBean) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException)

Example 3 with UnsatisfiedResolutionException

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);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) CamelContextHelper.getMandatoryEndpoint(org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) BeanProcessor(org.apache.camel.component.bean.BeanProcessor) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException)

Example 4 with UnsatisfiedResolutionException

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);
}
Also used : BeanManagerImpl(org.apache.webbeans.container.BeanManagerImpl) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) OwbBean(org.apache.webbeans.component.OwbBean) ExtensionBean(org.apache.webbeans.component.ExtensionBean) BuiltInOwbBean(org.apache.webbeans.component.BuiltInOwbBean) Bean(javax.enterprise.inject.spi.Bean)

Example 5 with UnsatisfiedResolutionException

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);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException)

Aggregations

UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)5 CamelContext (org.apache.camel.CamelContext)3 CreationException (javax.enterprise.inject.CreationException)2 Endpoint (org.apache.camel.Endpoint)2 Bean (javax.enterprise.inject.spi.Bean)1 Consumer (org.apache.camel.Consumer)1 FailedToCreateConsumerException (org.apache.camel.FailedToCreateConsumerException)1 FailedToCreateProducerException (org.apache.camel.FailedToCreateProducerException)1 Processor (org.apache.camel.Processor)1 Producer (org.apache.camel.Producer)1 RedeliveryPolicyFactoryBean (org.apache.camel.cdi.xml.RedeliveryPolicyFactoryBean)1 BeanProcessor (org.apache.camel.component.bean.BeanProcessor)1 CamelPostProcessorHelper (org.apache.camel.impl.CamelPostProcessorHelper)1 RedeliveryPolicy (org.apache.camel.processor.RedeliveryPolicy)1 CamelContextHelper.getMandatoryEndpoint (org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint)1 BuiltInOwbBean (org.apache.webbeans.component.BuiltInOwbBean)1 ExtensionBean (org.apache.webbeans.component.ExtensionBean)1 OwbBean (org.apache.webbeans.component.OwbBean)1 BeanManagerImpl (org.apache.webbeans.container.BeanManagerImpl)1