Class CdiComponentProvider

java.lang.Object
org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider
All Implemented Interfaces:
jakarta.enterprise.inject.spi.Extension, ComponentProvider

public class CdiComponentProvider extends Object implements ComponentProvider, jakarta.enterprise.inject.spi.Extension
Jersey CDI integration implementation. Implements Jersey component provider to serve CDI beans obtained from the actual CDI bean manager. To properly inject JAX-RS/Jersey managed beans into CDI, it also serves as a CDI Extension, that intercepts CDI injection targets.
Author:
Jakub Podlesak
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Auxiliary annotation for mocked beans used to cover Jersey/HK2 injected injection points.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name to be used when binding CDI injectee skipping class analyzer to HK2 service injection manager.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Add a predicate to test HK2 dependency to create a CDI bridge bean to HK2 for it.
    boolean
    bind(Class<?> clazz, Set<Class<?>> providerContracts)
    Jersey will invoke this method before binding of each component class internally during initialization of it's injection manager.
    boolean
    bind(Class<?> component, ContractProvider contractProvider)
    Jersey will invoke this method before binding of each component class internally during initialization of it's injection manager.
    void
    Jersey will invoke this method after all component classes have been bound.
    org.glassfish.jersey.internal.inject.InjectionManager
    Gets you effective injection manager.
    void
    initialize(org.glassfish.jersey.internal.inject.InjectionManager injectionManager)
    Initializes the component provider with a reference to a injection manager instance, which will get used in the application to manage individual components.
    void
    processAnnotatedType(jakarta.enterprise.inject.spi.ProcessAnnotatedType processAnnotatedType)
     

    Methods inherited from class java.lang.Object

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

    • CDI_CLASS_ANALYZER

      public static final String CDI_CLASS_ANALYZER
      Name to be used when binding CDI injectee skipping class analyzer to HK2 service injection manager.
      See Also:
  • Constructor Details

    • CdiComponentProvider

      public CdiComponentProvider()
  • Method Details

    • initialize

      public void initialize(org.glassfish.jersey.internal.inject.InjectionManager injectionManager)
      Description copied from interface: ComponentProvider
      Initializes the component provider with a reference to a injection manager instance, which will get used in the application to manage individual components. Providers should keep a reference to the injection manager for later use. This method will be invoked prior to any bind method calls. The injection manager parameter will not be fully initialized at the time of invocation and should be used as a reference only.
      Specified by:
      initialize in interface ComponentProvider
      Parameters:
      injectionManager - an injection manager.
    • bind

      public boolean bind(Class<?> clazz, Set<Class<?>> providerContracts)
      Description copied from interface: ComponentProvider
      Jersey will invoke this method before binding of each component class internally during initialization of it's injection manager. If the component provider wants to bind the component class itself, it must do so and return true. In that case, Jersey will not bind the component and rely on the component provider in this regard.
      Specified by:
      bind in interface ComponentProvider
      Parameters:
      clazz - a component (resource/provider) class.
      providerContracts - provider contracts implemented by given component.
      Returns:
      true if the component class has been bound by the provider, false otherwise
    • bind

      public boolean bind(Class<?> component, ContractProvider contractProvider)
      Description copied from interface: ComponentProvider
      Jersey will invoke this method before binding of each component class internally during initialization of it's injection manager. If the component provider wants to bind the component class itself, it must do so and return true. In that case, Jersey will not bind the component and rely on the component provider in this regard.
      Specified by:
      bind in interface ComponentProvider
      Parameters:
      component - a component (resource/provider) class.
      contractProvider - optional registered ContractProvider of the component.
      Returns:
      true if the component class has been bound by the provider, false otherwise
    • done

      public void done()
      Description copied from interface: ComponentProvider
      Jersey will invoke this method after all component classes have been bound. If the component provider wants to do some actions after it has seen all component classes registered with the application, this is the right place for the corresponding code.
      Specified by:
      done in interface ComponentProvider
    • processAnnotatedType

      public void processAnnotatedType(jakarta.enterprise.inject.spi.ProcessAnnotatedType processAnnotatedType)
    • getEffectiveInjectionManager

      public org.glassfish.jersey.internal.inject.InjectionManager getEffectiveInjectionManager()
      Gets you effective injection manager.

      Note: Do NOT lower the visibility of this method. CDI proxies need at least this visibility.

      Returns:
      HK2 injection manager.
    • addHK2DepenendencyCheck

      public static void addHK2DepenendencyCheck(Predicate<Class<?>> predicate)
      Add a predicate to test HK2 dependency to create a CDI bridge bean to HK2 for it.
      Parameters:
      predicate - to test whether given class is a HK2 dependency.