ColdFusion 10 - An Augmented Virtual File System (VFS)

Posted March 5, 2012 at 10:08 AM by Ben Nadel

Tags: ColdFusion

Last week, I explored ColdFusion 10's new ability to load custom Java Classes and JAR files on a per-application basis. In that exploration, I ended up creating a number of Java classes and a ColdFusion component (CFC) that needed to work together. This got me thinking about code deployment - if I created a Java class that depended on a ColdFusion component, could I deploy them together in the same JAR file? With ColdFusion 10's enhanced virtual file system (VFS), the answer is surprisingly, Yes. In fact, a ColdFusion component can now be loaded directly from a JAR file.

NOTE: At the time of this writing, ColdFusion 10 was in public beta.

To recap what I did last week, I came up with a way to enable Java to invoke ColdFusion closures and ColdFusion component methods. I did this by storing a dynamic Java proxy to the ColdFusionProxy.cfc component as a static Java class property. This, obviously, created a strong coupling between the Java class files to the ColdFusionProxy.cfc component. As such, I wanted to deploy them together in a single JAR file.

The result of this thinking was the cf10.jar file which created an archive with the following, embedded files:

  • cf10.jar !/ com / bennadel / cf10 / Core.class
  • cf10.jar !/ com / bennadel / cf10 / CFArray.class
  • cf10.jar !/ com / bennadel / cf10 / ColdFusionProxy.cfc

As you can see, this JAR file contains two Java classes and my ColdFusion component.

The augmented virtual file system in ColdFusion 10 provides us with read-access to JAR files. So, in order to create a dynamic Java proxy for this archived ColdFusion component, I simply had to map the JAR file path to a custom ColdFusion mapping:

Application.cfc - Our ColdFusion Application Framework Component

  • <cfscript>
  • // NOTE: CFScript tags add purely for Gist color-coding. Remove.
  •  
  • component
  • output="false"
  • hint="I define the application settings and event handlers."
  • {
  •  
  •  
  • // Define our standard Application settings.
  • this.name = hash( getCurrentTemplatePath() );
  • this.applicationTimeout = createTimeSpan( 0, 0, 0, 5 );
  •  
  • // Map aspects of the Virtial File System (VFS). Notice that the
  • // mapped file here ends with "!". This separates the JAR file
  • // path from the embedded, archived files.
  • this.mappings[ "/cf10jar" ] = (
  • "jar://" &
  • getDirectoryFromPath( getCurrentTemplatePath() ) &
  • "lib/cf10.jar!"
  • );
  •  
  • // Define our per-application Java library settings. Here, we
  • // are telling it to load our CF10.jar file.
  • this.javaSettings = {
  • loadPaths: [
  • "./lib/cf10.jar"
  • ],
  • loadColdFusionClassPath: true
  • };
  •  
  •  
  • // I initialize the application.
  • function onApplicationStart(){
  •  
  • // Create a dynamic proxy using a ColdFusion Component that
  • // is loacated in our CF10 JAR file. Since we mapped the
  • // location of the JAR file itself, now all we need to
  • // supply is the dot-file-path to the embedded component.
  • var coldfusionProxy = createDynamicProxy(
  • "/cf10jar.com.bennadel.cf10.ColdFusionProxy",
  • [ "com.bennadel.cf10.ColdFusionProxy" ]
  • );
  •  
  • // Now that we have our proxy, let's initialize our custom
  • // JAVA library with our ColdFusion invocation "tunnel."
  • // This will enable our Java classes to be able to invoke
  • // ColdFusion closures and component methods.
  • createObject( "java", "com.bennadel.cf10.Core" )
  • .setColdFusionProxy( coldfusionProxy )
  • ;
  •  
  • // Return true so the application can load.
  • return( true );
  • }
  •  
  •  
  • }
  •  
  • // NOTE: CFScript tags add purely for Gist color-coding. Remove.
  • </cfscript>

As you can see, I am creating a ColdFusion application mapping of the virtual file path:

jar://[app directory]/lib/cf10.jar!

... to the mapping:

/cf10jar

Notice that the virtual file path contains a trailing "!". This character separates the physical file path (JAR) from the embedded file paths (archived files). Everything after the "!" will be considered an in-JAR file path.

Once this mapping has been set up, I can then create a ColdFusion component using the fully qualified component path:

/cf10jar.com.bennadel.cf10.ColdFusionProxy

As you can see, this component class path starts off with "/cf10jar", our custom ColdFusion mapping. But then, we use the standard dot-notation to define the in-JAR file path to the ColdFusionProxy.cfc component. We're using the virtual file system to load a ColdFusion component out of a JAR file archive.

The ColdFusion 10 virtual file system (VFS) is pretty darn cool. It provides file-based access to the following protocols:

  • BZIP2
  • File
  • FTP
  • FTPS
  • GZIP
  • HTTP
  • HTTPS
  • JAR
  • RAM
  • RES
  • SFTP
  • TAR
  • TEMP
  • WebDAV
  • ZIP

Not all of these protocols provide read, write, and list access. Many provide only read-access to virtual files. The list of functionality and limitations can be seen on the Apache Commons website.

NOTE: ColdFusion 9.01 and ColdFusion 10 also support Amazon's Simple Storage Service (S3) through the protocol, "s3://". This integration is much more robust and requires application settings to be defined in the Application.cfc ColdFusion framework component.

Wile not all protocols in the ColdFusion virtual file system (VFS) support both read and write access, I think the unified access notation is going to be a very useful feature.


You Might Also Be Interested In:



Reader Comments

May 31, 2012 at 11:46 PM // reply »
2 Comments

What's the performance like?

Does it run in a ram-disk, or unpack the jar to a temp directory and run it from there?

I presume it doesn't decompress on the fly, cause that would be massively cpu intensive.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 17, 2013 at 7:42 PM
HashKeyCopier - An AngularJS Utility Class For Merging Cached And Live Data
Ben - thanks so much for posting these Angular articles and findings, they've been a huge help towards learning one of the more 'complex' JavaScript frameworks out there (IMO). I have been using Angu ... read »
May 16, 2013 at 5:01 PM
UPDATE: Parsing CSV Data Files In ColdFusion With csvToArray()
Your code was the closest thing I've found to obtaining some direction for converting ISO fields to values that CF can translate properly. Thank you for posting! ... read »
May 15, 2013 at 10:37 PM
Very Simple Pusher And ColdFusion Powered Chat
hi id making plz easy ... read »
May 15, 2013 at 6:07 PM
Making SOAP Web Service Requests With ColdFusion And CFHTTP
Ben, you once again saved my bacon at work. Thank you, thank you, thank you! ... read »
May 15, 2013 at 4:15 PM
What If All User Interface (UI) Data Came In Reports?
@Josh, Thanks! @Ben, I definitely recommend the David West book "Object Thinking" I've been quoting from. It goes deeply into the philosophy and history of OO programming. His breadth ... read »
May 15, 2013 at 11:36 AM
Ask Ben: Print Part Of A Web Page With jQuery
I found this helpfull when you need to keep (refresh) the original parent page after closing the iframe child print dialog (Hoping you're not using a form at this time so it won't submit again): On ... read »
May 14, 2013 at 7:13 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, If there's any books you'd recommend on the subject of domain modelling, I'd love to hear it. I just downloaded the free PDF of "Domain Driven Design Quickly". Figured I'd give it ... read »
May 14, 2013 at 6:57 PM
The UX Of Prototyping: Low-Fidelity Is The New High-Fidelity
@Phillip, I'm not sure I follow what you mean? Are you saying that you looked at the list of widgets provided by the jQuery UI and let that be your style guide? ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools