I am developing an applet to digitally sign files from a web application, using JCAPI. Initial tests work fine, but i have found that there is a problem with Internet Explorer, when the page that includes the applet, is reloaded with Ctrl+F5 (that is, bypassing browser cache). If page is reloaded that way, an Exception is thrown, saying that dll is already loaded by another class loader.
It happens just with IE (works fine on Firefox and Opera), and just with Ctrl-F5 reload (just pressing F5, works fine)
It seems than Internet Explorer unloads all Java classes, so when loaded again, static initializers are re-executed. I guess that JCAPI uses a boolean static atribute to check if dll has been loaded, and that static mark is setted to its original value.
Anyway, I have implemented my own checking, with a boolean static atribute, and a static method that executes "Security.addProvider(new JCAPIProvider())". Code is like this:
private static boolean ini = false;
public static void init() {
if (! ini) {
java.security.Security.addProvider(new com.pheox.jcapi.JCAPIProvider());
ini= true;
}
}
Adding logging to this code, shows that when applet is reloaded in IE, when reeloading page with Ctrl+F5, private static boolean ini atribute is set to false again. But dll is already loaded by the JRE, so an Exception is thrown.
I have used a system property to avoid this (using java.lang.System.getProperty and java.lang.System.setProperty), checking and setting it when adding JCAPI provider. In this case, code is not executed when applet is reloaded with Crtl+F5, but then an exception is thrown when I try to use JCAPI after reload, saying than JCAPI provider has not been added.
I know that it seems to be an IE bug, not JCAPI bug, but ¿Is there any kind of workaround? If not ¿are there plans to make it possible (maybe allowing JCAPI to ignore dll load exceptions, if developer want to)?