Java Code Examples for javax.enterprise.inject.spi.AfterDeploymentValidation#addDeploymentProblem()

The following examples show how to use javax.enterprise.inject.spi.AfterDeploymentValidation#addDeploymentProblem() . 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: JtaExtension.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
void init(@Observes final AfterDeploymentValidation afterDeploymentValidation, final BeanManager bm) {
    if (!hasRegistry && hasManager) {
        afterDeploymentValidation.addDeploymentProblem(new IllegalStateException("You should produce a TransactionManager and TransactionSynchronizationRegistry"));
        return;
    }
    final TransactionManager manager = TransactionManager.class.cast(
            bm.getReference(bm.resolve(bm.getBeans(TransactionManager.class)), TransactionManager.class, bm.createCreationalContext(null)));
    final TransactionSynchronizationRegistry registry = TransactionSynchronizationRegistry.class.isInstance(manager) ?
            TransactionSynchronizationRegistry.class.cast(manager) :
            TransactionSynchronizationRegistry.class.cast(bm.getReference(bm.resolve(bm.getBeans(TransactionSynchronizationRegistry.class)),
                    TransactionSynchronizationRegistry.class, bm.createCreationalContext(null)));
    context.init(manager, registry);

    try {
        final Class<?> builder = Thread.currentThread().getContextClassLoader().loadClass("org.apache.meecrowave.Meecrowave$Builder");
        final JtaConfig ext = JtaConfig.class.cast(builder.getMethod("getExtension", Class.class).invoke(
                bm.getReference(bm.resolve(bm.getBeans(builder)), builder, bm.createCreationalContext(null)), JtaConfig.class));
        config.handleExceptionOnlyForClient = ext.handleExceptionOnlyForClient;
    } catch (final Exception e) {
        config.handleExceptionOnlyForClient = Boolean.getBoolean("meecrowave.jta.handleExceptionOnlyForClient");
    }
}
 
Example 2
Source File: ConfigurationExtension.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
protected void processConfigurationValidation(AfterDeploymentValidation adv)
{
    for (ConfigValidator configValidator : ServiceUtils.loadServiceImplementations(ConfigValidator.class))
    {
        Set<String> violations = configValidator.processValidation();

        if (violations == null)
        {
            continue;
        }

        for (String violation : violations)
        {
            adv.addDeploymentProblem(new IllegalStateException(violation));
        }
    }
}
 
Example 3
Source File: ConfigExtension.java    From smallrye-config with Apache License 2.0 5 votes vote down vote up
protected void validate(@Observes AfterDeploymentValidation adv) {
    Config config = ConfigProvider.getConfig(getContextClassLoader());
    Set<String> configNames = StreamSupport.stream(config.getPropertyNames().spliterator(), false).collect(toSet());
    for (InjectionPoint injectionPoint : injectionPoints) {
        Type type = injectionPoint.getType();

        // We don't validate the Optional / Provider / Supplier / ConfigValue for defaultValue.
        if (type instanceof Class && ConfigValue.class.isAssignableFrom((Class<?>) type)
                || type instanceof Class && OptionalInt.class.isAssignableFrom((Class<?>) type)
                || type instanceof Class && OptionalLong.class.isAssignableFrom((Class<?>) type)
                || type instanceof Class && OptionalDouble.class.isAssignableFrom((Class<?>) type)
                || type instanceof ParameterizedType
                        && (Optional.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType())
                                || Provider.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType())
                                || Supplier.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType()))) {
            return;
        }

        ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
        String name = ConfigProducerUtil.getConfigKey(injectionPoint, configProperty);

        // Check if the name is part of the properties first. Since properties can be a subset, then search for the actual property for a value.
        if (!configNames.contains(name) && ConfigProducerUtil.getRawValue(name, (SmallRyeConfig) config) == null) {
            if (configProperty.defaultValue().equals(ConfigProperty.UNCONFIGURED_VALUE)) {
                adv.addDeploymentProblem(InjectionMessages.msg.noConfigValue(name));
            }
        }

        try {
            // Check if there is a Converter registed for the injected type
            Converter<?> resolvedConverter = ConfigProducerUtil.resolveConverter(injectionPoint, (SmallRyeConfig) config);

            // Check if the value can be converted. The TCK checks this, but this requires to get the value eagerly.
            // This should not be required!
            SecretKeys.doUnlocked(() -> ((SmallRyeConfig) config).getOptionalValue(name, resolvedConverter));
        } catch (IllegalArgumentException e) {
            adv.addDeploymentProblem(e);
        }
    }
}
 
Example 4
Source File: ActivitiExtension.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager beanManager) {
  try {
    logger.info("Initializing activiti-cdi.");
    // initialize the process engine
    ProcessEngine processEngine = lookupProcessEngine(beanManager);
    // deploy the processes if engine was set up correctly
    deployProcesses(processEngine);
  } catch (Exception e) {
    // interpret engine initialization problems as definition errors
    event.addDeploymentProblem(e);
  }
}
 
Example 5
Source File: FlowableExtension.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager beanManager) {
    try {
        LOGGER.info("Initializing flowable-cdi.");
        // initialize the process engine
        ProcessEngine processEngine = lookupProcessEngine(beanManager);
        // deploy the processes if engine was set up correctly
        deployProcesses(processEngine);
    } catch (Exception e) {
        // interpret engine initialization problems as definition errors
        event.addDeploymentProblem(e);
    }
}
 
Example 6
Source File: ExceptionControlExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies all injection points for every handler are valid.
 *
 * @param afterDeploymentValidation Lifecycle event
 * @param bm  BeanManager instance
 */
@SuppressWarnings("UnusedDeclaration")
public void verifyInjectionPoints(@Observes final AfterDeploymentValidation afterDeploymentValidation,
                                  final BeanManager bm)
{
    if (!isActivated)
    {
        return;
    }

    for (Map.Entry<Type, Collection<HandlerMethod<? extends Throwable>>> entry : allHandlers.entrySet())
    {
        for (HandlerMethod<? extends Throwable> handler : entry.getValue())
        {
            for (InjectionPoint ip : ((HandlerMethodImpl<? extends Throwable>) handler).getInjectionPoints(bm))
            {
                try
                {
                    bm.validate(ip);
                }
                catch (InjectionException e)
                {
                    afterDeploymentValidation.addDeploymentProblem(e);
                }
            }
        }
    }
}