1

I have a problem with an unsatisfied reference in an OSGi declarative service component:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
    name="com.mycompany.foo.Service"
    immediate="true"
    activate="activate"
    deactivate="deactivate">
<implementation class="com.mycompany.foo.Service"/>
<!-- Other references -->
<reference
        interface="org.osgi.service.http.HttpService"
        name="HttpService"
        cardinality="1..1"
        policy="static"
        bind="setHttpService"
        unbind="unsetHttpService"/>
</scr:component>

I launch the OSGi application from Eclipse, and the console shows the service is in the Unsatisfied state:

osgi> ls
All Components:
ID    State            Component Name            Located in bundle
6    Unsatisfied        com.mycompany.foo.Service            com.mycompany.foo(bid=18)

The comp command reports the reason is an unsatisfied reference to org.osgi.service.http:

osgi> comp 6
Component[
    name = com.mycompany.foo.Service
    ...
    state = Unsatisfied
    references = {
        ...
        Reference[name = HttpService, interface = org.osgi.service.http.HttpService, policy = static, cardinality = 1..1, target = null, bind = setHttpService, unbind = unsetHttpService]
    }
    located in bundle = com.mycompany.foo_1.2.3 [18]
]
Dynamic information :
   *The component is NOT satisfied
   The following references are not satisfied:
     Reference[name = HttpService, interface = org.osgi.service.http.HttpService, policy = static, cardinality = 1..1, target = null, bind = setHttpService, unbind = unsetHttpService]
   Component configurations :
     Configuration properties:
       component.name = com.mycompany.foo.Service
       component.id = 6
     Instances: 

But org.osgi.service.http is available as the packages command shows:

osgi> p org.osgi.service.http
org.osgi.service.http; version="1.2.1"<org.eclipse.osgi.services_3.2.100.v20100503 [54]>
  com.mycompany.foo_1.2.3 [18] imports
  org.eclipse.equinox.http.registry_1.1.1.R36x_v20101103 [46] imports
  org.eclipse.equinox.http.servlet_1.1.0.v20100503 [47] imports
  org.eclipse.equinox.http.servletbridge_1.0.200.v20100503 [48] imports

I tried removing the reference from the service document and the service component is instantiated and activated correctly, but without the essential HttpService piece.

Any help to troubleshoot further is much appreciated.

claudiopro
  • 339
  • 4
  • 17

1 Answers1

0

The error is saying that your component requires an implementation of the HttpService. You do not have one available.

The "p" command only reports on static packages. You have the org.osgi.service.http API package available, but you need a bundle that actually implements the API and provides the service.

I recommend adding the org.apache.felix.http.jetty bundle, which contains an easy-to-use implementation of HttpService.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • Thanks Neil, I will try that now. The implementation should be made available by `org.eclipse.equinox.http.servlet.internal.HttpServiceImpl`. – claudiopro Oct 21 '13 at 11:45
  • That's the name of a class which is private inside a bundle. You shouldn't need to care about that -- you only care about which bundle provides the service. – Neil Bartlett Oct 21 '13 at 19:27
  • Turns out there were missing bundles in my workspace. My project required cherry-picking a minimum set from a broader repository of bundles. The target platform required more bundles than those I originally picked. I guess the absence of runtime errors in such circumstances is by design? – claudiopro Oct 25 '13 at 08:53