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 serverWebServerjava
java server.Webserver someabsolutepathtodocumentroot
In the above example, is the port number that the server will listen to and someabsolutepathtodocumentroot 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
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
If the file does not exist, the server must respond to the client with a valid HTTP not found response
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
If the file does not exist, the server must respond to the client with a valid HTTP not found response
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
If the file is not successfully created, the server must respond with a valid HTTP error response
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
If the file exists and is not successfully deleted, the server must respond with a valid HTTP error response
If the file does not exist, the server must respond to the client with a valid HTTP not found response
Note that in all cases with a body, the server must include the necessary HTTP headers in the response eg ContentLength and ContentType, Date Some requests may require additional headers.
Support Simple Authentication
Your server must be able to handle the 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 This response must contain the header WWWAuthenticate, with the value Basic realm 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.
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
