Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 325057

Summary: OsgiBundleResource should implement contentLength()
Product: [RT] Gemini.Blueprint Reporter: Bryan <bryan>
Component: CoreAssignee: Project Inbox <gemini.blueprint-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: cleau
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Bryan CLA 2010-09-12 15:08:08 EDT
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.
Comment 1 Costin Leau CLA 2011-01-26 10:41:05 EST
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.