Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

Getting Started Integrating CFML with Java & .NET

Integration opens some cool doors

It's great to have a whole issue of CFDJ focused on integrating CFML with Java. The process is a lot easier than many might think, as the articles in this issue will show.

I'd like to review the very basics to get you started, showing some of the cool doors of opportunity that this integration opens. Perhaps more important for some, though, I'd like to also point out that direct integration of CFML with .NET is also possible.

Surprised to hear about direct integration of CFML with .NET? You may know that you can call .NET objects through web services in CFMX. But you can also call them directly (as opposed to via a web service, as well integrate CFML and ASP.NET) using BlueDragon's .NET edition. Don't worry. If you're only interested in CF, this article is still for you in its introduction to integrating CFML with Java.

Solutions for CF 4.5/5/MX and BlueDragon
Indeed, even if you're still using CF 4.5 or 5, and never transitioned to CFMX, this article will still apply. Some may be surprised to hear that integration of CFML with Java was introduced in CF 4.5. It's certainly true that the Java-based CFMX and BlueDragon engines make this integration easier; still, it is possible to do Java integration with CF 4.5 and 5. In fact, some readers of CFDJ may recall the excellent 8-part series by Guy Rish from called "A Cold Cup o' Joe", where he introduced many of us for the first time to the idea, benefits, and challenges of doing such CFML/Java integration. He showed how you can install the Java Runtime on your machine and enable access to it from within CFML with a single change to the CF Admin (you can also see the CF 4.5/5 docs for more.) It's great to see him back in this issue, with "Cold Cup o' Joe - Second Shot" and I wish him luck with this new series.

In the first series, Guy showed how to call Java objects from within CFML, as well as how to call upon and integrate CFML with JSPs and Servlets. Of course, with CFMX and BlueDragon both being built upon Java, you don't need to make any changes to leverage Java. It's just built-in. Still, most of Guy's series will still apply and would be highly recommended for further reading. The CFMX docs also now have an entire chapter on CFML/Java integration, available online at http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/java.htm. I certainly don't want to repeat all the information provided in these useful and rich resources.

Why Bother With Java?
We all know that CFML is a wonderfully high-level language. Why would we want to bother with Java? Indeed, the reason we like it and are so productive is that we can do nearly everything we want right from within CFML. Still, some hold this simplicity against CFML, lamenting that if they want to do something that CFML can't do, they feel stuck. You're not. There's an entire world of new possibilities in the form of Java objects and libraries that you can leverage to extend your CFML. These can either be the built-in libraries that come with the Java framework, or that you or others in your organization build, or that you acquire from third parties.

An important point to clarify is that it is not necessary that you know Java to do the kind of integration I'm discussing. For example, there is no CFML tag or function that will return the IP address for a given domain name. But there is a way to get this information by calling the InetAddress class in the Java API. The Java API documentation for this can be found at http://java.sun.com/j2se/1.4.2/docs/api/java/net/InetAddress.html. With a little reading, you'd learn that the GetByName method accepts a host name and returns an InetAddress object for that host name, which then has a getHostAddress method that returns the actual IP address.

The following CFML example demonstrates one way to call on this object and its methods, using CFOBJECT:


<CFOBJECT NAME="iaddrClass"  CLASS="java.net.InetAddress" TYPE="JAVA" ACTION="CREATE">
<CFSET IADDR=iaddrClass.getByName("www.newatlanta.com")>
<CFOUTPUT>#iaddr.getHostAddress()#</CFOUTPUT>

Recall that since CFMX and BlueDragon are built atop the Java API, you have direct access to the Java API and this java.net.InetAddress class. If you run this code (while connected to the internet, since the getByName method does require net access to search for the information about the host name), you will get the following answer:
209.235.23.101

Recall that in order to run this in CF4/5, you need to first modify the CF Admin to enable Java access. See http://livedocs.macromedia.com/coldfusion/ 5.0/Developing_ColdFusion_Applications/cfobject8.htm.

Beyond the built-in objects in the Java API libraries, you can also access any Java class that is (or has been made) available on the JVM classpath (see the CFMX or BlueDragon Admin console) or which has been placed in either of the following locations under either the CFMX or BlueDragon directories:
- WEB-INF/lib (as a Java archive or .jar file)
- WEB-INF/classes (as a .class file)

