Online stores are the new, next-generation, "revolutionize the world as we see it today" way of doing business. In the context of business transactions, online stores use the global Internet to facilitate purchase and sale of goods and services. The ability to support online sales is an essential component of the new e-commerce paradigm for Internet-based businesses today. Putting together an enterprise-level application for an Internet store involves design and integration of various technologies that play specific roles in a distributed computing environment. A distributed topology is a prerequisite for building such Internet applications since the Internet is inherently distributed in nature.
Due to the plethora of alternative technologies available in the computing arena today, designing an enterprise application involves choosing between technologies based on feasibility, applicability, cost, availability and several other factors. No solution is "the right one." The hard part is to figure out which technology to use to provide a particular functionality. The challenge is to take competing and complementary technologies and make them play nicely together.
This is the first in a series of articles on some of the prominent technologies available to build a simple Internet-based Ticket Store application. This application offers online purchase of airline tickets as well as goods sold in airports. Our discussion is focused on two popular technologies: Java platform components (Java Applets and Servlets, RMI and JDBC) and Allaire Corporation's ColdFusion application server. The modules implemented using Java technologies will be presented here and in three subsequent issues of Java Developer's Journal. The modules implemented using ColdFusion will be discussed in Volume 1, issues 46, of ColdFusion Developer's Journal.
One objective 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. A simple protocol for exchanging name-value parameters between a Java Servlet running in the middle tier and a ColdFusion engine running in a front-end tier will be used for this purpose.
I'm assuming that readers are familiar with the Java technologies mentioned earlier. Knowledge of ColdFusion is not assumed for the JDJ articles. This article will concentrate on the modules that constitute the application, the technologies used to build the store and the "protocol" for sending data back and forth between the Java components and the ColdFusion templates.
Please note that this is not a real-world application, but one I put together to demonstrate how components and services implemented in an application server (like ColdFusion) and the Java platform may be used to build a distributed e-commerce application. This application will evolve over the next few months. Readers are encouraged to provide feedback if they'd like to take part in defining the scope and design of this application.
The Online Ticket Store
The Online Ticket Store is an Internet-based application that allows an Internet user to log in and purchase tickets via a browser. It accepts credit card payments for purchases and also maintains corporate accounts for its customers. 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:
- Acts as a ticket agent and may be used to purchase tickets, comparison-shop between different airlines and determine flight itineraries.
- 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.
- Allows Internet users to lease equipment for in-flight use, including laptops and printer, portable CD players and music CDs. The idea is that a person who uses the Internet to reserve a flight can instruct the airline to have the leased equipment available on the flight he or she will be taking. The equipment will be available to the passenger on boarding and will be surrendered when he or she leaves the plane.
The software components that make up the Online Ticket Store, their functions and the technologies used for their implementation are illustrated in Table 1.
Only the modules used for ticket transactions are listed. The modules used for building the virtual store will be discussed in a future article. We're not too concerned about the airline's back offices. Our focus on the back office will be limited to the access mechanisms used for the services offered by the back office. For example, how an airline prices and reserves tickets is beyond the scope of this article. However, the format in which a back office accepts a reservation request and the format of the response will be defined here and in subsequent articles. The transport mechanism (RMI/CORBA/other) will also be discussed and implemented, although security issues involved in transporting the data will not.
The application modules are illustrated in Figure 1.
The framework for this application is distributed among the following tiers:
- Client UI: The end-user interface into the Ticket Store. The client UI is responsible for the front-end interaction with the customer and 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: 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, etc. It interacts with the Services Access tier to get information from the various data sources (airlines).
- Services Access tier: Middleware tier that accepts service requests from the Merchant Server tier, routes them to the Application Services tier and serves back the response to the Merchant Server tier.
- Application Services tier: Offers the ticket price/availability quote services.
Figure 2 illustrates the application framework tiers.
Java Servlets and ColdFusion
The Merchant Server interacts primarily with the Service Access tier via a URL connection and is implemented using the ColdFusion 4.0 application server. For the purposes of this application I developed a custom tag called CF_Servlet (see CFDJ Vol. 1, issue 4). While details of the custom tag aren't relevant to the JDJ articles, they will be discussed in CFDJ.
Before describing the access mechanism, I'll elucidate why specific modules are implemented in ColdFusion while others are implemented using different Java technologies. ColdFusion is an application server whose most important feature is its ability to connect to data created and maintained in other applications. It allows the building of dynamic queries on the fly to retrieve data from such applications. It achieves this through the use of a very flexible tag-based markup language. This makes it an ideal tool for creating dynamic Web application components such as shopping carts, account management modules, purchasing modules, customer profiles, etc.
Servlets, on the other hand, excel at making server-side services available to the client in a dynamic and interactive fashion. Servlets can be used to efficiently access a variety of services offered across different tiers of a distributed architecture. Servlets basically serve HTML to the client. They also bring access control and enhanced security into the equation. They are closely tied to the Web server they run in and thus help extend the server's capabilities to the client. One thing they're NOT designed for is building sophisticated GUIs. They are primarily "HTML servers."
Typically, ColdFusion-based applications and Java Servlets can be used in conjunction if the division of functionality leverages these strengths. In our application, all data pertaining to the customer should reside in the ColdFusion components and be presented to the customer in a snazzy and sophisticated user interface. However, when back-office services like ticket price/availability quotes need to be dynamically accessed (e.g., for submitting a request for a ticket quote), Java Servlets provide an ideal access mechanism to these services. The Merchant Server tier uses the Service Access tier:
This is based on the premise that the airline back-office services are publicly published as RMI/CORBA services. The Service Access tier dynamically queries the various airlines for the ticket price/availability and returns a quote based on some predetermined selection rules. The Service Access tier also maintains a database that captures each interaction with the Application Service tier. This database can be used for statistical analysis in the future, after the data has been accumulated over a period of time. The data would be valuable to the airline agencies. For example, if most customers have been rejecting an airline's quotes because the price is too high, the carrier would probably want to be aware of this fact.
- To access server-side Java services. Non-Java (C++) services could be accessed using JNI.
- To gain access to RMI/CORBA services.
- To perform sophisticated computation-intensive tasks on the server as opposed to burdening the client with this responsibility.
The rest of this article discusses the implementation of a test scenario for the application. Basically, it shows the interaction between a Java Servlet and an RMI server for getting a quote for a ticket. The servlet should be accessible from the ColdFusion template described in the corresponding CFDJ issue. However, you can also run it from a regular browser by invoking the corresponding URL.
Before we define the protocol for communication between the Merchant Server and the Service Access tiers, let's examine the information we'd like to pass between the two. A typical end-to-end transaction in this system would have the following steps. Please note that for this transaction we're not making use of the Customer Profile Manager, Travel Profile Manager, Shopping Cart and other components that are a part of the application implemented in ColdFusion:
- The user feeds in his or her input for a flight quote request via the Client UI (Web browser). This actually invokes the ColdFusion template on the Merchant Server.
- The request goes to the Merchant Server. A ColdFusion template passes the data to the Service Access layer by invoking a servlet. Let us call this the TicketServlet.
- The TicketServlet packages the data into a TicketQuery object.
- The TicketServlet sends the TicketQuery object to the different airline carriers as a request for a price and availability quote.
- The TicketServlet receives the quote from the different carriers in the form of TicketQuote objects.
- The TicketServlet chooses the price quote/quotes based on some predefined selection rules.
- The TicketServlet packages the response into HTML and passes it back to the Merchant Server.
- The corresponding ColdFusion template at the Merchant Server converts the response into a Web page that it serves back to the Client UI. For this article the UI is in the form of a browser at the client site.
Here, we'll just look at the classes that will implement this scenario.
The logic in these example classes is hard-coded. The actual implementation will be developed in subsequent articles. The classes used for the basic scenario are:
- TicketServlet (Listing 1): Receives a ticket request from the Merchant Server, forwards it to an RMITicketServer and passes back the response to the Merchant Server.
- TicketQuery (Listing 2): Encapsulates a request for a ticket quote.
- TicketQuote (Listing 3): Encapsulates a ticket quote.
- TicketServerList (Listing 4): This is the interface for the services offered by the application services tier.
- RMITicketServer (Listing 5): Processes the TicketRequest object and sends back a TicketResponse object.
- RMITicketClient (Listing 6): This is accessed by the TicketServlet for submitting the request to a Ticket Server.
How the classes interact
The TicketServlet is the access mechanism for the RMI services offered by the RMITicketServer. The access protocol between the ColdFusion template and the TicketServlet is very simple. Since Servlets are accessible via a URL, the most convenient way to pass data between the two is in the form of Name-Value parameters that can be passed in the query string of the URL. The Servlet creates a TicketQuery object from these parameters. The TicketQuery object is propagated directly to an RMITicketServer via a RMITicketClient object. The RMITicketServer creates a TicketQuote and passes it back to the TicketServlet. The TicketServlet creates an output string in the form of Name-Value pairs, which are passed back on its output stream to the ColdFusion template.
The flight quote requested from the client is simple and doesn't contain all the fields necessary to process the actual flight request that will be used in our application. In fact, the TicketQuote only contains a single field, which is the price for the flight. The refined classes for the application will be discussed in the next part of this article series.
The code for this article was developed using JDK 1.1.7B on an NT 4.0 workstation. The TicketServlet is accessed using Jrun Pro 2.2. The code listings may be obtained from the JDJ Web site.
About the Author
Ajit Sagar, a member of the technical staff at i2
Technologies in Dallas,Texas, holds an MS in
computer science and a BS in electrical engineering. He focuses on Web-based e-commerce applications and architectures. Ajit is a Sun-certified Java
programmer with nine years of programming
experience, including two and a half in Java.
You can e-mail him at [email protected]
Download Assoicated Source Files (Zip format - 3 KB)