|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON General Java An Online Airplane Ticket Store Using Java & Coldfusion Part 2
An Online Airplane Ticket Store Using Java & Coldfusion Part 2
By: Ajit Sagar
Jul. 1, 1999 12:00 AM
This is the second in a series of articles focused on using some of the prominent Internet and Java technologies to develop a Ticket Store application. In the last issue of JDJ we defined the APIs and technologies and the network topology that would be used to develop the Ticket Store. We also walked through skeletal definitions of the classes used to implement this application. Now we'll add some meat to these classes. We'll also define some workflows and scenarios for our application, with emphasis on the design of the objects for the middleware tier of the store. Our focus will still be on the purchase of tickets via an online travel agent that gets quotes from different airlines and presents the Internet user with the best quote. The online store portion of our application will be discussed in the next article in the series. The UI design for this application isn't a major part of our Java-based design. A basic browser UI will be developed for the end user. In corresponding issues of ColdFusion Developer's Journal (Vol. 1, issues 46) we'll develop the more sophisticated and personalized UI in parallel using ColdFusion. I'd like to reiterate that as this isn't a real-world application, several decisions made for the design will be oversimplified, their primary purpose being to illustrate how the components defined here can be integrated into a distributed application. Of the four tiers of the Ticket Store application described in the last article, the Service Access tier, and specifically the Ticket Reservation and Sales Broker, will occupy most of our attention. As defined in last month's article, the Service Access tier is a 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. The Merchant Server tier adds in user-specific data and sends back the response to the user interface. Ticket Reservation and Sales
Broker Requirements
This is a simple workflow that runs through the system in a sequential fashion. We'll implement this workflow in our system, ignoring other functionality such as canceling a reservation, etc. The idea is to demonstrate how data flows through our Ticket Store from the end customer to the back office and back. Figure 1 illustrates the use cases for the Broker. The workflow is illustrated in Figure 2.
Class Design
Step 3 of the workflow defined above encapsulates the main functionality of the Broker. Let's break this step down and identify the classes we'll need to provide this functionality. The classes needed for the design of the Broker and their function are summarized in Table 1. The relationship between the classes is illustrated in a class diagram in Figure 3. The classes and code listings are described below.
TicketBrokerServlet
TYPE="Query/Book" Our Broker is capable of connecting to airline carriers with different kinds of interfaces based on the protocol used for the data exchange. In our system we have four fictitious airline carriers in the Service Access tier SeemaAir, KarunaAir, NitiAir and ApuAir. SeemaAir makes its prices available via a simple Socket interface. KarunaAir exposes its services via an RMI service. NitiAir uses a CORBA server. ApuAir offers a service via a Servlet, i.e., it supports a URL invocation. TicketBrokerServlet (which represents the Broker's connection layer) sends the TicketRequest to each of these carriers and waits for responses on each of them. When it receives all the responses, it uses the TicketPricer (described later) to send back the best quotation. The network connections between the Broker and the airline components in the Application Services layer are illustrated in Figure 4. Since the Broker supports four kinds of services, it creates four clients, one for each service. These clients are instantiated by the TicketClientManager class, which establishes and manages connections to the different airline carriers: if (clientManager_ == null) clientManager_ = new TicketClientManager(); The service() method of the TicketBrokerServlet instantiates the TicketClientManager. It then calls a getQuotes() method on this instance. The method getQuotes() returns a vector of TicketQuote objects. The four client classes (SocketTicketClient, RMITicketClient, CORBATicketClient and ServletTicketClient) and the TicketQuery and TicketQuote classes are described later in this article. The next method call in the service() method is to the method getBestQuote(). A vector of TicketQuote objects is passed in as a parameter. The method getBestQuote() calls static methods on the TicketPricer object to get the final price on each of the quotes obtained from the airlines. It selects the best price and sends a new TicketQuote object to the service() method of the servlet. The service() method calls the getQuoteString() method and passes it the TicketQuote object that it just got back. The resultant string is returned to the invoker of the URL. The string is in the form of name-value pairs, similar to the input received by the TicketBrokerServlet. One of the parameters passed into the servlet is a "TYPE=VALUE" parameter. The "VALUE" can be "QUERY" or "BOOK". When the string "Query" is passed in as an argument to the servlet, the getQuotes() method described above is invoked. When the string "BOOK" is passed in, the bookSeats() method is called to actually book the flight. The bookSeats() method is described later in this article under the TicketService class.
TicketQuery
The fields in the TicketQuery class are:
TicketQuote
The fields in the TicketQuote class are:
In case there is no availability based on the search criteria, the TicketQuote returns with a "0" in the noOfSeats and the other fields are invalid. This is not the most efficient way of sending a response, but it will serve our purpose.
TicketService
My assumption is that the reader is familiar with the workings of the different protocols used in this application. Thus I won't go into details of the classes used here. Each of the service protocols (Socket/RMI/CORBA/Servlet) has the following set of classes as illustrated earlier in Figure 3:
In the interest of space and general sanity, I won't go into details of the classes for all four types of services. I will cover the RMI example here. The understanding of the rest is left as an exercise for readers. In a real-world application the responses from each "airline" could take varying amounts of time. There would also be a timeout for waiting for the responses. This kind of a transaction is asynchronous and would be best handled by spawning each ticket quote service as a separate thread. However, in our application we'll assume that the responses are instantaneous (indeed they will be, because our Service Application Tier is pretty much hard-coded). Therefore, each of the clients that request a quote from the corresponding airline server is started sequentially as shown in the TicketBrokerServlet class. The clients for the different protocols are described in the next four sections.
TicketClientManager
The TicketClientManager contains a getQuotes() method that calls a getQuote() on each of the clients. Each client in turn calls the getQuotes() method on its corresponding remote server. The resultant value is a TicketQuote object that is passed back to the TicketBrokerServlet. The TicketClientManager also contains a bookSeats() method that is forwarded in a similar fashion to the corresponding protocol server. The bookSeats() method returns a boolean value that indicates the result of the operation. The bookSeats() method takes in a string parameter that indicates the protocol (and corresponding airline) that was selected for the best fare.
RMITicketClient
TicketPricer
Application Service Tier Classes
Each class inherits from the TicketService interface. The classes provide implementations for the client-side stubs. Hence, they provide implementations of the getQuote() and bookSeats() methods. The code in the ticket server classes is trivial and is not described here.
Quoter
Running the Programs
|
The one thing that unifies the distributed computing style known as SOA, in most of its manifestations, is self-describing data via the Extensible Markup Language (XML). The benefits of XML over opaque message formats in data interchange are well established. No matter if your fo... |
In the past couple of years, interest in Jetty has surged. Jetty is an open source Java-based web and application server and servlet container, but what else do you know about it? To commemorate the 12th anniversary of Jetty, here are 12 things that might surprise you |
JavaScript is one of the most interesting and misunderstood programming languages in common use today. Most developers will go their entire careers without realizing its full potential. It's not often that you get a language that supports the feature set that JavaScript does, whi... |
JavaScript 2 is becoming increasingly important. Learn how to take advantage of JavaScript 2 while still running in today's browsers. Leverage your current JavaScript and HTML skills to build applications that run in Flash 7-9, DHTML and more with no code changes! OpenLaszlo 4.2 ... |
JavaScript is a language with more than its share of bad parts. It went from non-existence to global adoption in an alarmingly short period of time. It never had an interval in the lab when it could be tried out and polished. JavaScript has some extraordinarily good parts. In Jav... |
Cloud computing is an opportunity for businesses to implement low-cost, low-power and high-efficiency systems to deliver scalable infrastructure. But moving to a cloud infrastructure is not necessarily as nice and clean as the providers would want you to think. With cloud infrast... |
Click to Add our RSS Feeds to the Service of Your Choice:
![]()
View Additional SYS-CON Feeds
|
In every field of design one of the first things students do is learn from the work of others. They ... Oct. 7, 2008 11:15 PM |
There are many forces that influence technological evolution. After a decade of building enterprise ... Jun. 30, 2008 03:45 PM |
2008 is going to be an important year for Rich Internet Applications. Most organizations are deliver... Jun. 20, 2008 12:45 PM |
The OpenAjax Alliance is developing an Ajax industry wishlist for future browsers, using a dedicated... Jun. 18, 2008 07:45 PM |
Infragistics announced the availability of two Community Technology Preview (CTP) User Interface (UI... Jun. 4, 2008 08:00 AM |
The YUI development team has released version 2.5.2; you can download the new release from SourceFor... Jun. 2, 2008 05:00 AM |