CHAPTER 6 : SYSTEM AND DATA ARCHITECTURE
6.2 WEB SERVICE
The communication between the client and the server is carried out using HTTP, the standard web protocol. Smart Radio uses an Apache38 web server as the system front door through which client requests are received and responses despatched. The web server also delivers static material such as images, Javascript pages and style sheets.
The web server works in conjunction with a servlet engine which handles the processing logic required by requests that require dynamically generated content such as a web page displaying the user’s most recent recommendation set. The servlet engine is a multithreaded container designed to provide a processing facility in the Java language39 for request/response
protocols such as HTTP40. Each servlet is a Java programme written to deal with the logic
processing required by a specific request. For instance, in Smart Radio the recommendation servlet will handle a client request for a web page displaying his/her recommendations. The web server recognises that requests are to be passed to the servlet Engine for processing by identifying the request URL as a request for dynamic rather than static content. This is done by reserving a folder name as an identification for servlet processing. In Smart Radio the reserved folder is /smartradio/. Servlets act as controllers selecting which recommendation/database services to call, and choosing which presentation layer (View) component to render.
Figure 6.2 illustrates the system architecture from the perspective of the web service. The red arrows point out the logical path followed by a request from the client browser until a response is received from the web server.
37 http://java.sun.com/j2ee/faq.html 38 http://www.apache.org
39 http://java.sun.com
Figure 6.2: The system architecture from the perspective of the web service
Model-View-Controller (MVC)
The client server architecture in Smart Radio follows the Model-View-Controller (MVC) design pattern. The MVC paradigm is a way of breaking an application interface into three parts: the model, the view and the controller. MVC was originally developed to map the input, processing and output roles in GUI design for Smalltalk-80 applications (Goldberg & Robson 1983). More recently it has become an increasingly popular design pattern for client-server systems on the web (Alur et al. 2001). The key to the MVC design pattern is the decoupling of data access, application logic, data presentation and user interaction. In this context the functionality of the MVC is summarised in Table 6.1.
Table 6.1: A summary of the functions of the Model-View-Controller design pattern
Description Smart Radio Components
Model The Model encapsulates the business logic of the
application. It can respond to requests and notify the View component of changes, and updates.
The Recommendation Server, Database Access component
View The View renders the contents of a model. It is the
view's responsibility to maintain consistency in its presentation when the model changes.
JSP pages and Data Beans
Controller A Controller is the means by which the user interacts
with the application. A controller accepts input from the user and instructs the model and view to perform actions based on that input. In effect, the controller is responsible for mapping end-user action to application response.
The Controller logic in Smart Radio is carried out by servlets. This involves checking for new recommendations, creating data containers (data beans), and requesting updates to the recommendation server either asynchronously or synchronously, which we discuss later in the chapter.
Data Beans are data structures created by the interaction of the Servlet with the database or the Recommendation server (the model components). They are created in order to provide content for each Java Server Page (JSP), the HTML rendering component of the servlet engine. In this way they provide an interface between the Model and the View components. A data bean is created for each client request for specific information such as a list of a user’s recommendations or the top ten lists in Smart Radio. In order to reduce the number of requests being made to the database, which can be a bottleneck, data beans are cached (by the controller). Servlets will check the cache before requesting new information from the database. When the control logic required for the request has been carried out, the servlet engine forwards the request and a data container, the data bean, to the JSP rendering engine.
JSP pages, which act as the View component of the system, are servlet extensions which are designed for rendering the presentation layer in an application. Each page contains HTML in which some Java code is embedded, mainly for providing data access. In the case of Smart Radio, data access is performed by the servlet component and the contents rendered into a data bean. JSP pages format the data in the data bean into HTML pages. We use JSP pages in conjunction with a JSP template library which allows us to standardise and modularise our presentation design.
The Model functionality is carried out by the Recommendation server, and the database connectivity module. The Recommendation server can be queried synchronously or asynchronously. We will describe its role in the overall system in greater detail in Section 6.6.