The subject of creating Java class files is beyond the scope of this article. I'm sure other articles in the issue will cover the topic, and if they don't recall that the Macromedia docs have an entire chapter on CFML/Java integration. It includes some sample Java code to create your own example class file, and discusses how to compile and place the class files. Beyond that, the documentation discusses several other useful topics regarding integration of Java with CFML, including:

  • How cfobject loads the class and makes available any static objects
  • How to use the built-in init() method to call the object's constructor
  • How to use createObject instead of CFOBJECT, where appropriate
  • Passing arguments to methods
  • Handling datatype conversion
  • Resolving datatype ambiguity with Javacast
  • Handling case-sensitivity issues
  • Handling java exceptions
  • Calling EJBs
One last point of interest in this topic is that CFMX 7 has introduced a new option for Javacast to help cast a variable as a null.

The documentation also discusses integration of CFML with JSPs and servlet, which are the Java form of web application scripting. These are also often referred to as part of the J2EE (Java 2 Enterprise Edition) framework. CFMX was built atop a J2EE server (JRun) and can be run atop others (WebLogic, WebSphere, and so on), as can BlueDragon.

What about .NET?
The previous section focused on integrating CFML with Java. What if your organization is moving to the Microsoft .NET Framework? .NET is Microsoft's response to J2EE, and it offers many of the same features that one may find in J2EE development, and more. While CFMX is only available to run atop the J2EE framework, it is possible to run your CFML natively on .NET using BlueDragon for the Microsoft .NET Framework, a product from New Atlanta (disclaimer: that's the company I work for) which offers an alternative implementation of CFML - abbreviated from hereon as BlueDragon/.NET. You don't need ColdFusion at all if you install BlueDragon, though you can also install both CF and BlueDragon at the same time for testing purposes. Why should you care? If your organization is moving to .NET, you may feel you have no choice but to rewrite your investment of CFML as ASP.NET. The fact is, with BlueDragon/.NET, you can simply run your CFML natively on the .NET framework. This is a subject for another entire article, and you can find out more at www.newatlanta.com/bluedragon/. (In fact, there will be a couple of presentations on the subject at the upcoming CFUnited conference.)

But for the sake of this article, I want to point out that you can equally leverage the underlying .NET framework classes from CFML, just as I discussed in the previous section regarding Java. You can call either the built-in classes of .NET (there are more than 4,000 of them) or ones you build or acquire, and again some of them provide information not available otherwise in CFML.

For instance, if you want to know the name of the computer on which the code is running, the following will leverage the .NET framework's Environment class in the "System" namespace, to return the MachineName. (See the .NET documentation for details on this class, at http://msdn.microsoft.com/library/default.asp?url=/ library/en-us/cpref/html/cpref_start.asp.) This CFML will only run on BlueDragon/.NET:


<CFOBJECT ACTION="create" type=".net" NAME="env" CLASS="System.Environment">
<p>Computer Name = <CFOUTPUT>#env.get_MachineName()#</CFOUTPUT>

On my machine, this returns CharlieD600, the name of my machine. Not the most compelling example (more on those in a moment), but it shows how very similar this approach is to the Java examples above. Indeed, besides using a .NET class and its method, there is just one difference.

Note the use of TYPE=".net" rather than TYPE="java" as in the previous examples. In BlueDragon/.NET, you can call any underlying .NET class this way. In fact, you could use TYPE="java" as well, and even run the example provided in the previous section, unchanged. Though it runs atop the .NET framework, BlueDragon/.NET also requires installation of the Visual J# Redistributable runtime environment, which makes most of the same Java API libraries available within .NET, and therefore available to CFML pages running on .NET via BlueDragon. Along the same lines, note that when the CFML code in the .NET example above referred to the MachineName, it used get_MachineName(). The .NET documentation for this class would show that MachineName is a property, rather than a method. But it would also show that when calling the class with Visual J#, one would need to call the property as a method instead. Because of BlueDragon/.NET's underlying reliance on Visual J#, we need to use the same form in our CFML.

Before leaving the subject of .NET integration with CFML, I would add that there is of course a whole lot more that is possible in terms of leveraging underlying .NET libraries, just as there is much more than I showed in the one example of Java integration above. While some of the other articles in this issue (and the Macromedia documentation) will highlight more about Java integration, let me take a moment to show just a little more of what's possible with .NET integration. Here's one more example, that uses CFML to display the foreign languages available in .NET for supporting globalization:


<cfobject name="culturetypes" class="System.Globalization.CultureTypes"
action="CREATE" type=".net" >
<cfobject name="cultures" class="System.Globalization.CultureInfo"
action="CREATE" type=".net" >
<cfset cultarray=cultures.getcultures(culturetypes.NeutralCultures)>
<cfloop from="1" to="#arraylen(cultarray)#" index="i">
	<cfoutput>#cultarray[i].get_NativeName()#
	(#cultarray[i].get_Name()#)
</cfoutput> </cfloop>

A subset of the result shown would include:

But even beyond this, the .NET framework offers so much more. There is built-in support for calendar, datagrids, adrotators, and so much more. It would be possible to show how to implement even these features within CFML, but again this is beyond the scope of this article. The discussions presented here should be enough to get you started and motivate further interest.

Other Resources for Getting Started
Before concluding, I'd like to point out a few resources to learn more about CFML integration with Java and .NET. Beyond the Macromedia documentation I mentioned above, there are other resources you can turn to in order to learn more about CFML integration and Java. There are two books that cover the topic:
Java for ColdFusion Developers, by Eban Hewitt
Reality J2EE: Integrating ColdFusion and J2EE, by Ben Forta, et al
JRun Web Application Construction Kit, by Drew Falkman

While the latter really isn't about CFML, since CFMX runs atop JRun, it provides the same kind of friendly introduction to leveraging JRun and J2EE in general that was modeled in the infamous ColdFusion Web Application Construction Kit.

For more on BlueDragon/.NET, there is an entire manual, Deploying CFML on ASP.NET Servers, with many examples. It's available with the download/install of BlueDragon/.NET, or it's available online at www.newatlanta.com/products/bluedragon/ self_help/docs/6_2/BlueDragon_62_CFML_on_ASP_NET.pdf.

You can also find all the articles in Guy Rish's excellent series from the following link: http://cfdj.sys-con.com/author/113Rish.htm.

More Stories By Charlie Arehart

A veteran ColdFusion developer since 1997, Charlie Arehart is a long-time contributor to the community and a recognized Adobe Community Expert. He's a certified Advanced CF Developer and Instructor for CF 4/5/6/7 and served as tech editor of CFDJ until 2003. Now an independent contractor (carehart.org) living in Alpharetta, GA, Charlie provides high-level troubleshooting/tuning assistance and training/mentoring for CF teams. He helps run the Online ColdFusion Meetup (coldfusionmeetup.com, an online CF user group), is a contributor to the CF8 WACK books by Ben Forta, and is frequently invited to speak at developer conferences and user groups worldwide.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use of real time applications accelerate, legacy networks are no longer able to architecturally support cloud adoption and deliver the performance and security required by highly distributed enterprises. These outdated solutions have become more costly and complicated to implement, install, manage, and maintain.SD-WAN offers unlimited capabilities for accessing the benefits of the cloud and Internet. ...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
I think DevOps is now a rambunctious teenager - it's starting to get a mind of its own, wanting to get its own things but it still needs some adult supervision," explained Thomas Hooker, VP of marketing at CollabNet, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Major trends and emerging technologies – from virtual reality and IoT, to Big Data and algorithms – are helping organizations innovate in the digital era. However, to create real business value, IT must think beyond the ‘what’ of digital transformation to the ‘how’ to harness emerging trends, innovation and disruption. Architecture is the key that underpins and ties all these efforts together. In the digital age, it’s important to invest in architecture, extend the enterprise footprint to the cl...
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
Two weeks ago (November 3-5), I attended the Cloud Expo Silicon Valley as a speaker, where I presented on the security and privacy due diligence requirements for cloud solutions. Cloud security is a topical issue for every CIO, CISO, and technology buyer. Decision-makers are always looking for insights on how to mitigate the security risks of implementing and using cloud solutions. Based on the presentation topics covered at the conference, as well as the general discussions heard between sessio...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
No hype cycles or predictions of zillions of things here. IoT is big. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, Associate Partner at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He discussed the evaluation of communication standards and IoT messaging protocols, data analytics considerations, edge-to-cloud tec...
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
CloudEXPO | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.