Refine search
/** * Wraps all JAR-RS components by Jersey-specific injection target. * * @param pit process injection target. * @param <T> type of the processed injection target. */ public <T> void observeInjectionTarget(@Observes ProcessInjectionTarget<T> pit) { BasicInjectionTarget<T> it = (BasicInjectionTarget<T>) pit.getInjectionTarget(); JerseyInjectionTarget<T> jerseyInjectionTarget = new JerseyInjectionTarget<>(it, pit.getAnnotatedType().getJavaClass()); jerseyInjectionTargets.add(jerseyInjectionTarget); pit.setInjectionTarget(jerseyInjectionTarget); }
/** * Ignores the classes which are manually added using bindings (through {@link Application} class) and scanned by CDI. * The manual adding is privileged and the beans scanned using CDI are ignored. * <p> * TODO: The method counts with the condition that the all bindings are known before the CDI scanning has been started, * can be changed during the migration from CDI SE to JAVA EE environment. * * @param pat processed type. * @param <T> type of the scanned bean. */ public <T> void ignoreManuallyRegisteredComponents( @Observes @WithAnnotations({ Path.class, Provider.class }) ProcessAnnotatedType<T> pat) { for (Binding binding : bindings.getBindings()) { if (ClassBinding.class.isAssignableFrom(binding.getClass())) { ClassBinding<?> classBinding = (ClassBinding<?>) binding; if (pat.getAnnotatedType().getJavaClass() == classBinding.getService()) { pat.veto(); return; } } else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) { InstanceBinding<?> instanceBinding = (InstanceBinding<?>) binding; if (pat.getAnnotatedType().getJavaClass() == instanceBinding.getService().getClass()) { pat.veto(); return; } } } }
private boolean isBeanWithManagedBeanAnnotation(ProcessAnnotatedType processAnnotatedType) { Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass(); return beanClass.isAnnotationPresent(ManagedBean.class); }
private void recordAnnotatedGaugeSite(@Observes @WithAnnotations(Gauge.class) ProcessAnnotatedType<?> pat) { LOGGER.log(Level.FINE, () -> "### recordAnnoatedGaugeSite for class " + pat.getAnnotatedType().getJavaClass()); AnnotatedType<?> type = pat.getAnnotatedType(); LOGGER.log(Level.FINE, () -> "### Processing annotations for " + type.getJavaClass().getName()); // Register metrics based on annotations AnnotatedTypeConfigurator<?> configurator = pat.configureAnnotatedType(); Class<?> clazz = configurator.getAnnotated().getJavaClass(); // If abstract class, then handled by concrete subclasses if (Modifier.isAbstract(clazz.getModifiers())) { return; } // Process @Gauge methods keeping non-private declared on this class configurator.filterMethods(method -> method.getJavaMember().getDeclaringClass().equals(clazz) && !Modifier.isPrivate(method.getJavaMember().getModifiers()) && method.isAnnotationPresent(Gauge.class)) .forEach(method -> { Method javaMethod = method.getAnnotated().getJavaMember(); String explicitGaugeName = method.getAnnotated().getAnnotation(Gauge.class).name(); String gaugeName = String.format("%s.%s", clazz.getName(), explicitGaugeName != null && explicitGaugeName.length() > 0 ? explicitGaugeName : javaMethod.getName()); annotatedGaugeSites.put(gaugeName, method); LOGGER.log(Level.FINE, () -> String.format("### Recorded annotated gauge with name %s", gaugeName)); }); }
/** * Gather Application or resource classes to start. * * @param pit injection target * @param <T> any type */ @SuppressWarnings("unchecked") public <T> void gatherApplications(@Observes ProcessInjectionTarget<T> pit) { AnnotatedType<T> at = pit.getAnnotatedType(); if (!at.isAnnotationPresent(ApplicationScoped.class)) { return; } // class is annotated, let's make sure it is an application Class<?> theClass = at.getJavaClass(); if (Application.class.isAssignableFrom(theClass)) { this.applications.add((Class<? extends Application>) theClass); } else { // still may be a jax-rs resource (with no application attached) if (at.isAnnotationPresent(Path.class)) { this.resourceClasses.add(theClass); } } }
private boolean isBeanWithManagedBeanAnnotation(ProcessAnnotatedType processAnnotatedType) { Class<?> beanClass = processAnnotatedType.getAnnotatedType().getJavaClass(); return beanClass.isAnnotationPresent(ManagedBean.class); }
private void registerMetrics(@Observes @WithAnnotations({Counted.class, Metered.class, Timed.class}) ProcessAnnotatedType<?> pat) { AnnotatedType<?> type = pat.getAnnotatedType(); Interceptor annot = type.getAnnotation(Interceptor.class); if (annot != null) { LOGGER.log(Level.FINE, () -> "### Processing annotations for " + pat.getAnnotatedType().getJavaClass().getName()); Class<?> clazz = configurator.getAnnotated().getJavaClass();
/** * Collects all FT methods in a set for later processing. * * @param event Event information. */ void registerFaultToleranceMethods(@Observes ProcessManagedBean<?> event) { AnnotatedType<?> type = event.getAnnotatedBeanClass(); for (AnnotatedMethod<?> method : type.getMethods()) { if (isFaultToleranceMethod(type.getJavaClass(), method.getJavaMember())) { getRegisteredMethods().add(new BeanMethod(type.getJavaClass(), method.getJavaMember())); } } }
private Class<? extends Annotation> getJsf2ScopeAnnotation(ProcessAnnotatedType processAnnotatedType) { for (Class<? extends Annotation> currentJsfScope : this.mappedJsfScopes.keySet()) { if (processAnnotatedType.getAnnotatedType().getJavaClass().isAnnotationPresent(currentJsfScope)) { return currentJsfScope; } } return null; }
public void registerClient(@Observes @WithAnnotations({RegisterRestClient.class}) ProcessAnnotatedType<?> pat) { Class<?> typeDef = pat.getAnnotatedType().getJavaClass(); if(typeDef.isInterface()) { proxyTypes.add(typeDef); pat.veto(); } else { errors.add(new IllegalArgumentException("Rest client needs to be interface: " + typeDef)); } }
/** * Registers metrics for all field and method producers defined by the application. * * @param adv After deployment validation event. * @param bm Bean manager. */ private void registerProducers(@Observes AfterDeploymentValidation adv, BeanManager bm) { LOGGER.log(Level.FINE, () -> "### registerProducers"); MetricRegistry registry = getMetricRegistry(); producers.entrySet().forEach(entry -> { Metric metric = entry.getValue().getAnnotation(Metric.class); if (metric != null) { String metricName = getMetricName(new AnnotatedElementWrapper(entry.getValue()), entry.getValue().getDeclaringType().getJavaClass(), MetricUtil.MatchingType.METHOD, metric.name(), metric.absolute()); registry.register(metricName, getReference(bm, entry.getValue().getBaseType(), entry.getKey())); } }); producers.clear(); }
private Class<? extends Annotation> getJsf2ScopeAnnotation(ProcessAnnotatedType processAnnotatedType) { for (Class<? extends Annotation> currentJsfScope : this.mappedJsfScopes.keySet()) { if (processAnnotatedType.getAnnotatedType().getJavaClass().isAnnotationPresent(currentJsfScope)) { return currentJsfScope; } } return null; }
/** * Set a default scope for each CDI bean which is a JAX-RS Resource. * * @param <T> type * @param event event * @param beanManager bean manager */ public <T> void observeResources(@WithAnnotations({Path.class}) @Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { setBeanManager(beanManager); AnnotatedType<T> annotatedType = event.getAnnotatedType(); if(!annotatedType.getJavaClass().isInterface() && !isSessionBean(annotatedType) // This check is redundant for CDI 1.1 containers but required for CDI 1.0 && GetRestful.isRootResource(annotatedType.getJavaClass()) && !annotatedType.isAnnotationPresent(Decorator.class)) { LogMessages.LOGGER.debug(Messages.MESSAGES.discoveredCDIBeanJaxRsResource(annotatedType.getJavaClass().getCanonicalName())); event.setAnnotatedType(wrapAnnotatedType(annotatedType, requestScopedLiteral)); this.resources.add(annotatedType.getJavaClass()); } }
@SuppressWarnings("unused") private void processInjectionTarget(@Observes final ProcessInjectionTarget event) { final InjectionTarget it = event.getInjectionTarget(); final Class<?> componentClass = event.getAnnotatedType().getJavaClass();
private void checkExpressionActivated(ProcessAnnotatedType<?> processAnnotatedType) { Class<?> annotatedClass = processAnnotatedType.getAnnotatedType().getJavaClass(); if(!ActivationUtils.isActivated(annotatedClass, PropertyExpressionInterpreter.class)) { processAnnotatedType.veto(); LOG.finer("Expression Veto for bean with type: " + processAnnotatedType.getAnnotatedType().getJavaClass() ); } }
/** * Set a default scope for each CDI bean which is a JAX-RS Provider. * * @param <T> type * @param event event * @param beanManager bean manager */ public <T> void observeProviders(@WithAnnotations({Provider.class}) @Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { setBeanManager(beanManager); AnnotatedType<T> annotatedType = event.getAnnotatedType(); if(!annotatedType.getJavaClass().isInterface() && !isSessionBean(annotatedType) // This check is redundant for CDI 1.1 containers but required for CDI 1.0 && annotatedType.isAnnotationPresent(Provider.class)) { LogMessages.LOGGER.debug(Messages.MESSAGES.discoveredCDIBeanJaxRsProvider(annotatedType.getJavaClass().getCanonicalName())); event.setAnnotatedType(wrapAnnotatedType(annotatedType, applicationScopedLiteral)); this.providers.add(annotatedType.getJavaClass()); } }
/** * Wrap InjectionTarget of JAX-RS components within JaxrsInjectionTarget * which takes care of JAX-RS property injection. * * @param <T> type * @param event event */ public <T> void observeInjectionTarget(@Observes ProcessInjectionTarget<T> event) { if (event.getAnnotatedType() == null) { // check for resin's bug http://bugs.caucho.com/view.php?id=3967 LogMessages.LOGGER.warn(Messages.MESSAGES.annotatedTypeNull()); return; } if (Utils.isJaxrsComponent(event.getAnnotatedType().getJavaClass())) { event.setInjectionTarget(wrapInjectionTarget(event)); } }
private void vetoBean(ProcessAnnotatedType processAnnotatedType) { if(this.logger.isLoggable(Level.FINER)) { this.logger.finer(processAnnotatedType.getAnnotatedType().getJavaClass().getName() + " won't be used as CDI bean"); } processAnnotatedType.veto(); }
/** * Set a default scope for each CDI bean which is a JAX-RS Application subclass. * * @param <T> type * @param event event * @param beanManager bean manager */ public <T extends Application> void observeApplications(@Observes ProcessAnnotatedType<T> event, BeanManager beanManager) { setBeanManager(beanManager); AnnotatedType<T> annotatedType = event.getAnnotatedType(); if(!isSessionBean(annotatedType)) { LogMessages.LOGGER.debug(Messages.MESSAGES.discoveredCDIBeanApplication(annotatedType.getJavaClass().getCanonicalName())); event.setAnnotatedType(wrapAnnotatedType(annotatedType, applicationScopedLiteral)); } }
void beforeBeanDiscovery( @Observes final BeforeBeanDiscovery event, BeanManager beanManager) { // Register FlowBuilderFactoryBean as a bean with CDI annotations, so the system // can take it into account, and use it later when necessary. AnnotatedType<FlowBuilderFactoryBean> flowDiscoveryHelper = beanManager.createAnnotatedType(FlowBuilderFactoryBean.class); event.addAnnotatedType(flowDiscoveryHelper, flowDiscoveryHelper.getJavaClass().getName()); }