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")>

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:

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> </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
"When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
The Internet giants are fully embracing AI. All the services they offer to their customers are aimed at drawing a map of the world with the data they get. The AIs from these companies are used to build disruptive approaches that cannot be used by established enterprises, which are threatened by these disruptions. However, most leaders underestimate the effect this will have on their businesses. In his session at 21st Cloud Expo, Rene Buest, Director Market Research & Technology Evangelism at Ara...
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...
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 examined how DevOps helps to meet the de...
When growing capacity and power in the data center, the architectural trade-offs between server scale-up vs. scale-out continue to be debated. Both approaches are valid: scale-out adds multiple, smaller servers running in a distributed computing model, while scale-up adds fewer, more powerful servers that are capable of running larger workloads. It’s worth noting that there are additional, unique advantages that scale-up architectures offer. One big advantage is large memory and compute capacity...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assista...
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company, specialized 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 acr...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 21st Int\ernational Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to focus on the core of their ...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
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 looked 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 deliver...
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), provided an overview of various initiatives to certify the security of connected devices and future trends in ensuring public trust of IoT. Eric Lachapelle is the Chief Executive Officer of the Professional Evaluation and Certification Board (PECB), an international certification body. His role is to help companies and individuals to achieve professional, accredited and worldwide re...