Community
Participate
Working Groups
The OsgiBundleResource class does not implement contentLength(), rather it relies on the default implementation in AbstractResource. The default implementation calls getFile().getLength(). This is not a very reliable way to get the content length, and in fact fails for resources in jars embedded inside an OSGi bundle (e.g. using the Bundle-Classpath header). OsgiBundleResource should instead implement contentLength() explicitly so it can handle this more gracefully and not rely on a call to getFile(). The real world problem for me is using Spring MVC inside an OSGi container. Spring MVC's ResourceHttpRequestHandler calls Resource.contentLength(), which is fails for me. My workaround was to subclass ResourceHttpRequestHandler so it doesn't call contentLength.
Unfortunately there's no easy way to fix this currently. As you mentioned there are various resources that can be found - files inside jars that are embedded in other jars - for each of these items we rely on the underlying platform and we only retrieve InputStreams. Thus we cannot find out the length of the underlying resources - at least not reliably and not always... Patches are welcome of course.