Class ResteasyParamCdiExtension

java.lang.Object
org.jboss.resteasy.cdi.ResteasyParamCdiExtension
All Implemented Interfaces:
jakarta.enterprise.inject.spi.Extension

public class ResteasyParamCdiExtension extends Object implements jakarta.enterprise.inject.spi.Extension
A CDI Extension that enables Jakarta REST parameter annotations (@CookieParam, @FormParam, @HeaderParam, @MatrixParam, @PathParam, @QueryParam, and @BeanParam) to function as CDI qualifiers. This allows Jakarta REST resource classes to receive parameter values via CDI constructor injection rather than requiring a public no-arg constructor.

The extension operates in six CDI lifecycle phases:

  1. BeforeBeanDiscovery — registers each @*Param annotation as a CDI qualifier
  2. ProcessAnnotatedType — adds @Inject to @*Param-annotated fields, setter methods, and constructors so that CDI resolves parameter values automatically. RESTEasy-specific annotations (org.jboss.resteasy.annotations.jaxrs.*Param) are also handled by adding the corresponding Jakarta REST annotation alongside @Inject. The @BeanParam aggregators of resources are recorded.
  3. AfterTypeDiscovery — makes each recorded @BeanParam aggregator which is not a bean a @Dependent bean
  4. ProcessInjectionPoint — collects the types of all @*Param-annotated injection points
  5. AfterBeanDiscovery — registers synthetic beans that produce parameter values at request time by delegating to ParameterExtractors
  6. AfterDeploymentValidation — warns about @BeanParam aggregators with a normal scope
Author:
James R. Perkins
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addBeanParamTypes(jakarta.enterprise.inject.spi.AfterTypeDiscovery event)
    Makes each @BeanParam aggregator of a resource which is not a bean a @Dependent bean, and adds @Inject to its @*Param-annotated members.
    <T> void
    observeBeanParamCandidates(jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event)
    Records the discovered types which may be @BeanParam aggregators, so that addBeanParamTypes(AfterTypeDiscovery) does not add a type which is already a bean.
    <T> void
    observeParamResources(jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event)
    Observes Jakarta REST resource types and adds @Inject to fields, setter methods, and constructors annotated with @*Param annotations so that CDI can resolve parameter values via the synthetic beans registered by this extension.
    <T,X> void
    processInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint<T,X> pip)
    Observes each injection point during bean discovery and records the types of any injection points annotated with a @*Param qualifier.
    void
    registerParamQualifiers(jakarta.enterprise.inject.spi.AfterBeanDiscovery afd, jakarta.enterprise.inject.spi.BeanManager beanManager)
    Registers the @*Param annotations as CDI qualifiers with producers.
    void
    registerQualifiers(jakarta.enterprise.inject.spi.BeforeBeanDiscovery event)
    Registers each @*Param annotation as a CDI qualifier, marking all annotation members as Nonbinding so that qualifier resolution matches on presence alone rather than on member values.
    void
    validateBeanParamScopes(jakarta.enterprise.inject.spi.AfterDeploymentValidation event, jakarta.enterprise.inject.spi.BeanManager beanManager)
    Logs a warning for each @BeanParam aggregator whose bean has a normal scope.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ResteasyParamCdiExtension

      public ResteasyParamCdiExtension()
  • Method Details

    • registerQualifiers

      public void registerQualifiers(@Observes jakarta.enterprise.inject.spi.BeforeBeanDiscovery event)
      Registers each @*Param annotation as a CDI qualifier, marking all annotation members as Nonbinding so that qualifier resolution matches on presence alone rather than on member values.
      Parameters:
      event - the before bean discovery event
    • observeParamResources

      public <T> void observeParamResources(@Observes jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event)
      Observes Jakarta REST resource types and adds @Inject to fields, setter methods, and constructors annotated with @*Param annotations so that CDI can resolve parameter values via the synthetic beans registered by this extension. This covers both Jakarta REST annotations (jakarta.ws.rs.*Param) and RESTEasy-specific annotations (org.jboss.resteasy.annotations.jaxrs.*Param).
      Type Parameters:
      T - the type being processed
      Parameters:
      event - the annotated type being processed
    • observeBeanParamCandidates

      public <T> void observeBeanParamCandidates(@Observes jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event)
      Records the discovered types which may be @BeanParam aggregators, so that addBeanParamTypes(AfterTypeDiscovery) does not add a type which is already a bean. The scope and stereotype meta-annotations match a type with a bean defining annotation, which may have only @Context members or none. Any other type without these annotations has nothing for CDI to inject.
      Type Parameters:
      T - the type being processed
      Parameters:
      event - the annotated type being processed
    • addBeanParamTypes

      public void addBeanParamTypes(@Observes jakarta.enterprise.inject.spi.AfterTypeDiscovery event)
      Makes each @BeanParam aggregator of a resource which is not a bean a @Dependent bean, and adds @Inject to its @*Param-annotated members. CDI then creates the aggregator, and injects all its members, as for an aggregator which is a bean. An aggregator which CDI cannot create, e.g. one without a no-argument or @Inject constructor, is left to RESTEasy.
      Parameters:
      event - the after type discovery event
    • validateBeanParamScopes

      public void validateBeanParamScopes(@Observes jakarta.enterprise.inject.spi.AfterDeploymentValidation event, jakarta.enterprise.inject.spi.BeanManager beanManager)
      Logs a warning for each @BeanParam aggregator whose bean has a normal scope. The aggregator is then a client proxy, whose fields do not hold the parameter values, e.g. when validating a @Valid aggregator.
      Parameters:
      event - the after deployment validation event
      beanManager - the bean manager
    • registerParamQualifiers

      public void registerParamQualifiers(@Observes jakarta.enterprise.inject.spi.AfterBeanDiscovery afd, jakarta.enterprise.inject.spi.BeanManager beanManager)
      Registers the @*Param annotations as CDI qualifiers with producers.
      Parameters:
      afd - the after bean discovery event
      beanManager - the bean manager
    • processInjectionPoint

      public <T,X> void processInjectionPoint(@Observes jakarta.enterprise.inject.spi.ProcessInjectionPoint<T,X> pip)
      Observes each injection point during bean discovery and records the types of any injection points annotated with a @*Param qualifier. These types are later used to register synthetic producer beans.
      Type Parameters:
      T - the bean class of the bean that declares the injection point
      X - the declared type of the injection point
      Parameters:
      pip - the process injection point event