The Largest Repository of ColdFusion Knowledge in The World for More Than 12 Years

ColdFusion on Ulitzer

Subscribe to ColdFusion on Ulitzer: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get ColdFusion on Ulitzer: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

CFDJ Authors: AppDynamics Blog, Michael Kopp, Tad Anderson, Bob Gourley, Jayaram Krishnaswamy

Related Topics: ColdFusion on Ulitzer, Online Shopping, Java Developer Magazine

CFDJ: Article

An Online Ticket Store- The Storefront

An Online Ticket Store- The Storefront

In the August issue of CFDJ we walked through the development of a custom CF_Servlet tag that would allow ColdFusion to access Java functionality on the server side via Java servlets. In subsequent issues of JDJ I developed the Online Ticket Store application for the Java modules. In order to provide self-contained modules for ColdFusion readers, I'd like to set the context for the design of the modules that have been developed in ColdFusion. Before doing that, however, I want to point out some interesting developments at Allaire that have a direct bearing on this article.

For one thing, the first article in this series generated more feedback than I expected. It has been a pleasant surprise to know that a few companies actually have airline store sites developed in ColdFusion similar to the fictitious one I've developed through this article series. I've also received e-mail that indicated folks took this application more seriously than I thought they would. These readers concluded that this is a real-world application. While the design of the application outlines a real-world architecture for a business problem and serves as a template for a real-world solution, it's not a production-level system.

Another interesting development was that Allaire acquired Live Software. Most of you are aware of this merger, which happened in June when JavaOne was in progress. While there I spoke with Jeremy Allaire (ColdFusion) and Paul Colton (JRun) about this development ­ a smart move on Allaire's part in my opinion. A few months before, Allaire had acquired Bright Tiger Technologies, a company that specializes in clustering technology. The acquisition of JRun makes Allaire's app server story complete. ColdFusion is a great product and I've always felt that they needed a story on the Java side. That was part of my motivation for building the Online Ticket Store application. Coincidentally, the August issue of CFDJ featured two articles with two individual CF_SERVLET tags ­ the professional one from Live Software and my own.

As the first part of this series was dedicated exclusively to the development of the CF_Servlet tag, I'll begin this article with a description of the application. (Readers who have been following this series in JDJ can skip the following section.) The Online Ticket Store Application

The design of the Online Ticket Store illustrates the use of ColdFusion and the Java platform for building a simple Internet-based Ticket Store application. This application offers online purchase of airline tickets as well as goods sold in airports. One of the objectives of this design is to illustrate how Java servlets can be used as access mechanisms in server modules that serve up data to front-end storefront modules implemented in ColdFusion. The data format for information exchange between the CF page and the Java servlet is XML.

