In this assignment, you will extend the functionality of the simple web server application introduced in lecture to
![]() | service HTTP GET requests for any specified .html file that exists in the server's webapps folder (by returning the content of those files in a correctly-formatted HTTP message) |
![]() | service HTTP GET requests for image files (.png, .jpg, .gif, or similar) |
![]() | service HTTP GET requests for files of type .unk (that is, files whose extension is .unk and whose content type is unknown to the server) |
![]() | service HTTP GET requests for non-existent .html (or other) files that do not exist in the server's webapps folder (by returning the appropriate HTTP error indicating that the resource does not exist) |
![]() | service an HTTP GET request for a virtual resource (i.e. a url that does not correspond to a physical file) |
![]() | implement multithreading so that your web server can service multiple requests simultaneously. |
You should already have an "regular" Eclipse Java project setup around the example ServerApp application from lecture, with the usual <package>/src folder hierarchy within the project.
The webapps folder at the base of the project's hierarchy will be the location where you'll have the server look for .html files requested by a browser via a url such as http://localhost:8080/index.html. Note that if the browser user specifies a url such as http://localhost:8080/pictures/2008/graduation.gif, then the server will have to look for the file "graduation.gif" in a "webapps/pictures/2008" subfolder. You should be able to place any number of files anywhere within the webapps folder (or subfolders) and be able to retrieve them with an appropriate url.
You'll be modifying the receiveRequest() and sendResponse() methods of the ServerApp to parse the incoming HTTP GET request in order to extract the name and file path of the resource to retrieve, and then return that resource successfully. Note that you'll have to adjust the Content-Type in the HTTP response if you are returning image files, and you'll also have to use a different output stream writer (hint: you may want to create a separate "sendBinaryFile()" helper method) for returning the binary image content.
You must also make appropriate modifications to receiveRequest() to handle the situation where the requested resource does not exist. In such a case, your modified ServerApp must create an appropriate HTTP message response indicating that to the client (the browser). Read this article on HTTP responses in order to figure out what type of HTTP message to send back in this case. Note: You may want to have a separate sendErrorReponse() method to handle this case.
Additionally, you must modify receiveRequest() to detect a request for a resource file that ends with ".unk". When detected, set the content type (in the HTTP header response) to "application/unk". You'll be observing the behavior of the browser in this case as explained below.
Finally, you must modify receiveRequest() to detect a request for the following virtual resource: http://localhost:8080/info. In this case, no physical file named "info" needs to exist. Instead, your ServerApp will respond to this url by generating a dynamically-formulated HTTP/HTML response returning the following information to the client browser (note the colors - any three different colors of your choice are required. The font-face/size for each line is your choice. The response must be correctly formulated HTML and CSS, according to the HTML and CSS validators).
CS4220 Simple
Server
written by <your name>
Info request received from client at IP <nnn.nnn.nnn.nnn>
on <today's date/time>
Read the Javadoc on the Socket class to figure out how to determine the client's IP address. The Date/time must be dynamically generated so that the current value is displayed whenever this url is requested.
Important: The sample ServerApp code is capable of servicing only a single request at a time. Thus, response performance is limited to servicing a single request at a time. You must implement multi-threading to improve performance, so that the receiveRequest() and sendResponse() methods are executed on separate threads.
Note: Commercial web servers usually impose a limit on the number of incoming requests they will service by implementing thread-pooling or similar mechanisms (you may have seen messages like "server is busy - try again later". You might want to also consider limiting the number of threads to a finite value (e.g. 10), but you are not required to for this assignment.
You must, using an HTML editor of your choice, create a "results.html" file implementing correct HTML grammar (validated with 0 errors) and place it in your webapps folder - this file should contain an explanation of what you observe in the circumstances described below. Note that your ServerApp should be able to serve this file properly to a browser:
![]() | Explain what is displayed when your Server returns the "requested resource does not exist" HTTP response. Include a screen capture as as part of this explanation . |
![]() | Create a simple text file with Notepad (or other text editor). Save this file to your "webapps" directory, and change the file extension to "unk". Explain what is displayed by when your Server returns this file (or any file whose extension ends with "unk"). Include a screen capture as as part of this explanation. |
![]() | Explain what is displayed if your server mistakenly returns an HTTP head that is misspelled (e.g. "HPPT"). Include a screen capture as as part of this explanation. |
![]() | Explain what is displayed by Firefox when your Server returns the "requested resource does not exist" HTTP response. Include a screen capture as as part of this explanation. |
![]() | Explain what is displayed by Firefox when your Server returns a file whose extension ends with "unk". Include a screen capture as as part of this explanation. |
![]() | Explain what is displayed by Firefox if your server mistakenly returns an HTTP head that is misspelled (e.g. "HPPT"). Include a screen capture as as part of this explanation. |
When you have finished, zip (not rar, tar, or something else) your Eclipse src and webapps folders (I don't want the entire project folder and all the binary junk that goes with it) and submit it to Blackboard (do not email it). Incorrect submissions will be rejected and will be accumulate late penalties until submitted correctly.
Make sure your submitted code conforms to the following standard.
All source code submitted must use JavaDoc commenting conventions for every class and method and meet the minimum documentation standards below:
The beginning of each source file must contain:![]() | The name of the file. | ||||||
![]() | A short description of the purpose of the class contained in the file. | ||||||
![]() | The date it was originally written. | ||||||
![]() | The original author. | ||||||
![]() | A modification log (when appropriate) which describes:
|
Each class method must contain the following documentation header:
![]() | Explanatory notes regarding the overall usage of the method; that is, what the method does. |
![]() | The parameters passed in the formal argument |
![]() | What the method returns (if anything) |
![]() | Any sources other than the author (Web URL, fellow student, etc.) that aided in the design of the method (and what aid was provided). |
![]() | Explanatory notes regarding the internal workings and coding whose purpose is not immediately obvious to someone with your current level of programming knowledge |
Method bodies must be commented appropriately using conventional commenting. All code must be properly formatted (conventional indentation). Class, method, and variable names should be logical and according to the conventions taught in previous SE courses.
Required functionality 45 pts
Implements multithreading 10 pts
Report page 15 pts
Commenting/formatting 30 pts