URL Handlers


This bundle implements the standard OSGi URL Handlers service. To perform its function, it listens for stream and content handler services to be registered and then adds them to its list of handlers, which will then be use to service URL requests.

This bundle is also useful when working with legacy libraries that perform resource loading using methods like Class.getResource(). In many cases, legacy libraries convert the returned URLs into strings and this result in errors when trying to interpret the URL. This is because resources loaded from a bundle will have a URL that something like this:


The bundle: protocol requires a special stream handler for interpretation, where the 7.0 is the bundle identifier and the remainder is the path to the resource inside the bundle. Oscar automatically attaches the appropriate stream handler to the URL instance returned by methods like Class.getResource(), but if this URL is converted to a string and then later converted back into a URL, then it loses its special stream handler. To deal with this situation, the URL Handlers service for Oscar registers a stream handler for the bundle: protocol, so that string URLs can be converted back into URL instances and correctly interpreted. You will want to make sure that the URL Handlers bundle is in a start level lower than your legacy bundle.

Of course, Oscar could have been implemented to behave this way by default, but there are two reasons why it does not:

  1. Oscar would have to use URL.setURLStreamHandlerFactory() and this method can only ever be called once per JVM execution. Thus, if Oscar called this method, then anyone embedding Oscar inside of their own project would never be able to use this method if they wanted to do so.
  2. It represents a security risk, since it means that anyone can simply create a bundle: URL and then read from it. This is not possible in Oscar by default.

Since providing bundle: protocol support is a security concern, it is possible to disable it in the URL Handlers service by using the property specified below.

Stephane Chomat (stephane.chomat@imag.fr)
Richard S. Hall (heavy@ungoverned.org)




Only one configuration property is availabe:

Properties can be configured using the standard bundle.properties file as described in the usage document.

org.osgi.util.tracker, org.osgi.service.url