Search in sources :

Example 1 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project camel by apache.

the class CdiCamelExtension method beans.

private void beans(@Observes ProcessBean<?> pb, BeanManager manager) {
    cdiBeans.add(pb.getBean());
    // Lookup for CDI event endpoint injection points
    pb.getBean().getInjectionPoints().stream().filter(ip -> CdiEventEndpoint.class.equals(getRawType(ip.getType()))).forEach(ip -> {
        Type type = ip.getType() instanceof ParameterizedType ? ((ParameterizedType) ip.getType()).getActualTypeArguments()[0] : Object.class;
        String uri = eventEndpointUri(type, ip.getQualifiers());
        cdiEventEndpoints.put(uri, new CdiEventEndpoint<>(uri, type, ip.getQualifiers(), manager));
    });
}
Also used : CdiSpiHelper.isAnnotationType(org.apache.camel.cdi.CdiSpiHelper.isAnnotationType) Produces(javax.enterprise.inject.Produces) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) LoggerFactory(org.slf4j.LoggerFactory) ProcessBean(javax.enterprise.inject.spi.ProcessBean) Endpoint(org.apache.camel.Endpoint) PropertyInject(org.apache.camel.PropertyInject) EventObject(java.util.EventObject) ProcessProducerField(javax.enterprise.inject.spi.ProcessProducerField) ProcessObserverMethod(javax.enterprise.inject.spi.ProcessObserverMethod) Map(java.util.Map) Observes(javax.enterprise.event.Observes) ProducerTemplate(org.apache.camel.ProducerTemplate) ANY(org.apache.camel.cdi.AnyLiteral.ANY) Method(java.lang.reflect.Method) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Collectors.toSet(java.util.stream.Collectors.toSet) CamelContextAware(org.apache.camel.CamelContextAware) Annotated(javax.enterprise.inject.spi.Annotated) Extension(javax.enterprise.inject.spi.Extension) CdiSpiHelper.hasType(org.apache.camel.cdi.CdiSpiHelper.hasType) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) BeanManagerHelper.getReference(org.apache.camel.cdi.BeanManagerHelper.getReference) Set(java.util.Set) ResourceHelper.getResource(org.apache.camel.cdi.ResourceHelper.getResource) CdiSpiHelper.getRawType(org.apache.camel.cdi.CdiSpiHelper.getRawType) ProcessProducerMethod(javax.enterprise.inject.spi.ProcessProducerMethod) BeanInject(org.apache.camel.BeanInject) Stream(java.util.stream.Stream) Type(java.lang.reflect.Type) CdiEventEndpoint.eventEndpointUri(org.apache.camel.cdi.CdiEventEndpoint.eventEndpointUri) Annotation(java.lang.annotation.Annotation) ConsumerTemplate(org.apache.camel.ConsumerTemplate) EXCLUDED(org.apache.camel.cdi.Excluded.EXCLUDED) Bean(javax.enterprise.inject.spi.Bean) RoutesBuilder(org.apache.camel.RoutesBuilder) EndpointInject(org.apache.camel.EndpointInject) Component(org.apache.camel.Component) AbstractExchangeEvent(org.apache.camel.management.event.AbstractExchangeEvent) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Produce(org.apache.camel.Produce) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) Collections.newSetFromMap(java.util.Collections.newSetFromMap) APPLICATION_SCOPED(org.apache.camel.cdi.ApplicationScopedLiteral.APPLICATION_SCOPED) BeanManagerHelper.getReferencesByType(org.apache.camel.cdi.BeanManagerHelper.getReferencesByType) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) Stream.concat(java.util.stream.Stream.concat) Named(javax.inject.Named) DEFAULT(org.apache.camel.cdi.DefaultLiteral.DEFAULT) ServiceStatus(org.apache.camel.ServiceStatus) CamelContext(org.apache.camel.CamelContext) Default(javax.enterprise.inject.Default) Logger(org.slf4j.Logger) CdiSpiHelper.getQualifiers(org.apache.camel.cdi.CdiSpiHelper.getQualifiers) Consume(org.apache.camel.Consume) Predicate.isEqual(java.util.function.Predicate.isEqual) STARTUP(org.apache.camel.cdi.Startup.Literal.STARTUP) InjectionException(javax.enterprise.inject.InjectionException) Converter(org.apache.camel.Converter) ProcessInjectionTarget(javax.enterprise.inject.spi.ProcessInjectionTarget) TypeConverter(org.apache.camel.TypeConverter) ParameterizedType(java.lang.reflect.ParameterizedType) RouteContainer(org.apache.camel.model.RouteContainer) CdiSpiHelper.hasAnnotation(org.apache.camel.cdi.CdiSpiHelper.hasAnnotation) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManager(javax.enterprise.inject.spi.BeanManager) ParameterizedType(java.lang.reflect.ParameterizedType) CdiSpiHelper.isAnnotationType(org.apache.camel.cdi.CdiSpiHelper.isAnnotationType) CdiSpiHelper.hasType(org.apache.camel.cdi.CdiSpiHelper.hasType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) CdiSpiHelper.getRawType(org.apache.camel.cdi.CdiSpiHelper.getRawType) Type(java.lang.reflect.Type) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) BeanManagerHelper.getReferencesByType(org.apache.camel.cdi.BeanManagerHelper.getReferencesByType) ParameterizedType(java.lang.reflect.ParameterizedType)

