Skip to content

ddellagiacoma/webarch-2016-assignment-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Extending the simple web server

1. INTRODUCTION

The goal of this assignment is to extend a concurrent http mini-server. The extension aims to execute external processes and handle their responses. Moreover, this allows the external process to respond with dynamic web pages, which will be managed by the server.

2. IMPLEMENTATION

First of all, the server decomposes the client request into different parts. A well-formed request should have this format:

GET /home.html HTTP/1.1

In this case the server responds to the client with the correspondent file of the request or, if it does not exist, with an error message. On the other hand, if the URL starts with the token “process/” the server execute an external process and responds to the client with the output generated by the process.

Let’s see in details how the server works when the URL starts with “process/” (e.g. process/add?op1=4&op2=7). The server splits the request in two parts process/add and op1=4&op2=7. Then, it executes the external process (in our case a jar file) described in the first part of the request (process/add) passing as parameter the second part (op1=4&op2=7). In this case, the process will be executed in this way:

java –jar process/add.jar op1=4&op2=7

The process add.jar checks the completeness and correctness of the parameter and print the result (or any errors):

"<html><head><h1>" + sum + "</h1></head></html>"

The server captures the output of the process (thanks to this guide http://www.rgagnon.com/javadetails/java-0014.html) and sends it to the client.

3. DEPLOYMENT

The server can be started either by running it in NetBeans (or any other IDE) or typing in the terminal:

java –jar TinyHttpd.jar

The port number can be passed as parameter. If it is not defined, the server will use the default port number 8000.

The request can be send to the server through a web browser using the following URL:

http://localhost:8000/index.html

Where 8000 corresponds to the port number and /index.html corresponds to the desired file.

Otherwise, the following URL can be used to run the external process and visualize its result:

http://localhost:8000/process/add?op1=5&op2=7

Where 5 and 7 corresponds to two Integers.

4. COMMENTS AND NOTES

Three different browsers have been used to test the mini-server. While Google Chrome and Microsoft Edge displays correctly the dynamic web pages generated by the process, Mozilla Firefox displays the whole response (i.e. <html><head><h1>12<h1></head></html>).