ops4j / org.ops4j.pax.cdi

Contexts and Dependency Injection for OSGi
Apache License 2.0
34 stars 26 forks source link

Injection of OSGi Services not work [PAXCDI-239] #280

Open ops4j-issues opened 5 years ago

ops4j-issues commented 5 years ago

Alexander Rotnov created PAXCDI-239

Bug reproduced with sample bundles "pax-cdi-sample1" and "pax-cdi-sample1-web".
To reproduce get clean Karaf 4.2.5, install required features and sample bundles:

feature:install pax-http-whiteboard
feature:install pax-cdi-web-weld-jetty
feature:install war
bundle:install -s mvn:org.ops4j.pax.cdi.samples/pax-cdi-sample1/1.1.1
bundle:install -s mvn:org.ops4j.pax.cdi.samples/pax-cdi-sample1-web/1.1.1

Open URL: http://localhost:8181/sample1/ice
Result is Error 503 Service Inavailable with message:

javax.servlet.ServletException: org.eclipse.jetty.servlet.ServletHolder$1: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001408: Unsatisfied dependencies for type IceCreamService with qualifiers @Dynamic @Service @Filter @UniqueIdentifier
  at injection point [BackedAnnotatedField] @Inject @Service @Dynamic @Filter private org.ops4j.pax.cdi.sample1.web.IceCreamServlet.chocolate
  at org.ops4j.pax.cdi.sample1.web.IceCreamServlet.chocolate(IceCreamServlet.java:0)
...

Affects: 1.0.0, 1.1.0, 1.1.1 Votes: 0, Watches: 1

paulsp commented 2 years ago

The issue is present in 1.1.4

The URL /sample1/ice is not present in the integration testing. Adding the following test to itest/src/it/itest-standalone/src/test/java/org/ops4j/pax/cdi/test/ServletTest.java will test OSGi Service injection.

   @Test
   public void servletServiceInjection() {
        Client client = Client.create();
        WebResource resource = client.resource(String.format("http://localhost:%s/sample1/ice", httpPort));
        assertThat(resource.get(String.class), is("Message from managed bean\r\n"));
    }

Although message text need to be corrected, the following exception is being thrown:

org.jboss.weld.exceptions.IllegalArgumentException: WELD-001408: Unsatisfied dependencies for type IceCreamService with qualifiers @Dynamic @Service @Filter @UniqueIdentifier
  at injection point [BackedAnnotatedField] @Inject @Service @Dynamic @Filter private org.ops4j.pax.cdi.sample1.web.IceCreamServlet.chocolate
  at org.ops4j.pax.cdi.sample1.web.IceCreamServlet.chocolate(IceCreamServlet.java:0)
paulsp commented 2 years ago

See #294 related to POM issue relate to Integration Testing

grgrzybek commented 2 years ago

I'm sorry - last time I checked, the integration tests worked fine, but I agree that the Pax Exam integration test setup is a bit fragile.

The problem is that recently (~2 years) I was refactoring Pax Web (Pax Web 8.0.0 is already released) and I realized that Pax CDI has lots of issues I'll rather won't have the time to fix. Also I was working a bit trying to make Pax Web 8 working with Aries CDI and there's one deadlock left to fix - see ops4j/org.ops4j.pax.web#1622 ;)

Because Aries CDI is an implementation of OSGi R8 CMPN CDI Specification, I'm afraid Pax CDI won't get much attention...

paulsp commented 2 years ago

Thank you for the status. I will keep this in mind as I use Pax CDI.