javax.enterprise.inject.spi.BeforeBeanDiscovery Java Examples

The following examples show how to use javax.enterprise.inject.spi.BeforeBeanDiscovery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InterDynExtension.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager)
{
    if (!ClassDeactivationUtils.isActivated(getClass()))
    {
        return;
    }

    enabled = CoreBaseConfig.InterDynCustomization.INTERDYN_ENABLED.getValue();

    if (enabled)
    {
        logger.info("Starting with deltaspike.interdyn instrumentation");
        init();
    }
}
 
Example #2
Source File: ViewScopedExtension.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
/**
 * javax.faces.bean.ViewScoped is no CDI Scope.
 * We need to add it programmatically to CDI.
 */
public void addViewScoped(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());

    if (isActivated)
    {
        //this extension is only needed if the cdi-based view-scope handling isn't delegated to jsf 2.2+
        isActivated = !JsfUtils.isViewScopeDelegationEnabled();
    }

    if (!isActivated)
    {
        return;
    }

    beforeBeanDiscovery.addScope(ViewScoped.class, true, true);
}
 
Example #3
Source File: SmallRyeJWTAuthCDIExtension.java    From smallrye-jwt with Apache License 2.0 6 votes vote down vote up
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager beanManager) {
    CDILogging.log.beforeBeanDiscovery(beanManager);

    // TODO: Do not add CDI beans unless @LoginConfig (or other trigger) is configured
    addAnnotatedType(event, beanManager, ClaimValueProducer.class);
    addAnnotatedType(event, beanManager, CommonJwtProducer.class);
    addAnnotatedType(event, beanManager, DefaultJWTParser.class);
    addAnnotatedType(event, beanManager, JsonValueProducer.class);
    addAnnotatedType(event, beanManager, JWTAuthContextInfoProvider.class);
    addAnnotatedType(event, beanManager, JWTAuthenticationFilter.class);
    addAnnotatedType(event, beanManager, PrincipalProducer.class);
    addAnnotatedType(event, beanManager, RawClaimTypeProducer.class);
    if (registerOptionalClaimTypeProducer()) {
        addAnnotatedType(event, beanManager, OptionalClaimTypeProducer.class);
    }

    if (isEESecurityAvailable()) {
        addAnnotatedType(event, beanManager, JWTHttpAuthenticationMechanism.class);
        CDILogging.log.jwtHttpAuthenticationMechanismRegistered();
    } else {
        // EE Security is not available, register the JAX-RS authentication filter.
        CDILogging.log.jwtHttpAuthenticationMechanismNotRegistered();
    }
}
 
Example #4
Source File: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private void addInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager manager) {
    SmallRyeMetricsLogging.log.logSmallRyeMetricsVersion(getImplementationVersion().orElse("unknown"));

    String extensionName = MetricCdiInjectionExtension.class.getName();

    // It seems that fraction deployment module cannot be picked up as a CDI bean archive - see also SWARM-1725
    for (Class clazz : new Class[] {
            MetricProducer.class,
            MetricNameFactory.class,
            GaugeRegistrationInterceptor.class,
            MetricRegistries.class,

            MeteredInterceptor.class,
            CountedInterceptor.class,
            ConcurrentGaugeInterceptor.class,
            TimedInterceptor.class,
            SimplyTimedInterceptor.class,
            MetricsRequestHandler.class
    }) {
        bbd.addAnnotatedType(manager.createAnnotatedType(clazz), extensionName + "_" + clazz.getName());
    }
}
 
Example #5
Source File: FaultToleranceExtension.java    From smallrye-fault-tolerance with Apache License 2.0 6 votes vote down vote up
void registerInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
    LOGGER.info("MicroProfile: Fault Tolerance activated");
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(CircuitBreaker.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Retry.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Timeout.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Asynchronous.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Fallback.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Bulkhead.class)));

    // It seems that fraction deployment module cannot be picked up as a CDI bean archive - see also SWARM-1725
    bbd.addAnnotatedType(bm.createAnnotatedType(FaultToleranceInterceptor.class),
            FaultToleranceInterceptor.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(DefaultFallbackHandlerProvider.class),
            DefaultFallbackHandlerProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(ExecutorProvider.class),
            ExecutorProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(DefaultFaultToleranceOperationProvider.class),
            DefaultFaultToleranceOperationProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(MetricsCollectorFactory.class), MetricsCollectorFactory.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(StrategyCache.class), StrategyCache.class.getName());
}
 
Example #6
Source File: MPJWTCDIExtension.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void observeBeforeBeanDiscovery(@Observes final BeforeBeanDiscovery bbd, final BeanManager beanManager) {
    bbd.addAnnotatedType(beanManager.createAnnotatedType(JWTAuthConfigurationProperties.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(JsonbProducer.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(MPJWTFilter.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(MPJWTInitializer.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(org.apache.tomee.microprofile.jwt.bval.BValInterceptor.class));
}
 
Example #7
Source File: CdiHelper.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
static <T extends Annotation> void declareAsInterceptorBinding(Class<T> annotation, BeanManager manager, BeforeBeanDiscovery bbd) {
    AnnotatedType<T> annotated = manager.createAnnotatedType(annotation);
    Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
    for (AnnotatedMethod<? super T> method : annotated.getMethods())
        methods.add(new AnnotatedMethodDecorator<>(method, NON_BINDING));

    bbd.addInterceptorBinding(new AnnotatedTypeDecorator<>(annotated, INTERCEPTOR_BINDING, methods));
}
 
Example #8
Source File: MeecrowaveExtension.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
void addBeansFromJava(@Observes final BeforeBeanDiscovery bbd, final BeanManager bm) {
    if (Cxfs.IS_PRESENT) {
        bbd.addInterceptorBinding(JAXRSFieldInjectionInterceptor.Binding.class);

        Stream.of(MeecrowaveBus.class, JAXRSFieldInjectionInterceptor.class)
              .forEach(type -> bbd.addAnnotatedType(bm.createAnnotatedType(type)));
    }
}
 
Example #9
Source File: JtaExtension.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
void register(@Observes final BeforeBeanDiscovery beforeBeanDiscovery, final BeanManager beanManager) {
    Stream.of(
            MandatoryInterceptor.class, NeverInterceptor.class,
            NotSupportedInterceptor.class, RequiredInterceptor.class,
            RequiredNewInterceptor.class, SupportsInterceptor.class)
            .forEach(c -> beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(c)));
}
 
Example #10
Source File: PersistenceUnitDescriptorInitExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery before)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());

    if (!isActivated)
    {
        return;
    }

    PersistenceUnitDescriptorProvider.getInstance().init();
}
 
Example #11
Source File: TomEESecurityExtension.java    From tomee with Apache License 2.0 5 votes vote down vote up
void observeBeforeBeanDiscovery(@Observes final BeforeBeanDiscovery beforeBeanDiscovery,
                                final BeanManager beanManager) {
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(DefaultAuthenticationMechanism.class));
    beforeBeanDiscovery.addAnnotatedType(
            beanManager.createAnnotatedType(TomEESecurityServletAuthenticationMechanismMapper.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(TomEEDefaultIdentityStore.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(TomEEIdentityStoreHandler.class));

    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(AutoApplySessionInterceptor.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(RememberMeInterceptor.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(LoginToContinueInterceptor.class));

    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(TomEESecurityContext.class));
}
 
Example #12
Source File: TomEEOpenAPIExtension.java    From tomee with Apache License 2.0 5 votes vote down vote up
void init(@Observes final BeforeBeanDiscovery beforeBeanDiscovery) {
    config = GeronimoOpenAPIConfig.create();
    processor = new AnnotationProcessor(config, loadNamingStrategy(config), null);
    skipScan = Boolean.parseBoolean(config.read(OASConfig.SCAN_DISABLE, "false"));
    classes = getConfigCollection(OASConfig.SCAN_CLASSES);
    packages = getConfigCollection(OASConfig.SCAN_PACKAGES);
    excludePackages = getConfigCollection(OASConfig.SCAN_EXCLUDE_PACKAGES);
    excludeClasses = getConfigCollection(OASConfig.SCAN_EXCLUDE_CLASSES);
    try {
        Yaml.getObjectMapper();
        jacksonIsPresent = true;
    } catch (final Error | RuntimeException e) {
        // no-op
    }
}
 
Example #13
Source File: MPJWTExtension.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * Register the MPJWTProducer JsonWebToken producer bean
 *
 * @param bbd         before discovery event
 * @param beanManager cdi bean manager
 */
public void observeBeforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) {
    log.debugf("MPJWTExtension(), adding producers");
    String extensionName = MPJWTExtension.class.getName();
    for (Class<?> clazz : new Class<?>[] {
            JWTAuthContextInfoProvider.class,
            CommonJwtProducer.class,
            PrincipalProducer.class,
            RawClaimTypeProducer.class,
            ClaimValueProducer.class,
            JsonValueProducer.class,
    }) {
        bbd.addAnnotatedType(beanManager.createAnnotatedType(clazz), extensionName + "_" + clazz.getName());
    }
}
 
