HW#5 --- last modified
January 01 1970 00:00:00..
Solution set.
Due date: May 13
Files to be submitted:
MyWebServer.java
MyServerProperties.txt
test.html
test.cgi
Purpose:
To become more familiar with sockets. To
understand
how CGI works. To write a simple perl program. To use a Properties file.
Specification:
Your goal in this last assignment is to write a simple web server in Java
capable of serving HTML files without graphics and capable of executing
CGI scripts. You can do this assignment on your machine at home if you install Perl. This assignment makes no use of the Tomcat server on iqaluit.
Your server should be in the file MyWebServer.java.
When it is run it reads in the properties file (use the Properties class)
MyServerProperties.txt. This file should contain info on which port the
server runs on, what is the path to Perl, the name of the machine, and what is the real location of the
directories served by the server. Suppose the port number is set to 5432
and your URL is www.mymachine.com. Then your server uses a ServerSocket
to listen to requests on this port. It should use threads so it can handle multiple requests at the same time. Your server should be able to
handle requests for HTML documents in:
http://www.machine.com:5432/public_html
and handle requests for CGI scripts in:
http://www.machine.com:5432/cgi-bin
Your server only needs to be able to process HTTP GET requests. It can
ignore all other requests. If the request is for an HTML document, your
server just returns the document; if the request is for cgi script, use
the class RunTime to exec a shell process with the appropriate runtime
variables and run the script in question. The files test.html and test.cgi
should be test files to prove your server works. test.html can be an
html file of your choice that does not contain images. The file test.cgi
should be a perl script that prints out the environment variables and
implements a simple counter.
Point Breakdown
Departmental coding guidelines for Java followed | 1pt |
Properties file read by server |
1pt |
Server listens for and accepts connections | 1pt |
Threads used so server can handle multiple requests. | 1pt |
Server processes GET requests and serves HTML docs. In particular,
test.html | 2pt |
Server exec's process and sets up environment variables for
cgi requests. | 1pt |
The server only handles requests for documents in the two directories public_html and cgi-bin. | 1pt |
test.cgi outputs environment variables | 1pt |
test.cgi implements is also a counter
| 1pt |
Total | 10pts |
|