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
SYS-CON Events announced today that CollabNet, a global leader in enterprise software development, release automation and DevOps solutions, will be a Bronze Sponsor of SYS-CON's 20th International Cloud Expo®, taking place from June 6-8, 2017, at the Javits Center in New York City, NY. CollabNet offers a broad range of solutions with the mission of helping modern organizations deliver quality software at speed. The company’s latest innovation, the DevOps Lifecycle Manager (DLM), supports Value S...
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids and Smart Cities, the Industrial Internet, and more. Cool platforms like Arduino, Raspberry Pi, Intel's Galileo and Edison, and a diverse world of sensors are making the IoT a great toy box for developers in all these areas. In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists discussed what things are the most important, which will have the most profound e...
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists will look at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deli...
The explosion of new web/cloud/IoT-based applications and the data they generate are transforming our world right before our eyes. In this rush to adopt these new technologies, organizations are often ignoring fundamental questions concerning who owns the data and failing to ask for permission to conduct invasive surveillance of their customers. Organizations that are not transparent about how their systems gather data telemetry without offering shared data ownership risk product rejection, regu...
SYS-CON Events announced today that Grape Up will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct. 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company specializing in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market across the U.S. and Europe, Grape Up works with a variety of customers from emergi...
The age of Digital Disruption is evolving into the next era – Digital Cohesion, an age in which applications securely self-assemble and deliver predictive services that continuously adapt to user behavior. Information from devices, sensors and applications around us will drive services seamlessly across mobile and fixed devices/infrastructure. This evolution is happening now in software defined services and secure networking. Four key drivers – Performance, Economics, Interoperability and Trust ...
@ThingsExpo has been named the Most Influential ‘Smart Cities - IIoT' Account and @BigDataExpo has been named fourteenth by Right Relevance (RR), which provides curated information and intelligence on approximately 50,000 topics. In addition, Right Relevance provides an Insights offering that combines the above Topics and Influencers information with real time conversations to provide actionable intelligence with visualizations to enable decision making. The Insights service is applicable to eve...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
Cybersecurity is a critical component of software development in many industries including medical devices. However, code is not always written to be robust or secure from the unknown or the unexpected. This gap can make medical devices susceptible to cybersecurity attacks ranging from compromised personal health information to life-sustaining treatment. In his session at @ThingsExpo, Clark Fortney, Software Engineer at Battelle, will discuss how programming oversight using key methods can incre...
Most technology leaders, contemporary and from the hardware era, are reshaping their businesses to do software in the hope of capturing value in IoT. Although IoT is relatively new in the market, it has already gone through many promotional terms such as IoE, IoX, SDX, Edge/Fog, Mist Compute, etc. Ultimately, irrespective of the name, it is about deriving value from independent software assets participating in an ecosystem as one comprehensive solution.
The 20th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held June 6-8, 2017, at the Javits Center in New York City, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Containers, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal ...
SYS-CON Events announced today that Juniper Networks (NYSE: JNPR), an industry leader in automated, scalable and secure networks, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Juniper Networks challenges the status quo with products, solutions and services that transform the economics of networking. The company co-innovates with customers and partners to deliver automated, scalable and secure network...
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists will examine how DevOps helps to meet th...
SYS-CON Events announced today that Hitachi, the leading provider the Internet of Things and Digital Transformation, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Hitachi Data Systems, a wholly owned subsidiary of Hitachi, Ltd., offers an integrated portfolio of services and solutions that enable digital transformation through enhanced data management, governance, mobility and analytics. We help globa...
SYS-CON Events announced today that T-Mobile will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on ...
Five years ago development was seen as a dead-end career, now it’s anything but – with an explosion in mobile and IoT initiatives increasing the demand for skilled engineers. But apart from having a ready supply of great coders, what constitutes true ‘DevOps Royalty’? It’ll be the ability to craft resilient architectures, supportability, security everywhere across the software lifecycle. In his keynote at @DevOpsSummit at 20th Cloud Expo, Jeffrey Scheaffer, GM and SVP, Continuous Delivery Busine...
20th Cloud Expo, taking place June 6-8, 2017, at the Javits Center in New York City, NY, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy.
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo 2016 in New York. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place June 6-8, 2017, at the Javits Center in New York City, New York, is co-located with 20th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry p...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend @CloudExpo | @ThingsExpo, June 6-8, 2017, at the Javits Center in New York City, NY and October 31 - November 2, 2017, Santa Clara Convention Center, CA. Learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
SYS-CON Events announced today that SoftLayer, an IBM Company, has been named “Gold Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. SoftLayer, an IBM Company, provides cloud infrastructure as a service from a growing number of data centers and network points of presence around the world. SoftLayer’s customers range from Web startups to global enterprises.