Search code examples
javaldaposgiequinoxmalformedurlexception

OSGi Equinox: howto add protocol handler for LDAP?


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.


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