Accessibility

TechNote (Archived)

ColdFusion MX: Java objects using HttpsUrlConnection causes a ClassCastException

Issue


Creating Java objects that use HttpsUrlConnection to create SSL connections fails with a ClassCastException in Macromedia ColdFusion MX. For example, the following code example will fail with a ClassCastException:

 httpsConnection = (javax.net.ssl.HttpsURLConnection)url.openConnection(); 

Examining the class created shows the connection is of type com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl. A connection of class sun.net.www.protocol.https.HttpsURLConnectionImpl is expected. To examine the class that is created, use the following code:

 Object obj = url.openConnection(); System.out.println("Connection is type: " + obj.getClass().getName()); 

The ClassCastException appears similar to the following:

 java.lang.ClassCastException     at com.macromedia.utilities.HttpsConnection.postData(HttpsConnection.java:121)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:324)     at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:74)     at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:1622)     at cfhttptest2ecfm747877201.runPage(c:\inetpub\wwwroot\test\httptest.cfm:8)     at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)     at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)     at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:62)     at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:107)     at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)     at coldfusion.filter.PathFilter.invoke(PathFilter.java:80)     at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:47)     at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:52)     at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)     at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:35)     at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:43)     at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)     at coldfusion.CfmServlet.service(CfmServlet.java:105)     at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)     at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)     at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)     at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:249)     at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)     at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:192)     at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)     at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66) 

This issue occurs because ColdFusion MX is compiled under a 1.3 JDK for wider compatability. TheHttpsURLConnectionImpl desired is from a 1.4 JDK package.

Solution


The workaround is to add a JVM argument of
-Djava.protocol.handler.pkgs=javax.net.ssl on the Java and JVM page in the ColdFusion Adminstrator.

  1. Open the ColdFusion Administrator.
  2. Select the Java and JVM page.
  3. Navigate to the JVM Arguments field.
  4. At the end of the existing arguments, add a space, then the new JVM argument:

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

    Note: Use caution since arguments are case sensitive.
  5. Click Submit Changes.
  6. Restart the ColdFusion service for the changes to take effect.

View a demonstration of the steps to add the JVM argument.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_19418
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox

Products Affected:

coldfusion