Question

I am having problems with adding a protocol handler for LDAP on OSGi environment. I tried:

  • System.setProperty("java.protocol.handler.pkgs", "iaik.x509.net");
  • -Djava.protocol.handler.pkgs=iaik.x509.net in the Run Settings

but still get the java.net.MalformedURLException: unknown protocol: ldap

The protocol Handler for LDAP is in iaik.x509.net and is exported by its bundle. I am importing that bundle (that has iaik.x509.net) too. To me it seems that the System cannot find the package though. How do I "register" that protocol handler correctly? I am running equinox 3.6.0 using java 1.6.

Was it helpful?

Solution

Try to install iaik.x509.net bundle as a Framework extension bundle. It should contain MANIFEST header:

Fragment-Host: system.bundle; extension:=bootclasspath

In this case LDAP protocol handler will be available for all bundles as a part of bootclasspath. Don't forget to set system property.

More details for extension bundles: OSGi Core Spec 4.2 - Chapter 3.14

OTHER TIPS

Shouldn't the property be: -Djava.protocol.handler.pkgs=iaik.x509.net.ldap (it needs to be the package of the class extending URLConnection, from looking at this). To use it like this you'll have to add it to the Jar to boot classpath and export that package as part of the system bundle with org.osgi.framework.system.packages.extra=iaik.x509.net.ldap

Alternatively turn it into a first class OSGi component. Create a bundle that provides a wrapper for the handler with an implementation of org.osgi.service.url.URLStreamHandlerService that exports a service property url.handler.protocol=ldap

It's not much work to add a small bundle exporting the URLStreamHandlerService, this is definitely the way I'd go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top