Kola Oyedeji looks at how the ColdFusion scripting language has been adapted to integrate into the world of Java EE.
Integrating ColdFusion and Java EE
ColdFusion has been around long enough, and in different forms, that it's easy to not see it for what it is. In this article, Kola Oyedeji looks at how this long-lived scripting language has been adapted to integrate into the world of Java EE.
Forget Ruby on Rails; in this article I outline why, as a Java
developer, you should perhaps be looking to another technology
closer to home to leverage your existing in-house skills and
infrastructure. We'll briefly touch on some of the
features of ColdFusion , the
Java-EE-based application server from Adobe, and discuss why
ColdFusion is more relevant today for Java developers than it has ever
A Brief History Lesson
ColdFusion is one of the older scripting languages, first
introduced in 1995. It is a little-known fact that Microsoft was
once interested in acquiring Allaire, the original creators of
ColdFusion. When Allaire showed a lack of interest, Microsoft then
went on to purchase another company whose product formed the basis
of their ASP technology.
ColdFusion, which was an application server written in C++,
underwent a complete overhaul a few years ago, most notably a
rewrite in Java that has resulted in recent Java-based versions
being labelled with the "MX" suffix.
ColdFusion comes in three editions that are available on Linux,
UNIX, Windows, and Mac OS X: a free developer edition (restricted to
two IP addresses and localhost), a standard edition, and an
The standard edition is bundled with the JRun application server ,
one of the oldest J2EE application servers (with a long history), but
access to the underlying application server is restricted. The
enterprise version allows full access to the underlying application
server, allowing you to deploy both ColdFusion and your ColdFusion
applications as an EAR or WAR file on any of the supported
J2EE application servers. The benefits of these applications include:
- Share Java EE sessions between ColdFusion and EE
- Contain ColdFusion pages that include JSP pages, or vice versa
(i.e., JSP pages that include ColdFusion pages).
- Call ColdFusion components from Java (more on ColdFusion
- Create hybrid ColdFusion and Java applications that utilize
ColdFusion and Java servlets for the presentation layer and POJOs
or EJBs for the business services layer.
With the enterprise edition you can still capitalize on the
enterprise scalability, transaction support, messaging, etc. built
in to Java EE servers, and the knowledge of administration of these
OK, But Why Should I Use It?
The most compelling reason to use ColdFusion is productivity. As
with many dynamically typed scripting languages, there is no need
to build, deploy, or restart your app server. ColdFusion pages are
written in ColdFusion Markup Language (CFML), a tag-based markup
language similar to JSP tags and JSTL. With it, you simply save and
refresh your browser to view your latest changes. ColdFusion
compiles .cfm pages into Java servlets in much the same way
as JSP. However, compilation is done in memory and not to disk. The
compiled class is then cached in memory for subsequent calls to the
The second, and perhaps more pertinent, reason it is better suited
to Java developers than other languages is that you can make
seamless calls to all the built-in Java libraries, as well as those
bundled with ColdFusion and any custom APIs of your own. All
versions of ColdFusion have access to all of the core Java classes.
ColdFusion is a Java EE application, allowing you to leverage
existing Java libraries and code bases.
Much of the functionality available in ColdFusion is provided by
the bundled Java APIs and products that Java developers are
already familiar with, such as Apache Axis, JasperReports, log4J,
iText, J-integra, and JBuddy, to name but a few. All of these are
easily accessed using ColdFusion's simple tag-based language or its
alternative scripting syntax, CFScript. CFScript is based on
ECMAscript and is used by wrapping your code in
cfscript tags. Java
developers in particular may feel more at home with this
The following example illustrates how Java classes are used in
ColdFusion. To call a particular constructor from ColdFusion, there
is a special method called
init() that should be
called with the relevant arguments:
//to create an instance of a class calling a constructor...
myObj = createobject("Java","Java.lang.Someclasss").init(some,args);
someResult = myObj.someMethod();
ColdFusion and JSTL
JSP developers will notice similarities between the syntax of
JSTL and ColdFusion tags. Unlike JSTL, ColdFusion contains a much
larger set of tags and almost 300 functions for string
processing, date and time manipulation, encryption, XML, and more.
Although you can use Java classes or libraries directly, using the
built-in ColdFusion tags such as
CFMAIL make light work of many things such as creating
PDF documents, retrieving remote files via FTP, and sending
Sending an HTML email with the
CFMAIL tag, for
example, is as simple as:
<title>Our HTML newsletter</title>
Who needs Ruby...
Just as simple is creating a PDF from an HTML document using the
<cfdocument format="PDF" orientation="portrait">
<title>My html document</title>
<link rel="stylesheet" type="text/css" href="style.css">
The following line is all that is needed to apply an XSL
stylesheet to an XML document to perform a transformation:
<cfset myTransformedDoc = xmlTransform(originalXmldoc, XSLStylesheet) />
ColdFusion also has its own object-like constructs called
ColdFusion Components (CFCs) that provide for encapsulation,
inheritance, and polymorphism.
Integration Made Easy
ColdFusion has always been known for facilitating easy
integration with other technologies such as CORBA, web services,
and COM. For example, ColdFusion leverages Apache Axis for web
//get a reference to webservice
ws = createObject("webservice",
temperature = ws.getTemp(90210);
Similarly, if you need to connect and call a COM object, the
following code is all that is required:
<cfset myComObject = createObject("COM","excel.application.9") />
As you can see, to communicate with a COM object, there is no need
to download or install a third-party API, providing ease of
integration with Microsoft technologies.
Similar integration can be done on UNIX using ColdFusion
Extension Tags(CFXes). CFXes provide a method of calling native
code on Linux (as well as Windows). ColdFusion ships with a
library, the CFX API, that is required when writing such tags.
CFXes are, however, limited to ColdFusion editions running on UNIX
The advantage of using ColdFusion for your integration is that
you have a built-in, standard set of functions and tags that can be
used to integrate with other technologies. There is no need to
import another third-party library or learn yet another unfamiliar
Another interesting integration feature: ColdFusion has an
adapter that enables direct communication between ColdFusion
components and Adobe
Flex. For those who have not heard of Flex 2 yet, it's is the
latest version of the platform based on Flash for developing rich
internet applications. The Flex platform consists of Flex
builder (an IDE), Flex Data Services (FDS), and a free
compiler. Using Flex, developers can build rich internet
applications in MXML, a tag-based language. It should be noted that
you do not need ColdFusion to integrate with Flex, as an adapter
also exists for Java to talk to Flex directly.
Flex is beyond the scope of this article, but you can find more
info on the Adobe
OK, So It's a Very Large Tag Library on Steroids?
ColdFusion is much more than just a tag library--many of the
other features that would normally require third-party products or
APIs are built in. There is an administrator to enable caching and
scheduling of template execution, a built-in SMS gateway, and a
bundled graphing engine. And once again, the advantage of having all
of this functionality built in is that it frees developers to use
standard libraries instead of having to use (and more importantly
maintain) various versions of different third-party APIs. An
important point to take away from this is that it is not a choice
of Java + JSTL or ColdFusion + ColdFusion components; you can mix
and match where you see fit, creating an architecture that suits
The ColdFusion community has grown up too, with a growth in the
popularity of frameworks such as Mach-ii (an implicit invocation
framework), Fusebox ,
"http://www.model-glue.com/">Model Glue , and ColdSpring , a dependency
injection framework. There is also the open source project named ColdFusion on Wheels , modelled on
Ruby on Rails. The ColdFusion community is embracing agile
development and building applications that make use of common
design patterns. Apache Struts can also be used with ColdFusion
using ColdFusion for your views. Also, there are a number of sites
such as www.cfpetmarket.com that contain
ColdFusion framework versions of a pet-store application.
Finally with the free, open source CFEclipse, an Eclipse-based
plugin fast becoming the de facto IDE for ColdFusion developers,
many Java developers will feel right at home with the development
tools. There is also a commercial Eclipse-based interactive
debugger available called FusionDebug.
But if We Invest in ColdFusion, How Can We Be Sure It Will Be Here Tomorrow?
Twelve years later and having survived both Allaire and Macromedia's
acquisition, it is unlikely ColdFusion will be fading away any time
soon. Adobe is currently working on the next version, codenamed
"Scorpio." In addition, there are alternative ColdFusion engines
that can also run CFML, such as BlueDragon
If you have brushed off ColdFusion in the past in favor of
other complementary technologies, download the free developer's
edition, look at some of the tutorials, and give it a second look. You might just realize what a good fit ColdFusion can be in the
Java enterprise arena.
width="1" height="1" border="0" alt=" " />