CPS 606 - Final Project Report

Computerized travel reservation systems are very common these days, most of them using highly sophisticated and custom built systems. In this project I try to build a prototype of such a client-server airline reservation system for local flights between near by cities. The project is developed using jdk1.1 and has an applet for the user interface part and a server and flat file database at the back-end. Since the project was to demonstrate the use of java networking, features of the system are kept minimal.

For this prototype, I have selected three airports that are closer to Syracuse namely Boston, New York City and Toronto. The system is built for people who travel between these cities for work and other business purposes in a frequent or day to day basis. So the user interface is kept very simple by not collecting all the details from a user, but rather just the name and phone number of the person apart from the flight day and time. Four flight timings are listed, two in the morning hours and two in the afternoon hours. A user can select the airport that he wants to flight to and the departure airport and select the flight timing as well as enter the day that he wants to fly. Once the flight detail is, the user can also list the reservations for all flights between two airports.

The code is organized into three packages, gui consisting of all applet or user interface classes, client consisting of a class for creating sockets to the server and server package consisting of two classes that acts as the server and the connection handler classes. The data subdirectory consist of the data files for the reservations. The applet.html file has the embedded applet in it.The run file is used to start the server. The applet works using either Netscape4, Internet Explorer 4.0 or appletviewer. The server should be started before running the applet.

Back to Top

Technical Description

The project is divided into three packages namely gui package with all the user interface classes, client package which has a class for communicating with the server and a server package which has the server classes. Below you will find description about these packages.

Back to Top

User Interface :

The user interface part consist of the classes in the gui package and the class in the client package. The classes in the gui package consist of all the necessary classes for building up the applet. The starting point of the applet is the ReservationApplet class which is an applet that has some parameters being given through the applet tag in the html file. The parameters that this applet will take are the hostname and port number of the server with which the applet can communicate. Note that due to applet security restrictions, the applet (or the html file where the applet is embedded ) should be on the same machine where the server will be started so that the applet can communicate with the server through sockets. If no parameters are given to the applet in the html file then the default hostname is taken as 'carver.npac.syr.edu' and the default port number is taken as '4321'. Two static attributes are present in the applet class so that the Connection class can obtain the server's hostname and port number without having to hardcode the values in the class.

The ReservationApplet class uses a border layout and creates two components namely TopPage and MainPanel components. The TopPage class which extends from a canvas, is used for displaying the title for the applet. It sets some background and foreground colors and displays the string message on the canvas. The MainPanel class is a Panel which uses BorderLayout to place two components, LeftPanel and RightPanel in the window. The MainPanel also implements the ActionListener interface for trapping button click events generated from the buttons present in the LeftPanel class. When LeftPanel object is instantiated in the MainPanel, a reference for the MainPanel class is passed to the LeftPanel constructor. This is used for adding the ActionListener to the buttons present in the LeftPanel class. The RightPanel uses a CardLayout and has three cards, one called PlainPage which is the default card and displays the message 'Welcome to AirLine Reservation !' and NewForm class which is displayed when a user clicks the 'New' button in the left panel and a ListForm class which is displayed when a user clicks 'List' button in the left panel. The MainPanel class uses a public method 'showCard' in the RightPanel class to display the appropriate card when a button is clicked in the left panel. Thus the MainPanel class transfers the button click events from the left panel to the right panel and displays the appropriate page.

The LeftPanel class uses a GridBagLayout to place the three buttons and the label component appropriately. It uses the GridBagConstraints and Insets classes to place the components in order. The RightPanel class uses a CardLayout and has a public method for displaying a card depending on the card name string.

The NewForm class is the interface for adding new records to the database. It uses a CityList helper class for generating the list of cities as a Choice box with some default values being selected. It has another Choice list component for displaying the four flight timings. Apart from these choice lists, the user interface also has text boxes for entering date, name and phone number. It also has a StatusWin component for displaying the client-server interactions. The class uses GridBagLayout, GridBagConstraints and Insets classes for placing the components appropriately. The class also implements ActionListener interface for trapping the button click events generated from within the buttons in the class. When a user clicks the Submit or Cancel button, the actionPerformed method is called and appropriate actions are taken.

