Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325057 - OsgiBundleResource should implement contentLength()
Summary: OsgiBundleResource should implement contentLength()
Status: CLOSED WONTFIX
Alias: None
Product: Gemini.Blueprint
Classification: RT
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-12 15:08 EDT by Bryan CLA
Modified: 2011-01-26 10:41 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.