Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1.*
    • Fix Version/s: 2.1.*
    • Component/s: None
    • Labels:
      None

      Description

      HK2 needs to be able to delegate injection to CDI provider. Generic support is preferrable, but GlassFish specific support would be good enough.

      The typical use case for CDI / JAX-RS (Jersey) integration is a CDI bean (whose life-cycle is managed by CDI container) but is at the same time a JAX-RS resource that needs Jersey to satisfy the JAX-RS specific injection points. E.g.:

      @SessionScoped   // <-- CDI managed
      @Path("foo/{id}")   // <-- JAX-RS resource
      public class FooResource {
          @Inject MyEjb ejb;    // <-- injection point resolved by CDI
          @Context UriInfo uriInfo;    // <-- injection point resolved by Jersey (via HK2)
      
          ...
      }
      

      In the example above the FooResource needs to be managed by a CDI container and when Jersey tries to retrieve an instance of it via HK2 (e.g. via ServiceLocator.getService(FooResource.class)), the HK2 needs to recognize the bean is managed by an external container (CDI) and needs to retrieve it from that container.

      Also, the HK2 needs to be able to register an CDI extension bean in the CDI container that will be able to resolve custom (in our case JAX-RS) injection points that were added to the HK2 ServiceLocator by Jersey.

      In summary, the process of retrieval of an externally managed (CDI) component by Jersey via HK2 should look like:

      1. Jersey asks HK2 for a component instance
      2. HK2 does not have a descriptor so it consults the external provider(s) (in our case CDI) to provide the component instance
      3. External provider creates and injects the instance
        • During that phase external provider consults HK2 integration layer (in our case a CDI extension) to resolve the unsatisfied (JAX-RS/Jersey specific) injection points
      4. External provider returns the component to HK2
      5. HK2 passes the component to Jersey

      Note that the above could be converted into a generic HK2 external component provider API that is not necessarily CDI specific, but could be reused to integrate other injection providers too (Spring, Guice, ...). Obviously I do not insist on this particular solution. The important part is the use case demonstrating the problem that we need to solve.

        Issue Links

          Activity

          Hide
          TangYong added a comment -

          Good use case!

          I want to know whether having a plan to implement the task because a test case from osgi-javaee is also blocked by the task.

          Show
          TangYong added a comment - Good use case! I want to know whether having a plan to implement the task because a test case from osgi-javaee is also blocked by the task.
          Hide
          mikael.karon added a comment -

          We (Adrian.Gonzalez and Mikael.Karon) are working on getting a mixed stack of vertx (http://vertx.io) 2.0 and jersey 2.0 up and running and would really like this to.

          We currently have guice integration for vertx working, and for a while (a few revisions ago) we had a working example with jersey 1.x, vertx 2.0 and guice working fine (via IoCComponentProviderFactory) but as that is all replaced with HK2...

          Show
          mikael.karon added a comment - We (Adrian.Gonzalez and Mikael.Karon) are working on getting a mixed stack of vertx ( http://vertx.io ) 2.0 and jersey 2.0 up and running and would really like this to. We currently have guice integration for vertx working, and for a while (a few revisions ago) we had a working example with jersey 1.x, vertx 2.0 and guice working fine (via IoCComponentProviderFactory ) but as that is all replaced with HK2...
          Hide
          jwells added a comment -

          There is already hk2/CDI integration in GlassFish applications. This is not closed yet because we are not yet sure it meets all requirements, but the basics are there...

          Show
          jwells added a comment - There is already hk2/CDI integration in GlassFish applications. This is not closed yet because we are not yet sure it meets all requirements, but the basics are there...
          Hide
          jwells added a comment -

          HK2 and CDI have bi-directional injection capabilities. At this point, if there are any issues with it they should be tracked as separate bugs.

          Show
          jwells added a comment - HK2 and CDI have bi-directional injection capabilities. At this point, if there are any issues with it they should be tracked as separate bugs.

            People

            • Assignee:
              jwells
              Reporter:
              Marek Potociar
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: