|By Guy Rish||
|August 8, 2001 12:00 AM EDT||
Prior to ColdFusion 4.5 a developer could only write CFX tags in a binary language that supported the dynamic linking capabilities of the target platform.
For Windows it was C/C++ and Delphi and the like, any language that could create a DLL. For the UNIX platforms, it was pretty much the same thing - only with shared objects. Naturally anytime a CFX was distributed it needed to be compiled for the different platforms or the source code was required - which is assuming, of course, that the CFX was even designed to be ported!
Now that CFX tags can be written in Java it is a write once and run anywhere strategy, which is already one of the major pillars of the Java philosophy. This makes things simple: unless native calls are made, the CFX is guaranteed to run on both platforms without change.
Keeping It Simple
The folks at Allaire did us (the ColdFusion developer community) a wonderful service by making the Java CFAPI fairly simple. In fact, creating a basic custom tag is no more difficult than implementing a Java interface.
public interface CustomTag
public void processRequest(Request request, Response response)
The CustomTag interface in the CFAPI has only one method to implement: processRequest. This method receives two arguments, a Request object and a Response object, both from the CFAPI. It is through these two objects that the Java CFX receives information and provides output.
The CFAPI Model
All of the classes and interfaces of the CFAPI are shown in the UML model (see Figure 1).
There are a number of other classes and interfaces in the CFAPI library, but most of them are not designed for direct interaction with the developer. These are the native bindings and wrappers that hook into the Cold-Fusion Server. Of all of the classes in the CFAPI, there are only four you are likely to use directly: CustomTag, Request, Response, and Query.
This interface is the basis for all the custom tags derived from the CFAPI. Every tag must implement this interface in order for the ColdFusion Server to be able to hook it. There is only one method signature that needs to be implemented: processRequest (see Table 1). This method receives instances of two of the other classes: Request and Response.
This interface provides a way for the custom tag to receive information from the system or the calling logic (see Table 2).
This interface provides a way for the custom tag to return information to the calling logic (see Table 3).
This interface provides a way for the developer to manipulate a recordset (see Table 4).
I fear that I must exercise that tired example again; Listing 1 is a simple "Hello, World" Java CFX. As can be seen on Line 14, tag attributes can be retrieved through the Request object by means of the getAttribute method. As seen in Line 19, output can be returned to the ColdFusion Server by using the write method of the Response object.
Registering a Java CFX
As with their binary cousins, Java CFXs need to be registered in the ColdFusion Administrator. The process is fairly simple and - like almost all things in ColdFusion - does not require drilling through many screens.
The CFX Tags panel can be accessed from the ColdFusion Administrator. Starting from the left-hand navigation, under the Extensions menu is the hyperlink "CFX Tags". All the registered CFXs (binary and Java) are shown on the main CFX registration screen shown in Figure 2.
Enter a name for the CFX, set the type to be Java, and press the "Add" button. This will direct you to the second screen in the registration process, shown in Figure 3.
This screen is comprised of three entry fields: Tag Name, Class Name, and Description. The Tag Name field is the name by which the CFX will be referenced from within the template. In the case of the "Hello, World" example, created in Listing 1, I entered "Hello". So whenever the interpreter encounters a "cfx_hello" it will know to load the class file for this tag.
The Class Name entry specifies the class implementing the CFX's functionality. This class must exist somewhere in the CLASSPATH setting of the ColdFusion Server (configurable from the Java Setting panel, see Part 1 of this series in CFDJ, Vol. 3, issue 1).
When necessary, be certain to use the full class name with package path. Typically I put my CFXs (Java or otherwise) in the CFX subdirectory of the ColdFusion Server installation directory. This runs a little contrary to certain recommendations made in the ColdFusion documentation, which I will discuss later. The Description field is optional and can be used to describe the functionality of the library registered.
Testing the CFX
It is important to test the newly registered CFX since the Cold-Fusion Server does not verify any of the registration information until the CFX is first called. In the case of our "Hello, World" CFX this is rather simple. In Listing 2 I have created a simple template that called the "cfx_hello" tag in the body of an otherwise empty HTML document.
Now that you have a grasp of the basics, let's step it up a bit. As a rule, CFXs cannot pass or return complex data types (the sole exception to this is the CFML query type). More specifically, the ColdFusion Server will allow for one CFML query to be passed into the CFX and one to be passed back. You can pass a CFML query in by specifying the name of the query in an attribute to the CFX named Query.
A reimplementation of the "Hello, World" CFX, shown in Listing 3, demonstrates how to work with an incoming CFML query. The template, shown in Listing 4, will query a database to retrieve a list of names, which it will pass to the CFX through the Query attribute.
The CFX is not that much of a departure from the "Hello, World" code in Listing 1. However, instead of receiving a single name in the attribute Name, the incoming query is looped over and the Name column is concatenated.
During development, code often gets changed rapidly and must be tested just as rapidly - and CFX tags are no exception. However, trying to rerun a Java CFX is not as simple as rerunning a newly compiled application. Once the CFX has been loaded by the JVM, it stays cached and the ColdFusion Server must be restarted to flush it from the JVM. The DebuggingFactory I created for Part 4 of this series (CFDJ, Vol.3, issue 6) is of little use here since the ColdFusion Server is invoking the CFX class and cannot be made to use that class.
There is actually a way to hijack Allaire's CFX class loader, but it's a sticky operation at best. The ColdFusion 4.5 documentation (Developing Web Applications with ColdFusion, Chapter 18: "Building Custom CFAPI Tags") states that if CFXs are deployed in the same configured directory as the cfx.jar file, the ColdFusion Server will check the timestamp on the class file and reload it if there have been changes. This can be further ad-justed by passing an additional attribute to the CFX called Reload. For CFXs stored in the configured directory, the Reload attribute indicates to the ColdFusion Server whether the timestamp should be checked and what the reload rule should be (see Table 5).
This same documentation recommends that all Java CFX tags should be both debugged and deployed from this location. I would recommend against deploying production class files from the location for two reasons:
1. There is an additional performance hit to check the CFX class file each time for modifications.
2. It is a potential security risk to have a deployed production environment module reload without an explicit administrator request.
This situation gets a little better in ColdFusion 5.0, but the points I've made still remain.
For all their power (all CFXs - binary and Java alike), there are inherent limitations in the CFX model. These limitations have existed since the introduction of the CFX architecture and will continue to persist through version 5.0 (the Windows version being just newly available at the time of the writing of this article).
CFX tags can only be singular tags. This means there's no end tag, and thus no body or subordinate tags. This effectively makes CFX tags analogous to simply executing external programs.
Limited Relationship to Calling Logic
Undoubtedly CFX tags enhance the available power of the ColdFusion Server, but their implementation model hobbles them some. There is little connection with the calling logic of the CFX. There is no way for the CFX to find out information about its parent tag, it cannot trace the tag stack or access the Caller scope as other CFML-based tags do.
Complex Data Types
With the sole exception of a single incoming and outgoing query, no complex data types may be passed in or out of the CFX tag. This is a severe limitation that has not been corrected even in version 5.0 (there is a work around that I will discuss later in this series).
Difficulty in Debugging
Since the ColdFusion Server does not have specific hooks in it for stepping specific binary code or Java bytecode into either platform, debugging CFX tags can be difficult. Allaire has provided a number of classes to assist with this, but it isn't a silver bullet to the problem.
Wrapping It Up
Given the simplicity of writing CFXs in Java and the extensive libraries available, it makes sense to write tags in this manner. They are often more robust in functionality and frequently faster in execution than tags written in CFML. Naturally tags written in C/C++ will have better performance, but in many cases the loss of platform independence and thus the need to maintain two different code bases outweighs that gain.
In Part 6, I'll introduce you to some of the more advanced features of the CFX model, the recommended Allaire debugging techniques, and a couple of the benefits of using the JVM.
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. In his Day 3 Keynote at 20th Cloud Expo, Chris Brown, a Solutions Marketing Manager at Nutanix, will explore t...
Mar. 24, 2017 02:45 PM EDT Reads: 2,476
What if you could build a web application that could support true web-scale traffic without having to ever provision or manage a single server? Sounds magical, and it is! In his session at 20th Cloud Expo, Chris Munns, Senior Developer Advocate for Serverless Applications at Amazon Web Services, will show how to build a serverless website that scales automatically using services like AWS Lambda, Amazon API Gateway, and Amazon S3. We will review several frameworks that can help you build serverle...
Mar. 24, 2017 01:30 PM EDT Reads: 1,493
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 20th Cloud Expo, which will take place on June 6-8, 2017 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 add...
Mar. 24, 2017 01:15 PM EDT Reads: 410
SYS-CON Events announced today that Linux Academy, the foremost online Linux and cloud training platform and community, 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. Linux Academy was founded on the belief that providing high-quality, in-depth training should be available at an affordable price. Industry leaders in quality training, provided services, and student certification passes, its goal is to c...
Mar. 24, 2017 01:15 PM EDT Reads: 3,780
What sort of WebRTC based applications can we expect to see over the next year and beyond? One way to predict development trends is to see what sorts of applications startups are building. In his session at @ThingsExpo, Arin Sime, founder of WebRTC.ventures, will discuss the current and likely future trends in WebRTC application development based on real requests for custom applications from real customers, as well as other public sources of information,
Mar. 24, 2017 12:45 PM EDT Reads: 232
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of 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. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
Mar. 24, 2017 12:45 PM EDT Reads: 1,805
FinTech is the sum of financial and technology, and it’s one of the fastest growing tech industries. Total global investments in FinTech almost reached $50 billion last year, but there is still a great deal of confusion over what it is and what it means – especially as it applies to retirement. Building financial startups is not simple, but with the right team, technology and an innovative approach it can be an extremely interesting domain to disrupt. FinTech heralds a financial revolution that...
Mar. 24, 2017 12:30 PM EDT Reads: 2,952
SYS-CON Events announced today that Loom Systems 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. Founded in 2015, Loom Systems delivers an advanced AI solution to predict and prevent problems in the digital business. Loom stands alone in the industry as an AI analysis platform requiring no prior math knowledge from operators, leveraging the existing staff to succeed in the digital era. With offices in S...
Mar. 24, 2017 12:15 PM EDT Reads: 882
Keeping pace with advancements in software delivery processes and tooling is taxing even for the most proficient organizations. Point tools, platforms, open source and the increasing adoption of private and public cloud services requires strong engineering rigor - all in the face of developer demands to use the tools of choice. As Agile has settled in as a mainstream practice, now DevOps has emerged as the next wave to improve software delivery speed and output. To make DevOps work, organization...
Mar. 24, 2017 12:15 PM EDT Reads: 1,324
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 ...
Mar. 24, 2017 12:00 PM EDT Reads: 1,821
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of 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. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and management into a ...
Mar. 24, 2017 12:00 PM EDT Reads: 1,582
Deep learning has been very successful in social sciences and specially areas where there is a lot of data. Trading is another field that can be viewed as social science with a lot of data. With the advent of Deep Learning and Big Data technologies for efficient computation, we are finally able to use the same methods in investment management as we would in face recognition or in making chat-bots. In his session at 20th Cloud Expo, Gaurav Chakravorty, co-founder and Head of Strategy Development ...
Mar. 24, 2017 11:30 AM EDT Reads: 3,282
Interoute has announced the integration of its Global Cloud Infrastructure platform with Rancher Labs’ container management platform, Rancher. This approach enables enterprises to accelerate their digital transformation and infrastructure investments. Matthew Finnie, Interoute CTO commented “Enterprises developing and building apps in the cloud and those on a path to Digital Transformation need Digital ICT Infrastructure that allows them to build, test and deploy faster than ever before. The int...
Mar. 24, 2017 10:55 AM EDT Reads: 379
In today's enterprise, digital transformation represents organizational change even more so than technology change, as customer preferences and behavior drive end-to-end transformation across lines of business as well as IT. To capitalize on the ubiquitous disruption driving this transformation, companies must be able to innovate at an increasingly rapid pace. Traditional approaches for driving innovation are now woefully inadequate for keeping up with the breadth of disruption and change facing...
Mar. 24, 2017 10:45 AM EDT Reads: 10,577
SYS-CON Events announced today that CA Technologies has been named “Platinum Sponsor” of 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, and the 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 ...
Mar. 24, 2017 10:45 AM EDT Reads: 1,351