-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServer.java
More file actions
72 lines (64 loc) · 2.35 KB
/
WebServer.java
File metadata and controls
72 lines (64 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package webserver;
import Config.MimeTypes;
import Config.HttpdConf;
import Config.htaccess;
import Config.htpasswd;
import Response.ResponseBase;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference.Metadata;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.file.Files;
import java.util.HashMap;
/**
* Main WebServer class
* @author Sapan
*/
public class WebServer {
public static int DEFAULT_PORT = 8080;
public static String SERVER_ROOT = null;
public static String DOCUMENT_ROOT = null;
public static String LOG_FILE = null;
public static String abc;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO code application logic here
File config_file = new File("/Config/httpd.conf");
FileInputStream httpd = new FileInputStream(config_file);
byte[] httpd_data = new byte[(int) config_file.length()];
httpd.read(httpd_data);
httpd.close();
String config_content = new String(httpd_data, "UTF-8");
HttpdConf httpd_object = new HttpdConf(config_content);
File mime_file = new File("/Config/mime.types");
FileInputStream mime = new FileInputStream(mime_file);
byte[] mime_data = new byte[(int) mime_file.length()];
mime.read(mime_data);
mime.close();
String mime_content = new String(mime_data, "UTF-8");
MimeTypes mime_object = new MimeTypes(mime_content);
ServerSocket serverSocket = new ServerSocket(DEFAULT_PORT);
Socket clientSocket = null;
while(true) {
System.out.println("Server is now accepting connections from Port 8096");
clientSocket = serverSocket.accept();
Thread t = new Thread(new Worker(clientSocket, httpd_object, mime_object));
t.start();
}
}
}