Example 2 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project camel by apache.

the class Main method warnIfNoCamelFound.

private void warnIfNoCamelFound() {
    BeanManager manager = cdiContainer.getBeanManager();
    Set<Bean<?>> contexts = manager.getBeans(CamelContext.class, ANY);
    // Warn if there is no CDI Camel contexts
    if (contexts.isEmpty()) {
        LOG.warn("Camel CDI main has started with no Camel context!");
    }
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean)

Example 3 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project Activiti by Activiti.

the class CdiResolver method getWrappedResolver.

protected javax.el.ELResolver getWrappedResolver() {
    BeanManager beanManager = getBeanManager();
    javax.el.ELResolver resolver = beanManager.getELResolver();
    return resolver;
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager) ELResolver(org.activiti.engine.impl.javax.el.ELResolver)

Example 4 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project aries by apache.

the class CdiContainerTests method testGetBeanFromCdiContainerService.

public void testGetBeanFromCdiContainerService() throws Exception {
    BeanManager beanManager = cdiContainer.getBeanManager();
    assertNotNull(beanManager);
    assertPojoExists(beanManager);
}
Also used : BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 5 with BeanManager

use of javax.enterprise.inject.spi.BeanManager in project aries by apache.

the class CdiContainerTests method testGetBeanManagerFromCDI.

public void testGetBeanManagerFromCDI() throws Exception {
    Thread currentThread = Thread.currentThread();
    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
    try {
        BundleWiring bundleWiring = cdiBundle.adapt(BundleWiring.class);
        currentThread.setContextClassLoader(bundleWiring.getClassLoader());
        BeanManager beanManager = CDI.current().getBeanManager();
        assertNotNull(beanManager);
        assertPojoExists(beanManager);
    } finally {
        currentThread.setContextClassLoader(contextClassLoader);
    }
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

BeanManager (javax.enterprise.inject.spi.BeanManager)61 Bean (javax.enterprise.inject.spi.Bean)27 Test (org.junit.Test)12 CdiContainer (org.apache.deltaspike.cdise.api.CdiContainer)6 ArrayList (java.util.ArrayList)5 CarRepair (org.apache.deltaspike.cdise.tck.beans.CarRepair)5 InitialContext (javax.naming.InitialContext)4 NamingException (javax.naming.NamingException)4 ValidatorFactory (javax.validation.ValidatorFactory)4 ContextControl (org.apache.deltaspike.cdise.api.ContextControl)4 ServiceName (org.jboss.msc.service.ServiceName)4 CreationalContext (javax.enterprise.context.spi.CreationalContext)3 TransactionManager (javax.transaction.TransactionManager)3 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)3 BeanService (org.apache.aries.cdi.test.interfaces.BeanService)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 IOException (java.io.IOException)2 Annotation (java.lang.annotation.Annotation)2 Type (java.lang.reflect.Type)2 MalformedURLException (java.net.MalformedURLException)2