Package http.server
Class WebServer
java.lang.Object
http.server.WebServer
public class WebServer
extends java.lang.Object
WebServer is a simple web-server that handles HTTP GET, POST, PUT, HEAD and DELETE methods.
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringFILE_NOT_FOUNDPath to Error HTML pageprotected static java.lang.StringFILES_DIRECTORYPath to resource directoryprotected static java.lang.StringINDEXIndex page of a view inside the server. -
Constructor Summary
Constructors Constructor Description WebServer() -
Method Summary
Modifier and Type Method Description inthandleGet(java.io.BufferedOutputStream out, java.lang.String filename)Handles the GET requestinthandleHead(java.io.BufferedOutputStream out, java.lang.String filename)Handles HEAD requeststatic voidmain(java.lang.String[] args)Start the application.java.lang.StringresponseHeader(java.lang.String status, java.lang.String extension, long fileLength)Returns the equivalent Headers taking into account the paramentersprotected voidstart()WebServer constructor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
FILES_DIRECTORY
protected static final java.lang.String FILES_DIRECTORYPath to resource directory- See Also:
- Constant Field Values
-
FILE_NOT_FOUND
protected static final java.lang.String FILE_NOT_FOUNDPath to Error HTML page- See Also:
- Constant Field Values
-
INDEX
protected static final java.lang.String INDEXIndex page of a view inside the server. Constant to be appended to a path- See Also:
- Constant Field Values
-
-
Constructor Details
-
WebServer
public WebServer()
-
-
Method Details
-
start
protected void start()WebServer constructor. -
handleGet
public int handleGet(java.io.BufferedOutputStream out, java.lang.String filename)Handles the GET request- Parameters:
out- BufferedOutputStream attached to the connected socketfilename- String showing the name of the researched file- Returns:
- status code of the http request
-
handleHead
public int handleHead(java.io.BufferedOutputStream out, java.lang.String filename)Handles HEAD request- Parameters:
out- BufferedOutputStream attached to the connected socketfilename- String showing the name of the researched file- Returns:
- int status code
-
responseHeader
public java.lang.String responseHeader(java.lang.String status, java.lang.String extension, long fileLength)Returns the equivalent Headers taking into account the paramenters- Parameters:
status- statusCode and statusTextextension- extension of the corresponding filefileLength- length of the corresponding file- Returns:
- Headers
-
main
public static void main(java.lang.String[] args)Start the application.- Parameters:
args- Command line parameters are not used.
-