I have defined an OSGi bundle (cluster_implementation
) with a Declarative Service (DS) component definition, specifying one service exported, one activate method and one deactivate method.
In the body of the Activate method i need to access one file that is not present in the file-system but is bundled in the OSGi bundle itself.
During the activate method, the file content is retrieved as an InputStream
using java.lang.ClassLoader:getResourceAsStream
.
This mostly works, but there is one case where it doesn't work. In my application the service exported by the cluster_implementation
can be referenced by other bundles either via the Service Registry or Declarative Service or spring-dm. The activation policy of the component is delayed
so it gets activated when the first reference to the service happens.
Now if the activation happens because of a reference from Declarative Service component the file content is read fine, if instead the activation happens because a spring-dm component is in the need for the service, then the InputStream
for the resource is NULL
!
For now i have solved the problem by making the component to activate immediately by setting immediate="true"
in the component property, however my requests are these:
- Is it allowed to fetch the content of a resource as a Stream during DS component activation?
- If this is legal, why activating via spring-dm could cause the resource as Stream not to be accessible? BTW the resource is there - if I do a
Bundle.findEntries
I can see it!
The OSGi framework I'm using is Equinox 3.6.