-
Name: JIDUNG, LO
-
Assignment name: PA1-JIDUNG-LO
-
Description of my assignment:
Aspect Description MyWebServer- Initializes the server by parsing command-line arguments (document root and port).
- Listens for incoming connections usingServerSocket.
- Spawns a new thread (ClientHandler) for each client connection to handle requests concurrently.
- Tracks active connections usingAtomicIntegerClientHandler- Implements Runnableto handle client requests in a separate thread.
- Parse and validates HTTP requests (e.g., method, file path)
- Sends requested file if they exist and accessible
- Sends error pages for invalid or unauthorized requests (e.g., 404, 403, 400, 500)
- Handles persistent connections (HTTP keep-alive) based on request headers and protocolMgrResponseDTO- Generates HTTP responses with correct status code, heaeders, and body.
- Handles different connection types (close/persistent)
- Follow HTTP standards for responsesMgrResponseCode- Enum class that defines HTTP response codes and their corresponding messages.(e.g., 200 OK, 404 Not Found)
- Ensure consistency in response codeLog- Logs events such as server start, client connections, request processing, and errors.
- Writes logs to a file (tenet.log) with timestamps for tracking and debugging
- Provides methods for logging different levels of messages (info, error)
- Supports multithread-safe logging using synchronized methodsError Handling - Provides error pages (e.g., 400.html,403.html,404.html,500.html) for invalid requests, file not found, or unauthorized access
- Sends appropriate HTTP error responses to clients.
- Logs errors for debugging and monitoring purposesMultithreading - Handles concurrent client requests by running each in a separate thread (). ClientHandler
- Ensures efficient connections even when multiple clients access the server simultaneously. -
A list of submitted files
File Path File Name Description src/main/java/org.example/tenet/MyWebServer.javaMain class that initializes and starts the web server. src/main/java/org.example/tenet/ClientHandler.javaHandles client requests and responses. src/main/java/org.example/tenet/MgrResponseDTO.javaGenerates HTTP responses with status codes and headers. src/main/java/org.example/tenet/MgrResponseCode.javaDefines HTTP response codes and messages. src/main/java/org.example/tenet/Log.javaHandles logging of server events. ./tenet.logLog file for server events. webSource/400.htmlError page for bad requests. webSource/403.htmlError page for forbidden access. webSource/404.htmlError page for not found resources. webSource/500.htmlError page for internal server errors. webSource/index.htmlHome Page** for https://www.scu.edu/ webSource/secret.htmlWeb page for testing access control. Be sure to change permission using chmod 000 PA1-JIDUNG-LO/webSource/secret.htmlbefore testing.webSource/assetsDirectory containing static files. webSource/jsDirectory containing JavaScript files. webSource/livewhaleDirectory containing JavaScript files. webSource/mediaDirectory containing various images webSource/publicDirectory containing images and css Project Directory Structure:
PA1-JIDUNG-LO/ │ ├── src/ │ ├── main/ │ ├── java/ │ │ └── org/example/tenet/ │ │ ├── MyWebServer.java # Main class to initialize and start the web server │ │ ├── ClientHandler.java # Handles client connections in separate threads │ │ ├── MgrResponseDTO.java # Generates HTTP responses with headers and statuses │ │ ├── MgrResponseCode.java # Enum for HTTP response codes and their messages │ │ └── Log.java # Handles logging for server activities │ └── resources/ │ └── static/snapshot/ # Snapshots of the web pages │ ├── page1.jpg │ ├── page2.jpg │ └── ... ├── webSource/ │ ├── 400.html # Error page for "Bad Request" │ ├── 403.html # Error page for "Forbidden" │ ├── 404.html # Error page for "Not Found" │ ├── 500.html # Error page for "Internal Server Error" │ ├── index.html # Home page │ ├── secret.html # Page for testing access control │ ├── assets/ # Directory for static assets (e.g., images, logos) │ ├── js/ # Directory for JavaScript files │ ├── livewhale/ # Directory for livewhale-related files │ ├── media/ # Directory for images │ └── public/ # Public directory for additional images and CSS │ ├── tenet.log # Log file for server activities ├── run.sh # Shortcut shell script to compile and run the server ├── README.md # Documentation for the project
-
Instructions for running
tenetDependency Version Description OpenJDK 17.0.8 Java Development Kit for compiling and running the program. Operating System Any Works on Linux, macOS. CLI/Terminal Any Command-line interface to execute commands. -
Ensure OpenJDK 17 is installed:
Run the following command to install OpenJDK 17 if it is not already installed:
sudo apt install openjdk-17-jdk
-
Open terminal and navigate to the root directory of the
PA1-JIDUNG-LOproject:cd /path/to/PA1-JIDUNG-LO -
Compile the Java files using the following command:
javac src/main/java/org/example/tenet/*.java -
If the compilation is successful, start the web server by running the following command:
java -cp src/main/java org.example.tenet.MyWebServer -document_root "./webSource" -port 8888-
_document_root "./webSource"specifies the directory containing the web files. -
_port 8888specifies the port number on which the server will listen for incoming connections.
Note:
run.shcombines Step 3 and Step 4 into a single script for convenience. If you want to save time, you can simply run:./run.sh
Make sure you are in the document root when running this script.
-
-
Access the Web Server:
- Open a web browser and navigate to
http://localhost:8888/to access the home page. This URL corresponds to theindex.htmlfile in thewebSource/directory.
- Open a web browser and navigate to
-
Additional information—Log and Testing:
- Logs for server activities will be stored in the
tenet.logfile located in the project root. Open another terminal and run the following command to view the logs:tail -f tenet.log
- To test
400.html, try http://localhost:8888 POST. - To test
403.html, first run:Then try http://localhost:8888/secret.html.chmod 000 PA1-JIDUNG-LO/webSource/secret.html
- To test
404.html, try http://localhost:8888/pokemon.html. - To test
500.html, try http://localhost:8888/../secret.txt.
- Logs for server activities will be stored in the
-
-
Snapshots of my web browser
Snapshots of "http://localhost:8888/" Images
Image 1 Image 2 







-
Know Issues:
- Does not support HTTP methods other than GET.
- Limited to serving static content only; no dynamic page generation.
- Lacks HTTPS support.
- Port conflicts may occur; please ensure the specified port is available.
-
Logs Information
- Client requests:
- Timestamp.
- Method (
GET). - File/resource content type.
- Responses:
- Status codes.
- Requested files.
- Errors encountered (if any).
- Connection of each Thread's start/shutdown times.
- Client requests:
chrisluo5311/DistributedSystem
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