The Online Ticket Store is an Internet-based application that allows an Internet user to log in and purchase tickets via a browser. The store is a front end for the services offered via airline-agency back offices. These back-office locations provide ticket price/availability information and accept ticket reservations. The store offers the following services:

  • It acts as a "ticket agent," and may be used to purchase tickets, comparison-shop between different airlines and determine flight itineraries.
  • It provides an interface to a virtual airline store that allows catalog sales of merchandise such as clothes, appliances, computer equipment and other goods usually offered in airline magazine catalogs.
  • In addition, the store allows Internet users to lease equipment that they can use during the course of the flight. The equipment includes laptops and printers, portable CD players and music CDs. The idea is that a person who uses the Internet to reserve a flight can also instruct the airline to have the leased equipment available on the flight he or she will be taking. The passenger will have the equipment available when he or she boards, and will surrender it on leaving the plane.

    The software components that make up the Online Ticket Store, their functions and the technologies used for their implementation are defined in Table 1. We're not too concerned about the airline's back offices. Rather, our focus on the back office is limited to the mechanisms used to access the services offered by the back office. For example, a discussion on how an airline prices and reserves tickets is beyond the scope of this article, as are security issues involved in transporting the data.

    Application Framework
    The framework for this application is distributed among the following tiers:

  • Client UI: This is the end-user interface into the Ticket Store. The Client UI is responsible for the front-end interaction with the customer and the connection to the data tier that maintains the Internet user's data and conducts transactions with the Internet user. In our application this is typically a Web browser.
  • Merchant Server tier: This is where the application server that serves data to the Client UI resides. It has a data store for the customer's profile and maintains the shopping cart, catalog for merchandise, and so forth. It interacts with the Services Access tier to get information from the various data sources (airlines).
  • Services Access tier: This is a middleware tier that accepts service requests from the Application Server tier, routes them to the Application Services tier and serves back the response to the Merchant Server tier.
  • Application Services tier: This tier offers the ticket price/availability quote services.

    Figure 1 illustrates the application framework tiers.

    ColdFusion Application Modules
    The application modules for the entire application are illustrated in Figure 2. In our application ColdFusion is used to implement the modules in the Merchant Server Tier and to generate the Web pages for the browser-based Client UI. As it's beyond the scope of this article to implement all the modules in this tier, I'd like to "scope down" the application to fit. In this particular article we'll walk through a single workflow that enables a customer to submit his or her query for the best available flight, book the tickets, then lease some equipment for the duration of the flight. The Personal Profile Manager, Customer Profile Database and Catalog are implemented as simple database tables. The Shopping Cart and Payment Manager aren't implemented here. The Login Manager is implemented via a simple CF page.

    So what part of the Online Store application will we design here? Well, there is method to my madness. Some modules that have been skipped here will be implemented in later articles. Others, such as the Shopping Cart, are common and you should be able to pick them up from The ColdFusion Web Application Construction Kit by Ben Forta or from other ColdFusion references.

    The modules we'll address here are the ones that make use of the connectivity between Java servlets and ColdFusion pages, the very core of this article series: the Ticket Sales and Reservation Broker and the Merchandising Sales and Leasing Broker. I won't go over the complete design of these modules as they've been discussed in detail in the referenced JDJ issues; also, most of the modules have been implemented in Java. The modules that are implemented in ColdFusion enable the higher level workflow for the end user.

    The complete use case consists of the following steps:
    1. The User logs in.
    2. Upon successful login, the User enters the criteria for ticket availability search.
    3. Criteria are submitted as an XML object to the Ticket Sales and Reservation Broker via the TicketBrokerServlet.
    4. The result of the query is returned from the servlet as an XML string. The string is parsed and the result is displayed to the User.
    5. The User is prompted to book the ticket(s).
    6. If the User elects not to book the tickets, the use case ends here.
    7. If the User chooses to book the tickets, an XML BookingRequest object is sent to the Servlet.
    8. A Confirmation object is returned from the Servlet to the User. The XML object is parsed and the result is displayed to the User.
    9. The User is prompted to lease equipment for the flight.
    10. If the User elects not to lease equipment, the use case ends here.
    11. If the User chooses to lease equipment, a list of products is displayed.
    12. The User selects the equipment to lease.
    13. The request is sent to the StoreServlet as an XML Lease object.
    14. A Confirmation object is returned from the Servlet to the User. The XML object is parsed and the result is displayed to the User.

    Data between the Java servlets (StoreServlet and TicketBrokerServlet) is exchanged in the form of XML strings. In the CF world WDDX could have been used to serialize data input from the user and the servlets could then have parsed the resultant string. However, in defining the connectivity beween the servlets and ColdFusion, XML offers a more generic format. This will allow our Application Services Tier to interface with other front ends that understand XML (and not necessarily WDDX).

    Storefront Implementation
    To implement this workflow I developed six ColdFusion pages. Steps 1 and 2 of the use case above are trivial and won't be discussed here. The pages are shown in Listings 1 through 4 and the screen captures are illustrated in Figures 3 through 8. Descriptions of the pages are given below. (The custom tag, servlet.cfm, was described in the August CFDJ and is not repeated here. Descriptions of the TicketBrokerServlet and the StoreServlet were provided in the corresponding articles in JDJ.) The pages are currently hard-coded, i.e., they don't get data from an actual database. The purpose of this exercise is to demonstrate how the TicketBrokerServlet and the StoreServlet can be used for ticket reservation and equipment lease operations, respectively. Under the assumption that readers are familiar with XML, I haven't provided any discussion on XML parsing and usage.

    The complete Java and CF code is available at

    Listing 1: ticket_query.cfm
    This page is responsible for inputting the criteria for the flight availability search and passing on the information to the next page, which in turn calls the TicketBrokerServlet. The code in this file is fairly simple. In all of the pages the first code checks to see if the parameter "trace" has been passed in. If it has, and if it's set to "ON," the consequent pages will display debugging output.

    <CFIF IsDefined("trace")>      <CFIF trace IS "ON"> <i><b>Trace is ON</i></b><BR><BR>
         CFSET trace="OFF">

    The code basically consists of a form that accepts user input and passes it on to the next page (invokeTicketBrokerServlet.cfm). Figure 3 shows the screen for this.

    Listing 2: invokeTicketBrokerServlet.cfm
    The code in this file accomplishes three things:
    1. Formats the date passed from the previous page into XML
    2. Invokes the TicketBrokerServlet (via the CF_Servlet tag) and passes the XML string to the server for processing
    3. Displays the results of the query

    Figure 4 shows the entire page for this file. The XML formatting is straightforward. There are parsers available in scripting (e.g., Xparse for JavaScript) that I could have used, but I chose not to complicate the code. The elements of the XML string are created and then concatenated into the "xml_string" variable. Remember that if the server accepted WDDX, we could have serialized the data into WDDX objects and then passed it to the server environment. However, we're working under the premise that the server side accepts XML.

    Next, the TicketBrokerServlet is invoked via the CF_Servlet tag. The details of how this works are available in the August CFDJ, which is on the SYS-CON Web site.

    <CF_Servlet servletclass=TicketBrokerServlet
           trace=#trace# method=POST

    Last, the result is displayed. HTMLEditFormat is used so the reader can view the XML tags also. This output should be parsed and displayed to the user. However, for the purposes of this exercise I have demonstrated only the XML that came back from the servlet.

    <CFOUTPUT><BR><BR><B><I>Result = </i></b>#HTMLEditFormat(result)#

    Three parameters, ReferenceNo, Airline and Price, are passed to the next page and are thus manually parsed from the XML string returned by TicketBrokerServlet. ReferenceNo is used for all future references to the transaction in this particular use case. At this stage the user can go on to book the ticket or cancel. If the "Book Tickets" button is pressed, the next screen shows up.

    Listing 3: get_names.cfm
    This is a simple page that accepts the names of the passengers. Up to eight names are allowed. Figure 5 illustrates the form for this page.

    Listing 4 : book_tickets.cfm
    This file is similar in functionality to invokeTicketBrokerServlet. It uses the parameters passed from the previous two pages to create a booking request (in the form of an XML string) for the tickets that is passed to the TicketBrokerServlet. Note that this is the second invocation of the TicketBrokerServlet. The result of this second invocation is parsed and displayed. The result is a simple Confirmation Number. For simplicity I have kept this number the same as the reference number originally returned. Figure 6 illustrates the screen for this page.

    At this point the user can select "Done" or go on to lease equipment for the flight by pressing the "Go to Lease Equipment" button. Figures 7 and 8 illustrate the next two screens.

    Salient Features
    Obviously, this is a very simplified version of a real use case. A lot more database and graphics design will go into actually developing the storefront for this application. However, I hope the code described here serves to illustrate how Java servlets and ColdFusion can be used in conjunction to create a business application. Some of the points:

  • There is a continuity in the workflow, illustrated by the two-step process for searching for a flight and then booking the actual tickets. Note that the TicketBrokerServlet maintains state for the duration of this transaction.
  • Once the custom tag is available (whether my hacked version or Allaire's professional one), it's simple to invoke Java servlets from ColdFusion. This opens up a whole new world ­ that of Java ­ for ColdFusion applications. Servlets are Java's gateway to the server side. By using a custom tag, it's simple to get access to server-side functionality.
  • Server-side functionality can be distributed across different servlets. In this application CF provides the synchronous user workflow that works across different servlets (TicketBrokerServlet and StoreServlet).

    I hope to develop this application further to bring out other interesting aspects of Allaire's current initiative to integrate with Java APIs.

  • More Stories By Ajit Sagar

    Ajit Sagar is Associate VP, Digital Transformation Practice at Infosys Limited. A seasoned IT executive with 20+ years experience across various facts of the industry including consulting, business development, architecture and design he is architecture consulting and delivery lead for Infosys's Digital Transformation practice. He was also the Founding Editor of XML Journal and Chief Editor of Java Developer's Journal.

    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.