TrustManagerFactory IBM Java 1.7

871 Views Asked by At

In my Java Application, I used the keystore facility of Java in the client side. I support both Oracle and IBM Java environment. Basically the code looks like:

try {

        KeyStore ks = KeyStore.getInstance("JKS");

        MyResources gr = new MyResources(null);
        InputStream inpStream = gr.GetResourceAsStream(MYFILE);

        if (inpStream == null) {

        }

        ks.load(inpStream, MYPASSWORD);

        TrustManagerFactory Mytmf = null;

        try {
            Mytmf = TrustManagerFactory.getInstance("SUNX509");
        } catch (NoSuchAlgorithmException e) {
            Mytmf = TrustManagerFactory.getInstance("IbmX509");
        }

        Mytmf.init(ks);


    } catch (Exception e) {

    }

The program works fine in the IBM JRE 1.6 and earlier versions. In the version 1.7, The following exception is received in case of an connection attempt to the server and it fails at the end:

Exception in thread "myThread" java.lang.NoClassDefFoundError: sun/security/validator/KeyStores 09:06:46>>at sun.security.ssl.X509TrustManagerImpl.(X509TrustManagerImpl.java:80) 09:06:46>> at sun.security.ssl.TrustManagerFactoryImpl$SimpleFactory.getInstance(TrustManagerFactoryImpl.java:240) 09:06:46>> at sun.security.ssl.TrustManagerFactoryImpl.engineInit(TrustManagerFactoryImpl.java:79) 09:06:46>> at javax.net.ssl.TrustManagerFactory.init(TrustManagerFactory.java:19) 09:06:46>> at MyTrustMgr.getTrustManager(MyTrustMgr.java:34)

Do you have any idea what could be reason for this issue?

1

There are 1 best solutions below

2
On

Whatever the cause, the code is wrong. If you use TrustManagerFactory.getDefaultAlgorithm() as the argument, instead of that try/catch block, the problem will disappear.