Legacy application upgrade – Part 1

This will be a series of post talking about how I ended up in upgrading an legacy application to Java8 and Wildfly 10.1. Let us jump into part – 1,

The legacy application had very large code base which is running in 8+ (approx..) years old platform and libraries. They were using Java-6 to compile, JBOSS 5 to host applications. After some code walk on very first day I realized that there is no standard, no design pattern followed anywhere in the system. Disappointed? No, 10 years back, I know I was also in hurry to get some product to market first. In the same tone, I only see implementation which remain me those days of getting it done to showcase to customer.

Today, the task that I have in my hand to upgrade the code base to be able to compile using Java8 and able to host all the applications under Wildfly 10.1 container and run it fine.

Part 1 – Private (JDK) API Usage

A function in the code base is using sun.security.x509.CertAndKeyGen to generate self signed certificate like below,

CertAndKeyGen certAndKeyGen = new CertAndKeyGen(algorithm, "SHADSA");
X509Certificate certificate = certAndKeyGen.getSelfCertificate(name, validity);
KeyPair keyPair = new KeyPair(certificate.getPublicKey(), certificate.getPrivateKey());
SelfSigned selfSigned = new SelfSigned();

Thanks god ! Above code runs only in Test Environment !

The class CertAndKeyGen is private which used to be available inside rt.jar under sun.security.x509 package. In Java8, it has been moved inside tools sun.security.tools.keytool as this functionality is specific to keytool. Because of this change in Java8, the compilation fails with following error,

error: cannot find symbol [javac] import sun.security.x509.CertAndKeyGen;

After making import change accordingly, new compilation error popped out like below,

 [javac] KeyHelper.java:17: error: package sun.securitytools.keytool does not exist
 [javac] import sun.security.tools.keytool.CertAndKeyGen;

The above error is because rt.jar is not referred directly like other JAR files in classpath. The java compiler will use the symbol file (like stubs, available under %JAVA_HOME%/lib/ct.sym) to refer API’s in rt.jar. The keytool specific functions are not available in symbol files since CertAndKeyGen is moved inside keytool it become not available for Java applications. The above error is worked around using following compiler option in the existing ANT build system,

<compilerarg value="-XDignore.symbol.file"/>

With this I was able to continue with compilation further and yes, I got stuck with my second issue immediately. I will talk about that in the next post (part-2)…

Leave a Reply

Your email address will not be published.

WP2Social Auto Publish Powered By : XYZScripts.com