Search code examples
javacoldfusioncoldfusion-10

ClassCast exception when using GoCardless Java library with ColdFusion


I am using the GoCardless Java library with ColdFusion but am getting the following exception:

com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl cannot be cast to javax.net.ssl.HttpsURLConnection

Having read this blog post it seems that GoCardless is written against javax.net.ssl, but the JVM is dealing with com.sun.net.ssl.

The blog post suggests fixing this by setting the following Java system property:

-Djava.protocol.handler.pkgs=javax.net.ssl

I am inexperienced with changing JVM settings and wondered if changing the setting above might cause issues elsewhere, perhaps where native ColdFusion methods rely on com.sun.net.ssl? If it is possible that issues might arise then I cannot realistically fix the problem by changing the JVM setting as I have several applications running on the same instance of ColdFusion.

Would there be any other way around this issue? Thanks!


Solution

  • I read your comment on the referenced blog post. In it you asked is there a way to set -Djava.protocol.handler.pkgs to javax.net.sll temporarily and then switch it back to com.sun.net.ssl.internal.www.protocol. I believe there is.

    Disclaimer - I have not attempted this and I am not sure of the ramifications. For example, multiple requests could be running simultaneously while you have changed this setting.

    Read this post - You can set Java system properties via ColdFusion

    So, theoretically, you could change the setting like so:

    <cfset sys = createObject("java", "java.lang.System")>
    <cfset sys.setProperty("java.protocol.handler.pkgs", "javax.net.ssl")>
    

    And then change it back (see next example to retrieve the current setting):

    <cfset sys = createObject("java", "java.lang.System")>
    <cfset sys.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol")>
    

    You can also read the current system properties like so:

    <cfset sys = createObject("java", "java.lang.System")>
    <cfoutput>#sys.getProperty("java.protocol.handler.pkgs")#</cfoutput>
    

    (Reading that property on my ColdFusion 9.0.1 server returned com.sun.net.ssl.internal.www.protocol)