Example #14
Source File: OpenTracingCDIExtension.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public void observeBeforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager manager) {
  logger.info("Registering Tracer CDI producer");
  String extensionName = OpenTracingCDIExtension.class.getName();
  for (Class<?> clazz : new Class<?>[] {
          TracerProducer.class,
          OpenTracingInterceptor.class,
  }) {
    bbd.addAnnotatedType(manager.createAnnotatedType(clazz), extensionName + "_" + clazz.getName());
  }
}
 
Example #15
Source File: GlobalInterceptorExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager)
{
    if (!ClassDeactivationUtils.isActivated(getClass()))
    {
        return;
    }

    this.beanManager = beanManager;
    int priorityValue = CoreBaseConfig.InterceptorCustomization.PRIORITY;
    priorityAnnotationInstance = AnnotationInstanceUtils.getPriorityAnnotationInstance(priorityValue);
}
 
Example #16
Source File: CdiExtension.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void register(@Observes BeforeBeanDiscovery beforeBean, BeanManager beanManager) {
    if (!InMemoryIdentityStore.getCALLER_TO_CREDENTIALS().isEmpty()) {
        beforeBean.addAnnotatedType(
            beanManager.createAnnotatedType(InMemoryIdentityStore.class), 
            "Piranha " + InMemoryIdentityStore.class.getName());
    }
}
 
Example #17
Source File: SimpleCacheExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
void discoverInterceptorBindings(@Observes BeforeBeanDiscovery beforeBeanDiscoveryEvent)
{
    beforeBeanDiscoveryEvent.addInterceptorBinding(SimpleCache.class);
}
 
Example #18
Source File: MetricsExtension.java    From metrics-cdi with Apache License 2.0 4 votes vote down vote up
private void addInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager manager) {
    declareAsInterceptorBinding(Counted.class, manager, bbd);
    declareAsInterceptorBinding(ExceptionMetered.class, manager, bbd);
    declareAsInterceptorBinding(Metered.class, manager, bbd);
    declareAsInterceptorBinding(Timed.class, manager, bbd);
}
 
Example #19
Source File: TransactionContextExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());
}
 
Example #20
Source File: RepositoryExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery before)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());
}
 
Example #21
Source File: MockExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());
    mockFilters = ServiceUtils.loadServiceImplementations(MockFilter.class);
}
 
Example #22
Source File: ConverterAndValidatorProxyExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    this.isActivated = ClassDeactivationUtils.isActivated(getClass());
}
 
Example #23
Source File: SecurityExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());
    securityMetaDataStorage = new SecurityMetaDataStorage();
    ParentExtensionStorage.addExtension(this);
}
 
Example #24
Source File: MappedJsf2ScopeExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    this.isActivated = ClassDeactivationUtils.isActivated(getClass());
}
 
Example #25
Source File: ViewConfigExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    this.isActivated = ClassDeactivationUtils.isActivated(getClass());
}
 
Example #26
Source File: MockitoExtension.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void addMocks(@Observes final BeforeBeanDiscovery bbd) {
    // ensure it is init
    SystemInstance.get().getComponent(FallbackPropertyInjector.class);
}
 
Example #27
Source File: PartialBeanBindingExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    this.isActivated = ClassDeactivationUtils.isActivated(getClass());      
}
 
Example #28
Source File: SimpleCacheExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
void discoverInterceptorBindings(@Observes BeforeBeanDiscovery beforeBeanDiscoveryEvent)
{
    beforeBeanDiscoveryEvent.addInterceptorBinding(SimpleCache.class);
}
 
Example #29
Source File: MessageBundleExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());
    ParentExtensionStorage.addExtension(this);
}
 
Example #30
Source File: ResourceLoaderExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public void addResourceLoaders(final BeforeBeanDiscovery beforeBeanDiscovery, final BeanManager beanManager)
{
    beforeBeanDiscovery.addAnnotatedType(this.createAnnotatedType(ClasspathResourceProvider.class,beanManager));
    beforeBeanDiscovery.addAnnotatedType(this.createAnnotatedType(InjectableResourceProducer.class,beanManager));
    beforeBeanDiscovery.addAnnotatedType(this.createAnnotatedType(FileResourceProvider.class,beanManager));
}