----------------------- Lab #05 for CST8165 due November 22, 2006 (* DUE DATE UPDATED *) ----------------------- -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Global weight: 5% of your total mark this term. Due date: At the start of your lab period on Wednesday November 22. Interim submissions: Wednesday November 8 and 15 You will submit whatever progress you have made on this assignment before midnight on Wednesday November 8 and 15. The on-line deliverables for this exercise are to be submitted on-line in the Linux Lab T127 using the "cstsubmit" method described in the exercise description, below. No paper; no email; no FTP. Late-submission date: I will accept without penalty exercises that are submitted late but before 10h00 (10am) Thursday November 23, 2006. After that late-submission date, the exercise is worth zero marks. Interim work must be submitted by midnight on November 8 and 15. Exercises submitted by the *due date* will be marked on-line and your marks will be sent to you by email after the late-submission date. Code submitted without your added useful comments (no matter what its source) will not be marked (except for the Pig Latin code file). Exercise Synopsis ----------------- Modify an existing Java-based HTTP server. Document it. Test it. Where to work ------------- Submissions must run cleanly in the T127 Linux Lab, though you are free to develop and work on them anywhere you like. If you develop elsewhere, make sure the code works on the Linux Lab machines as well; that's where I test it! Code submitted without your added useful comments (no matter what its source) will not be marked (except for the Pig Latin code file). Resources / Documentation ------------------------- See week10notes.txt : "Coding an HTTP server (Java)" Suggested template from which to start coding a simple HTTP server: http://www.brics.dk/ixwt/examples/FileServer.java - this version does not adhere to the HTTP RFC in many respects - needs comments on functionality (not on how Java works) - has many "public" items that should be made private - may be missing things such as closing opened files... - client request parsing is broken and also not very "liberal" - needs a "time-out" so it doesn't run all day Code Quality and Portability ---------------------------- A. You must include useful comment blocks ahead of the code you write or modify. Code submitted without your added useful comments will not be marked (except for the Pig Latin code file). B. Marks are awarded for readability and elegance, not just correctness. If your code can't be read, you're useless in a team project. Coding the server ----------------- 1) Using the sample code (above), implement a basic HTTP RFC 2616 server with Java class name "PigLatinHTTP" that handles the two methods that MUST BE supported by a general-purpose HTTP server. (5.1.1 p.36) The 145-line FileServer code (above) is a very good starting point; but, note its many flaws (and lack of comments). 2) Add comments to the given source code. Fix the above problems. 3) Your PigLatinHTTP server must accept HTTP protocol versions 1.0 and 1.1 in requests from clients. (The sample code already does this.) Your server does *not* have to implement: - persistent connections - continuation lines - URIs with blanks or escapes (e.g. + or %20) - reading header lines from a client (only read one client request line) - checking for a mandatory "Host:" field (even for HTTP 1.1) The server need only read a single request line from a client. (The above sample code already does this; only one line is read.) If in doubt about what you need to implement, ask your instructor. 4) BE LIBERAL in the syntax you accept in client requests to your server. For example: Allow extra white-space after the method and before the HTTP version string. You may assume that the URI in the client request does not contain any whitespace. (Blanks would usually be escaped as %20; however, your server doesn't need to handle blanks or escapes in URIs. See the programming Hints below.) 5) Implement the following additional server response header fields: Server: (pick a name for your PigLatinHTTP server) Content-Length: (the length in bytes of the file being served) Content-Type: (the MIME type of the file being returned) Date: (the current date - section 14.18) Last-Modified: (the last modified date of the file being served - 14.29) (Java note: The java.io.File class has methods to return some of the above required information. See the Hints and Resources.) 6) Use the guessContentTypeFromName method to generate your Content-Type field. (The sample code already does this.) 7) Major Change: If the content type being requested is "text/plain", return the "Pig Latin" version of the file, not the regular text. You will find a PigLatinTranslator.java file in the course notes. You can try the translator by building and running it: $ javac PigLatinTranslator.java $ java PigLatinTranslator