Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MimeTypes resource loading incorrect on OSGi #797

Closed
mbechler opened this issue Aug 1, 2016 · 6 comments
Closed

MimeTypes resource loading incorrect on OSGi #797

mbechler opened this issue Aug 1, 2016 · 6 comments
Assignees
Labels
Bug For general bugs on Jetty side
Milestone

Comments

@mbechler
Copy link

mbechler commented Aug 1, 2016

Starting with 9.3.11 (#723) fails to load the bundled mime type resources in OSGI and logs two warnings.

The new code seems to load the resources through HashMap's (== bootstrap, with Loader falling back to system) classloader with is quite obviously wrong and should be MimeTypes.class or something like that.

@joakime joakime changed the title MimeTypes incorrect resource loading MimeTypes resource loading incorrect on OSGi Aug 1, 2016
@joakime joakime added the Bug For general bugs on Jetty side label Aug 1, 2016
@gregw gregw self-assigned this Aug 2, 2016
@gregw gregw added this to the 9.3.x milestone Aug 2, 2016
gregw added a commit that referenced this issue Aug 2, 2016
Pass MimeTypes.class as the classloader source.  
No unit test to confirm the fix.
@gregw
Copy link
Contributor

gregw commented Aug 2, 2016

@janbartel I've switched the loader class to MimeTypes, but we probably should have a unit test for this, can you look at that?

@gregw
Copy link
Contributor

gregw commented Aug 2, 2016

@janbartel Note also that in 9.4.x we no longer have a class argument to the loader, so a different solution will be required.

@janbartel
Copy link
Contributor

@gregw the solution to both 9.3 and 9.4 behaviour is to simply re-instate the use of the ResourceBundle instead of Loader.getResource(): ResourceBundle uses the classloader of the MimeTypes class, which is what is desired.

@janbartel
Copy link
Contributor

@mbechler FYI issue #705 is also relevant for jetty-9.4. Although in this case the problem will be solved if we revert to using ResourceBundle to load the mime types, in general if using in an osgi environment, you'll need to have a reasonable thread context classloader set up before accessing jetty classes.

janbartel added a commit that referenced this issue Aug 3, 2016
@mbechler
Copy link
Author

mbechler commented Aug 3, 2016

Wouldn't using MimeTypes.class.getClassLoader().getResource(..) solve all the issues at hand (for MimeTypes, extension loading is of course a different beast)? Doesn't do ResourceBundle's magic, does not use Loader and uses the correct classloader.

janbartel added a commit that referenced this issue Aug 10, 2016
Use MimeTypes.class.getClassLoader to load properties.
@janbartel
Copy link
Contributor

@mbechler actually ClassLoader.getResource() implements the java classloader search order, which is parent first. So it will actually try the parent first (or bootstrap classloader if there is no parent) before failing back to the actual classloader. So that doesn't seem totally ideal either. However,I've changed it to use your suggestion in jetty-9.3 and beyond. I'll close this issue for now, but let us know if there are any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

No branches or pull requests

4 participants