If the Submit button is clicked, then some error checking is done by checking whether all the textfields have data and by checking if the departure and arrival airports are the same or not. The error messages are printed on the status window. If no errors are present then the a connection to the server is established with the help of the Connection class in the client package and the data is sent to the server and the acknowledgement is printed in the status window. Various status messages are also printed during this communication process.

The communication protocol for the client-server communication is defined as follows. The server expects an 'action=List|Post' string in the first line of the request send by the client. The values of action depend of whether the request is for updating the database with a new record, in which case the value of action is 'Post' or  whether the request is for getting records from the database back to the client, in which case the action value is 'List'. The next line of the request will have the actual data or parameters of the query in an encoded form. The data and parameters are send in the same way as name-value pairs delimited by a '##' string. For e.g. an example request could be as shown below
action=Post
from=BOS##to=SYR##time=6.00 AM##day=12/15/1998##name=My Name##ph=315 443 1998

The ListForm class is displayed when the user clicks the 'List' button in the left panel. This is the user interface which lists the records returned from the database depending on the selections that the user made. The user first has to select the destination and departure airports and click the 'List' button. This class also uses the Connection class to connect to the server and send and receive messages to the server. The messges are send in the same exact format as above. After the request is sent, the response is read back from the server and formatted using the displayData method and displayed in the text area on the top.

The user interface uses a GridBagLayout and also has a status window which is updated with the status of the client-server communication. The class also implements the ActionListener interface for trapping the events generated by the button clicks in this class.

Finally the applet is embedded in an HTML file with hostname and port numbers as parameters to the applet.

Back to Top

Backend :

The backend consists of two classes in the server package. The main Server class is the starting point for the server. It takes the port number as a command line argument. If the port number is not specified then a default value of 4321 is used as the port number. The port number where the server is running should  also be given to the applet using the applet parameters in the applet's html file. The main method in the Server class creates a new Server object which creates a ServerSocket object in the specified port and starts listening to client connections. Once a client connection is accepted, the ConnectionHandler class is used to handle the connection.

The ConnectionHandler is the main class at the backend that does all the processing and writing to files etc. Once a connection is accepted a ConnectionHandler object is created by passing the client socket reference to the constructor. The input and output streams are created in this handler and the first line is read to check if the request was a 'List' or a 'Post'. But since both these will send data in the exact same format no matter whether it is a List or a Post, the data from the next lines from the input stream are read and stored in a Hashtable for convenience. Once the data is read, the appropriate file is opened before actually doing the handling of the request.

There are four data files in the data sub directory corresponding to the four 'from' cities. So if the from city is selected as SYR, then the data are written to syr.dat file and so on. Also, the records are written in a line by line basis with one record in every line. The first field in every record is the 'to' city name. Thus when the user selects a 'from' city and a 'to' city to list all the flight information for those two cities, what actually happens is that, first the correct file is opened with the help of 'from' city name and all records which starts with the 'to' city name are returned back to the client.

Once the files are opened, the action parameter is checked to see if it is a List or if it is a Post. If it is a Post then the data is written to the opened file. The method that actually writes to the file is made a synchronized method so that it avoids contention amongst multiple simultaneous writes to the same file. If the action is to List then the records that match the criteria are read and concatenated into a big string with newline separators between records and send back to the client using the client's output stream.

The connection handler class also has method for encoding and decoding the data in the format described above. Once everything is done the file is closed. The Server class closes the connection once it is handled.

Back to Top

Source :

The source is divided into three packages corresponding to the three packages.
The gui package consist of the following classes

The client package consist of the following
The server package consist of the following
The data directory has four .dat files.

Back to Top

Demo :

Inorder to run this applet, the server should be started and the corresponding port number should be specified in the applet's html file.
The demo applet works with Inernet Explorer 4.01 on Win NT, Netscape Communicator versions 4.5, 4.04 with AWT 1.1 patch and 4.05 with AWT 1.1 patch on Solaris machines. It will not work on Netscape 4.04 and Netscape 4.05 without AWT patch.
Click here if you have already started the server to run the demo.

Back to Top
xjqiu@npac.syr.edu  Go Back