javax.enterprise.inject.spi.AfterDeploymentValidation Java Examples
The following examples show how to use
javax.enterprise.inject.spi.AfterDeploymentValidation.
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: ConfigurationExtension.java From deltaspike with Apache License 2.0 | 6 votes |
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 #2
Source File: SecurityExtension.java From component-runtime with Apache License 2.0 | 6 votes |
void bindSecurityHandlers(@Observes final AfterDeploymentValidation afterDeploymentValidation, final BeanManager beanManager) { final ComponentServerConfiguration configuration = ComponentServerConfiguration.class .cast(beanManager .getReference(beanManager.resolve(beanManager.getBeans(ComponentServerConfiguration.class)), ComponentServerConfiguration.class, beanManager.createCreationalContext(null))); final String connectionHandler = configuration.getSecurityConnectionHandler(); onConnectionMtd = ofNullable(onConnectionObservers.get(connectionHandler)) .orElseThrow(() -> new IllegalArgumentException("No handler '" + connectionHandler + "'")); final String commandHandler = configuration.getSecurityCommandHandler(); onCommandMtd = ofNullable(onCommandObservers.get(commandHandler)) .orElseThrow(() -> new IllegalArgumentException("No handler '" + commandHandler + "'")); // no more needed onConnectionObservers.clear(); onCommandObservers.clear(); log .info("Security configured with connection handler '{}' and command handler '{}'", connectionHandler, commandHandler); }
Example #3
Source File: HealthExtension.java From thorntail with Apache License 2.0 | 6 votes |
public void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) { try { if (delegate != null) { Unmanaged<SmallRyeHealthReporter> unmanagedHealthCheck = new Unmanaged<>(beanManager, SmallRyeHealthReporter.class); reporterInstance = unmanagedHealthCheck.newInstance(); reporter = reporterInstance.produce().inject().postConstruct().get(); monitor.registerHealthReporter(reporter); // THORN-2195: Use the correct TCCL when health checks are obtained // In WildFly, the TCCL should always be set to the top-level deployment CL during extension notification monitor.registerContextClassLoader(Thread.currentThread().getContextClassLoader()); log.info(">> Added health reporter bean " + reporter); delegate = null; } } catch (Exception e) { throw new RuntimeException("Failed to register health reporter bean", e); } }
Example #4
Source File: BeanManagerProvider.java From deltaspike with Apache License 2.0 | 6 votes |
/** * By cleaning the final BeanManager map after the deployment gets validated, premature loading of information from * JNDI is prevented in cases where the container might not be fully setup yet. * * This might happen if the BeanManagerProvider is used in an extension during CDI bootstrap. This should be * generally avoided. Instead, an injected BeanManager should be used in Extensions and propagated using setters. * * In EARs with multiple webapps, each WAR might get a different Extension. This depends on the container used. */ public void cleanupFinalBeanManagers(@Observes AfterDeploymentValidation adv) { // CDI#current delegation enabled, skip everything if (CDI_CURRENT_METHOD != null && CDI_CURRENT_BEAN_MANAGER_METHOD != null && resolveBeanManagerViaStaticHelper() != null) { return; } for (BeanManagerInfo bmi : bmpSingleton.bmInfos.values()) { bmi.finalBm = null; bmi.booted = true; /*possible issue with >weld< based servers: if #getBeanManager gets called in a custom AfterDeploymentValidation observer >after< this observer, the wrong bean-manager might get stored (not deterministic due to the unspecified order of observers). finally a bean-manager for a single bda will be stored and returned (which isn't the bm exposed via jndi).*/ } }
Example #5
Source File: MetricsExtension.java From metrics-cdi with Apache License 2.0 | 6 votes |
private void configuration(@Observes AfterDeploymentValidation adv, BeanManager manager) { // Fire configuration event manager.fireEvent(configuration); configuration.unmodifiable(); // Produce and register custom metrics MetricRegistry registry = getReference(manager, MetricRegistry.class); MetricName metricName = getReference(manager, MetricName.class); for (Map.Entry<Bean<?>, AnnotatedMember<?>> bean : metrics.entrySet()) { // TODO: add MetricSet metrics into the metric registry if (bean.getKey().getTypes().contains(MetricSet.class) // skip non @Default beans || !bean.getKey().getQualifiers().contains(DEFAULT) // skip producer methods with injection point || hasInjectionPoints(bean.getValue())) continue; registry.register(metricName.of(bean.getValue()), (Metric) getReference(manager, bean.getValue().getBaseType(), bean.getKey())); } // Let's clear the collected metric producers metrics.clear(); }
Example #6
Source File: JtaExtension.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
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 #7
Source File: PortletCDIExtension.java From portals-pluto with Apache License 2.0 | 5 votes |
/** * After the bean container has validated the deployment from its point of view, * do some checking from the portlet point of view. Activate the portlet deployment * by passing in a bean manager in order to create the required portlet bean instances. * * @param adv * @param bm * @throws InvalidAnnotationException */ void afterDeploymentValidation(@Observes AfterDeploymentValidation adv, BeanManager bm) throws InvalidAnnotationException { // Done processing the annotations, so put the resulting configuration in an // application scoped bean to pass it to the servlet LOG.trace("Now attempting to get the AnnotatedConfigBean ..."); Set<Bean<?>> beans = bm.getBeans(AnnotatedConfigBean.class); @SuppressWarnings("unchecked") Bean<AnnotatedConfigBean> bean = (Bean<AnnotatedConfigBean>) bm.resolve(beans); if (bean != null) { LOG.trace("Got AnnotatedConfigBean bean: " + bean.getBeanClass().getCanonicalName()); try { CreationalContext<AnnotatedConfigBean> cc = bm.createCreationalContext(bean); acb = (AnnotatedConfigBean) bm.getReference(bean, AnnotatedConfigBean.class, cc); LOG.trace("Got AnnotatedConfigBean instance."); acb.setMethodStore(ams); acb.setSummary(summary); acb.setRedirectScopedConfig(par.getRedirectScopedConfig()); acb.setStateScopedConfig(par.getStateScopedConfig()); acb.setSessionScopedConfig(par.getSessionScopedConfig()); } catch (Exception e) { StringBuilder txt = new StringBuilder(128); txt.append("Exception getting AnnotatedConfigBean bean instance: "); txt.append(e.toString()); LOG.warn(txt.toString()); } } else { LOG.warn("AnnotatedConfigBean bean was null."); } LOG.info("Portlet CDI Extension complete. Config bean: " + acb); }
Example #8
Source File: DeltaSpikeContextExtension.java From deltaspike with Apache License 2.0 | 5 votes |
/** * We can only initialize our contexts in AfterDeploymentValidation because * getBeans must not be invoked earlier than this phase to reduce randomness * caused by Beans no being fully registered yet. */ public void initializeDeltaSpikeContexts(@Observes AfterDeploymentValidation adv, BeanManager beanManager) { if (!isActivated) { return; } WindowBeanHolder windowBeanHolder = BeanProvider.getContextualReference(beanManager, WindowBeanHolder.class, false); WindowIdHolder windowIdHolder = BeanProvider.getContextualReference(beanManager, WindowIdHolder.class, false); windowContext.init(windowBeanHolder, windowIdHolder); ConversationBeanHolder conversationBeanHolder = BeanProvider.getContextualReference(beanManager, ConversationBeanHolder.class, false); conversationContext.init(conversationBeanHolder); ViewAccessBeanHolder viewAccessBeanHolder = BeanProvider.getContextualReference(beanManager, ViewAccessBeanHolder.class, false); ViewAccessBeanAccessHistory viewAccessBeanAccessHistory = BeanProvider.getContextualReference(beanManager, ViewAccessBeanAccessHistory.class, false); ViewAccessViewHistory viewAccessViewHistory = BeanProvider.getContextualReference(beanManager, ViewAccessViewHistory.class, false); viewAccessScopedContext.init(viewAccessBeanHolder, viewAccessBeanAccessHistory, viewAccessViewHistory); }
Example #9
Source File: ExceptionControlExtension.java From deltaspike with Apache License 2.0 | 5 votes |
/** * 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); } } } } }
Example #10
Source File: ViewConfigExtension.java From deltaspike with Apache License 2.0 | 5 votes |
@SuppressWarnings("UnusedDeclaration") public void buildViewConfig(@Observes AfterDeploymentValidation adv) { if (!isActivated) { return; } //needed to transform the metadata-tree during the bootstrapping process transformMetaDataTree(); this.transformed = true; }
Example #11
Source File: BatchCDIInjectionExtension.java From incubator-batchee with Apache License 2.0 | 5 votes |
public void cleanupFinalBeanManagers(final @Observes AfterDeploymentValidation adv) { if (!CDI_1_1_AVAILABLE) { for (final BeanManagerInfo bmi : bmpSingleton.bmInfos.values()) { bmi.finalBm = null; } } }
Example #12
Source File: ConfigExtension.java From smallrye-config with Apache License 2.0 | 5 votes |
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 #13
Source File: EagerExtension.java From hawkular-metrics with Apache License 2.0 | 5 votes |
public void load(@Observes AfterDeploymentValidation event, BeanManager beanManager) { for (Bean<?> bean : eagerBeansList) { // note: toString() is important to instantiate the bean // // I found through testing that managed beans will get instantiated without the toString call; however, // @PostConstruct methods in producer beans do not get called without the toString call. I have also // noticed that with the toString call managed beans are instantiated twice. We may need modify this // method to ensure we do not have the two constructor calls. It is not an immediate concern though since // this is being introduced specifically for https://issues.jboss.org/browse/HWKMETRICS-23. beanManager.getReference(bean, bean.getBeanClass(), beanManager.createCreationalContext(bean)).toString(); } }
Example #14
Source File: EagerExtension.java From hawkular-apm with Apache License 2.0 | 5 votes |
public void load(@Observes AfterDeploymentValidation event, BeanManager beanManager) { for (Bean<?> bean : eagerBeansList) { // note: toString() is important to instantiate the bean // // I found through testing that managed beans will get instantiated without the toString call; however, // @PostConstruct methods in producer beans do not get called without the toString call. I have also // noticed that with the toString call managed beans are instantiated twice. We may need modify this // method to ensure we do not have the two constructor calls. It is not an immediate concern though since // this is being introduced specifically for https://issues.jboss.org/browse/HWKMETRICS-23. beanManager.getReference(bean, bean.getBeanClass(), beanManager.createCreationalContext(bean)).toString(); } }
Example #15
Source File: FlowableExtension.java From flowable-engine with Apache License 2.0 | 5 votes |
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 #16
Source File: ComponentConfigurationLoader.java From component-runtime with Apache License 2.0 | 5 votes |
void doInit(@Observes final AfterDeploymentValidation afterDeploymentValidation, final Config config, final Meecrowave.Builder builder) { StreamSupport .stream(config.getConfigSources().spliterator(), false) .filter(ComponentConfigurationLoader.class::isInstance) .map(ComponentConfigurationLoader.class::cast) .forEach(it -> it.doInit(builder)); }
Example #17
Source File: ActivitiExtension.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
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 #18
Source File: RestClientExtension.java From cxf with Apache License 2.0 | 4 votes |
public void registerErrors(@Observes AfterDeploymentValidation afterDeploymentValidation) { errors.forEach(afterDeploymentValidation::addDeploymentProblem); }
Example #19
Source File: StartWebServerExtension.java From hammock with Apache License 2.0 | 4 votes |
public void startWebTier(@Observes AfterDeploymentValidation adv) { StartWebServer startWebServer = CDI.current().select(StartWebServer.class).get(); startWebServer.start(); }
Example #20
Source File: WebappMultipleModuleTest.java From tomee with Apache License 2.0 | 4 votes |
private void end(@Observes final AfterDeploymentValidation ignored , final BeanManager manager) { final Bean<?> bean = manager.resolve(manager.getBeans(Marker.class)); assertNotNull(manager.getReference(bean, Marker.class, manager.createCreationalContext(bean))); CALLED.set(true); }
Example #21
Source File: JAXWSCdiExtension.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
public void load(@Observes final AfterDeploymentValidation afterDeploymentValidation, final BeanManager beanManager) { impl.load(afterDeploymentValidation, beanManager); }
Example #22
Source File: JpaExtension.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
void initBeans(@Observes final AfterDeploymentValidation adv, final BeanManager bm) { if (entityManagerBeans.isEmpty()) { return; } // only not portable part is this config read, could be optional final ServletContext sc = ServletContext.class.cast(bm.getReference(bm.resolve(bm.getBeans(ServletContext.class)), ServletContext.class, bm.createCreationalContext(null))); final Meecrowave.Builder config = Meecrowave.Builder.class.cast(sc.getAttribute("meecrowave.configuration")); final Map<String, String> props = new HashMap<>(); if (config != null) { ofNullable(config.getProperties()).ifPresent(p -> p.stringPropertyNames().stream() .filter(k -> k.startsWith("jpa.property.")) .forEach(k -> props.put(k.substring("jpa.property.".length()), p.getProperty(k)))); } final Map<String, PersistenceUnitInfo> infoIndex = unitBuilders.stream() .map(bean -> { final CreationalContext<?> cc = bm.createCreationalContext(null); try { final Bean<?> resolvedBean = bm.resolve(bm.getBeans( PersistenceUnitInfoBuilder.class, bean.getQualifiers().toArray(new Annotation[bean.getQualifiers().size()]))); final PersistenceUnitInfoBuilder builder = PersistenceUnitInfoBuilder.class.cast( bm.getReference(resolvedBean, PersistenceUnitInfoBuilder.class, cc)); if (builder.getManagedClasses().isEmpty()) { builder.setManagedClassNames(jpaClasses).setExcludeUnlistedClasses(true); } props.forEach(builder::addProperty); return builder.toInfo(); } finally { cc.release(); } }).collect(toMap(PersistenceUnitInfo::getPersistenceUnitName, identity())); entityManagerBeans.forEach((k, e) -> { PersistenceUnitInfo info = infoIndex.get(k.unitName); if (info == null) { info = tryCreateDefaultPersistenceUnit(k.unitName, bm, props); } if (info == null) { // not valid adv.addDeploymentProblem(new IllegalArgumentException("Didn't find any PersistenceUnitInfoBuilder for " + k)); } else { e.init(info, bm); } }); }
Example #23
Source File: VertxExtension.java From weld-vertx with Apache License 2.0 | 4 votes |
public void registerConsumersAfterDeploymentValidation(@Observes AfterDeploymentValidation afterDeploymentValidation, BeanManager beanManager) { if (vertx != null) { registerConsumers(vertx, BeanManagerProxy.unwrap(beanManager).event()); } asyncReferenceQualifiers.clear(); }
Example #24
Source File: MessageBundleExtension.java From deltaspike with Apache License 2.0 | 4 votes |
@SuppressWarnings("UnusedDeclaration") protected void cleanup(@Observes AfterDeploymentValidation afterDeploymentValidation) { messageBundleTypes.clear(); }
Example #25
Source File: ExcludeExtension.java From deltaspike with Apache License 2.0 | 4 votes |
/** * triggers initialization in any case * @param afterDeploymentValidation observed event */ @SuppressWarnings("UnusedDeclaration") protected void initProjectStage(@Observes AfterDeploymentValidation afterDeploymentValidation) { ProjectStageProducer.getInstance(); }
Example #26
Source File: RouteExtension.java From weld-vertx with Apache License 2.0 | 4 votes |
void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager beanManager) { this.beanManager = beanManager; }