Unformatted Attachment Preview
IT 365 Module Four Run the Code Guidelines and Rubric
Designing a Web Server
Overview: For this activity, download the Designing a Web Server source code and run the program with the NetBeans integrated development environment
(IDE). You will need to place comments in the code where identified and respond to the challenge questions associated with this assignment. The point of this
activity is to give you an understanding of how the code works.
Before beginning, review the code that relates to this activity.
Activity Review: Distributed Systems—Web Server
Designing a Web Server
This project consists of designing and implementing a simple multithreaded web server according to the HTTP 1.1 protocol. A web server operates by listening to
a port (typically port 80), waiting for client connections. When a client (a web browser) connects to the server, it requests a resource from the server such as an
HTML page, image, or document. If a valid client request is made, the server returns the requested resource to the client. Clients may also request other services
from a web server and may even ask to place a resource on the server. We do not consider these scenarios in this project.
Each client request is to be serviced by a separate thread on the server. You may service each client request by either creating a new thread or using a thread
pool (Section 4.5.4). If you choose to use a thread pool, you may use either the Java API for thread pools described in Section 4.5.4 or the thread pool you
created in the programming project in Chapter 6.
To best understand the interaction between a client and a web server, we first examine how a client makes a request to a server and then consider how a server
responds to a client request. Before we proceed, however, note that we are examining only a small portion of the HTTP protocol. Those who are interested in
the full details of HTTP are encouraged to read the request for comment (RFC) for HTTP 1.1 provided in the bibliography section of your textbook.
Client to Server
Once a client connects to a web server, it sends a request using an HTTP request message. This request message appears as:
The request line consists of an HTTP method, the name of the resource being requested, and the HTTP protocol being used. General headers include the date
and whether the TCP connection is to remain open or closed once the request has been fulfilled. The request headers include the host name of the server, the
document type (or types) the client will accept, and the agent (the web browser) making the request.
As an example, suppose a client (a Safari browser running on Mac OS X) requests the following URL:
http://localhost/index.html
The request message appears as shown in Figure 16.11.
Figure 16.11 The Request Message
Although a fully functional web server responds to all headers it receives, this project requires parsing only the request line—GET /index.html HTTP/1.1. The GET
method specifies that the client is requesting a resource from the server; the requested resource is /index.html. (Resource names appear after the leading
forward slash “/”.) Finally, the HTTP protocol being used by the client is HTTP/1.1. There are other methods specified in the HTTP protocol, such as HEAD, POST,
and PUT. For this project, you only need to handle the GET method.
As mentioned above, resource names appear after the leading forward slash “/”. Suppose a client requests the following URL:
//www.wiley.com
Here, the request line would appear as GET / HTTP/1.1—that is, with no resource name following the leading forward slash. When this occurs, a web server is
configured to return a default document. For this project, return index.html as the default document.
A Java program HttpRequestEcho.java is provided to further explain the request message sent from client browsers to web servers. Refer to the README file for
details on how to run this program.
Server to Client
Once the server has received a request message, it sends back an HTTP response message to the client. A response message appears as the following:
The status line is structured as follows:
HTTP/1.1 < reason phrase>
The first field of the status line is the HTTP version specified in the client request line. The status code is a numeric code indicating the status of the response
message. The reason phrase is a brief description of the status code. Your web server must support the three status codes and their associated reason phrases
shown in Figure 16.12. (Shortly, we will discuss which status code your web server will return to the client.)
Figure 16.12 Three Status Codes and Their Associated Reason Phrases
General headers include the date and whether the connection is to close or remain open. Response headers typically include the name of the server (e.g.,
an Apache web server). Entity headers include the content type of the resource (such as html or jpeg) and the length (in bytes) of the resource being returned.
A Java program HttpHeader.java is provided to further explain the response message sent from a web server to a client browser. Refer to the README file for
details on how to run this program.
The Web Server
Design a web server that listens to port 2880 and implements the GET command of the HTTP 1.1 protocol. Your server will listen for client connections, servicing
each in a separate thread. When a client request is received, the thread will parse the request, read the requested resource on the server, construct the
necessary HTTP headers, and return the response message and contents of the requested resource.
The response message will consist of the following headers:
1.
2.
3.
4.
5.
6.
Status line
Date
Connection: close
Server
Content-Type
Content-Length
When constructing the status line, you are responsible for three status codes—200, 400, and 404. The codes are to be sent in the following situations:
200 is sent if the request is valid and the resource is being sent to the client.
400 is sent if the client sent a request the server cannot understand.
404 is sent if the requested resource cannot be found on the server.
The date must be formatted according to a protocol (RFC 1123). The Java file DateFormatter.java is provided to illustrate how to format the date sent in the
response header. The header Connection: close indicates that your server does not support persistent connections and the Transmission Control Protocol (TCP)
connection is closed once the server replies to the client. The value of the server header is the name you have chosen for your web server.
The content types your web server must support are listed below:
Finally, the content length is the length in bytes of the resource you are returning to the client.
Logging
All requests to the web server must be recorded in a log using the common log file format. A line using this format appears as the following:
Remote host—The IP address of the remote host connecting to your web server
Date—The date of the request, which appears in square brackets “[]”
Request—The HTTP request line, which is placed in quotation remarks, as it may contain spaces
Status—The status code: 200, 400, or 600
Bytes—The length in bytes of the resource returned to the client
Two possible entries in a log file are the following:
10.0.0.2 [Thu Jul 2 17:24:07 EDT 2009] “GET /screen.jpg
HTTP/1.1” 200 82961
10.0.0.2 [Thu Jul 2 17:24:07 EDT 2009] “GET / HTTP/1.1” 200
22
XML Configuration
There are three parameters for configuring the web server:
The name and location of the log file
The name of the server
The location of the documents being served by the web server
These parameters are to be specified in an XML file. At startup, your server will read the configuration parameters in the file config.xml. The following Java
example illustrates how to obtain the value of the three configuration parameters specified in config.xml:
Configuration configurator = new Configuration(“config.xml”);
. . .
configurator.getLogFile();
configurator.getServerName();
configurator.getDocBase();
The getLogFile() method returns the name of the log file where the server is to log requests, and the method getServerName() provides the name of
the server. The getDocBase() method is used to obtain the name of the directory from which web pages are to be served. For example, if the folder where a
web site is stored is named
C:\\web-server\\docs
all documents will be retrieved below this directory, and getDocBase() will return this value. The URL
http://127.0.0.1/index.html
indicates that the resource index.html is stored as
C:\\web-server\\docs\\index.html.
The URL
http://127.0.0.1/pictures/jvm.gif
refers to the file
C:\\web-server\\docs\\pictures\\jvm.gif
and so forth.
A sample XML file is provided as well as three Java programs illustrating how to obtain the values specified in the XML file. These files are: (1) config.xml,
(2) Configuration.java, (3) ConfigurationException.java, and (4) Test.java and are available online.
Challenge Questions
After you have completed the program code, respond to the challenge questions below. Be sure your response includes proper rationale to support your
reasoning.
Challenge Question One
Consider a system that allocates pages of different sizes to its
processes. What are the advantages of such a paging scheme? What
modifications to the virtual memory system provide this
functionality?
Challenge Question Two
Explain why doubling the speed of the systems on an Ethernet
segment may result in decreased network performance. What
changes could help solve this problem?
Challenge Question Three
In what ways is using a name server better than using static host
tables? What problems or complications are associated with name
servers? What methods could you use to decrease the amount of
traffic that name servers generate to satisfy translation requests?
Specifically, the following critical elements must be addressed:
Comments: Comment in the code at every “Comment Here” section.
Running the code: Download the source code and run the program with the NetBeans IDE.
Challenge question: Provide detailed analysis with supporting elements that addresses each question.
Rubric
Guidelines for Submission: To properly complete this assignment, submit two files: a Java file and a Word document containing responses to the challenge
questions. Your Word document should list each challenge question followed by your response. Be sure you cite any academic sources in APA style.
Critical
Elements
Comment Code
Exemplary
Proficient
Needs Improvement
Not Evident
Value
Meets “Proficient” criteria and
comments demonstrate nuanced
understanding of the code
(100%)
Comments throughout the
provided code to explain how the
code works (85%)
Comments throughout the
provided code to explain how the
code works but lacks detail (55%)
Does not comment throughout
the provided code to explain how
the code works (0%)
40
Runs code, ensuring that there
are no errors present that might
prevent code from working
properly (100%)
Responses demonstrate a general
understanding of the program
setup and performance ability
(85%)
Runs code but there are errors
that prevent code from working
properly (55%)
Does not run code or show any
proof of running code (0%)
40
Responses require additional
support to demonstrate an
understanding of the program
setup (55%)
Responses are vague and unable
to correlate to the setup and
performance of the program
ability (0%)
20
Compile and
Run Code
Challenge
Question
Response
Responses meet “Proficient”
criteria and demonstrate
complete comprehension of the
programs setup and performance
ability (100%)
Total
100%