Question: Your web server must start from the command line, with arguments that indicate the port that the server will listen to and the document root

Your web server must start from the command line, with arguments that indicate the port that the server will listen to and the document root from which the web server will serve documents. Note that the order of the command line arguments (this is to make your lives easier, and this is the order I will use when grading)!
javac server/WebServer.java
java server.Webserver 9999/some/absolute/path/to/document_root
In the above example, 9999 is the port number that the server will listen to, and /some/absolute/path/to/document_root is an absolute path the server will use to determine what document to return to the client. The grading process is automated, so the WebServer class must include the main method, or I will not be able to start your server!
Basic Request Handling
Your server must handle invalid requests (requests that do not conform to the protocol). If an invalid request is received, your server must respond with a valid HTTP response (400).
Your server must handle GET requests for a static document. The server will attempt to find the requested file and:
If the file exists, the server must respond to the client with a valid HTTP success response (200)
If the file does not exist, the server must respond to the client with a valid HTTP not found response (404)
Your server must handle HEAD requests for a static document. The server will attempt to find the requested file and:
If the file exists, the server must respond to the client with a valid HTTP success response that does not include the file in the body of the response (200)
If the file does not exist, the server must respond to the client with a valid HTTP not found response (404)
Your server must handle PUT requests. The server will create or overwrite a file at the requested path and:
If the file is successfully created, the server must respond with a valid HTTP created response (201)
If the file is not successfully created, the server must respond with a valid HTTP error response (500)
Your server must handle DELETE requests. The server will attempt to find the requested file and:
If the file exists and is successfully deleted, the server must respond with a valid HTTP no content response (204)
If the file exists and is not successfully deleted, the server must respond with a valid HTTP error response (500)
If the file does not exist, the server must respond to the client with a valid HTTP not found response (404)
Note that in all cases with a body, the server must include the necessary HTTP headers in the response (e.g., Content-Length and Content-Type, Date). Some requests may require additional headers.
Support Simple Authentication
Your server must be able to handle the 401/403 authentication workflow. The presence of a .password file in the directory of the requested resource will determine permission to access a given resource.
If a .password file exists in the directory where the server finds the requested file, and if no Authorization header is present, the server must respond to the client with a valid HTTP unauthorized response (401). This response must contain the header WWW-Authenticate, with the value Basic realm=667 Server.
If a .password file exists in the directory that the server finds the requested file, and if an Authorization header is present, the server must check that the .password file contains the username and password provided in the header and:
If the .passwords file does not contain the username and password, the server must respond with a valid HTTP forbidden response. (403)
If the .passwords file contains the username and password, the server must respond as it would normally.
The format of the passwords file will be:
jrob:supersecretpassword
jack:password
Handle Requests in Threads
Your server must be able to handle simultaneous requests in threads

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!