Like Speaking French in Russian
Remember that ‘Most Interesting Man in the World’ commercial, where the narrator said he could speak French in Russian? That’s what this post reminded me of. Because to solve a problem recently, I had to extend a Java class… in JavaScript.
One of the drawbacks of cloud-based subscription hosting of software is the flexibility that you often lose. Last year for a client, I had to integrate a cloud system for which they had a subscription with another cloud system for which they also had a subscription. But the Java keystore for system A did not trust system B. And the cloud vendor would not permit changes to the Java keystore in production, because of course they wouldn’t. That’s not worth the risk to them for one random customer.
So what is a developer to do? The obvious answer is an intermediate system that the client can control. The intermediate system would pass calls from system A to B, and would ensure that it used a certificate that system A trusts.
But that is another expense — either a physical server that would need to be upgraded, managed and secured, or yet another monthly subscription.
Fortunately I was able to find a way around it. System A provided a JavaScript scripting interface within the Java JVM via Nashorn. So I extended a Java class using JavaScript syntax, overrode the keystore, added the certificate in plain text to the source code, loaded it into the keystore, registered the new keystore with the JVM whenever my interaction was running, and it worked! System A trusted System B with no intermediate step! And it didn’t break the main keystore.
I feel dirty. This is the definition of kluge. But at the same time, I feel pretty proud. This was a tricky problem, and I solved it in a way that saved the customer money and trouble, learned a thing or two about what was possible with Nashorn, and reminded myself just what I could do when I put my mind to it.
So, I’m the second-most interesting man in the world?