mirror of
https://github.com/JonasunderscoreJones/McWebserver.git
synced 2025-10-23 03:19:19 +02:00
Fixed Verbose Logger issues
This commit is contained in:
parent
ad20f3cca3
commit
6302a9b991
1 changed files with 25 additions and 27 deletions
|
@ -37,13 +37,13 @@ public class HTTPServer implements Runnable {
|
||||||
try {
|
try {
|
||||||
ServerSocket serverConnect = new ServerSocket(PORT);
|
ServerSocket serverConnect = new ServerSocket(PORT);
|
||||||
McWebserver.LOGGER.info("Server started.");
|
McWebserver.LOGGER.info("Server started.");
|
||||||
VerboseLogger.info("Listening for connections on port : \" + PORT + \" ...");
|
McWebserver.LOGGER.info("Listening for connections on port : " + PORT);
|
||||||
|
|
||||||
// we listen until user halts server execution
|
// we listen until user halts server execution
|
||||||
while (true) {
|
while (true) {
|
||||||
HTTPServer myServer = new HTTPServer(serverConnect.accept());
|
HTTPServer myServer = new HTTPServer(serverConnect.accept());
|
||||||
|
|
||||||
VerboseLogger.info("Connecton opened. (" + new Date() + ")");
|
VerboseLogger.info("Connection opened. (" + new Date() + ")");
|
||||||
|
|
||||||
// create dedicated thread to manage the client connection
|
// create dedicated thread to manage the client connection
|
||||||
Thread thread = new Thread(myServer);
|
Thread thread = new Thread(myServer);
|
||||||
|
@ -51,7 +51,7 @@ public class HTTPServer implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
McWebserver.LOGGER.info("Server Connection error : " + e.getMessage());
|
VerboseLogger.error("Server Connection error : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,13 +89,12 @@ public class HTTPServer implements Runnable {
|
||||||
byte[] fileData = readFileData(file, fileLength);
|
byte[] fileData = readFileData(file, fileLength);
|
||||||
|
|
||||||
// we send HTTP Headers with data to client
|
// we send HTTP Headers with data to client
|
||||||
out.println("HTTP/1.1 501 Not Implemented");
|
VerboseLogger.info("HTTP/1.1 501 Not Implemented");
|
||||||
out.println("Server: Java HTTP Server from SSaurel : 1.0");
|
VerboseLogger.info("Server: Java HTTP Server from SSaurel : 1.0"); //hopefully enough credits
|
||||||
out.println("Date: " + new Date());
|
VerboseLogger.info("Date: " + new Date());
|
||||||
out.println("Content-type: " + contentMimeType);
|
VerboseLogger.info("Content-type: " + contentMimeType);
|
||||||
out.println("Content-length: " + fileLength);
|
VerboseLogger.info("Content-length: " + fileLength);
|
||||||
out.println(); // blank line between headers and content, very important !
|
VerboseLogger.info(""); // blank line between headers and content, very important !
|
||||||
out.flush(); // flush character output stream buffer
|
|
||||||
// file
|
// file
|
||||||
dataOut.write(fileData, 0, fileLength);
|
dataOut.write(fileData, 0, fileLength);
|
||||||
dataOut.flush();
|
dataOut.flush();
|
||||||
|
@ -114,13 +113,12 @@ public class HTTPServer implements Runnable {
|
||||||
byte[] fileData = readFileData(file, fileLength);
|
byte[] fileData = readFileData(file, fileLength);
|
||||||
|
|
||||||
// send HTTP Headers
|
// send HTTP Headers
|
||||||
out.println("HTTP/1.1 200 OK");
|
VerboseLogger.info("HTTP/1.1 200 OK");
|
||||||
out.println("Server: Java HTTP Server from SSaurel : 1.0");
|
VerboseLogger.info("Server: Java HTTP Server from SSaurel : 1.0");
|
||||||
out.println("Date: " + new Date());
|
VerboseLogger.info("Date: " + new Date());
|
||||||
out.println("Content-type: " + content);
|
VerboseLogger.info("Content-type: " + content);
|
||||||
out.println("Content-length: " + fileLength);
|
VerboseLogger.info("Content-length: " + fileLength);
|
||||||
out.println(); // blank line between headers and content, very important !
|
VerboseLogger.info(""); // blank line between headers and content, very important !
|
||||||
out.flush(); // flush character output stream buffer
|
|
||||||
|
|
||||||
dataOut.write(fileData, 0, fileLength);
|
dataOut.write(fileData, 0, fileLength);
|
||||||
dataOut.flush();
|
dataOut.flush();
|
||||||
|
@ -134,11 +132,11 @@ public class HTTPServer implements Runnable {
|
||||||
try {
|
try {
|
||||||
fileNotFound(out, dataOut, fileRequested);
|
fileNotFound(out, dataOut, fileRequested);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
McWebserver.LOGGER.info("Error with file not found exception : " + ioe.getMessage());
|
VerboseLogger.error("Error with file not found exception : " + ioe.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
McWebserver.LOGGER.info("Server error : " + ioe);
|
VerboseLogger.error("Server error : " + ioe);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
|
@ -146,7 +144,7 @@ public class HTTPServer implements Runnable {
|
||||||
dataOut.close();
|
dataOut.close();
|
||||||
connect.close(); // we close socket connection
|
connect.close(); // we close socket connection
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
McWebserver.LOGGER.info("Error closing stream : " + e.getMessage());
|
VerboseLogger.error("Error closing stream : " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
VerboseLogger.info("Connection closed.");
|
VerboseLogger.info("Connection closed.");
|
||||||
|
@ -184,17 +182,17 @@ public class HTTPServer implements Runnable {
|
||||||
String content = "text/html";
|
String content = "text/html";
|
||||||
byte[] fileData = readFileData(file, fileLength);
|
byte[] fileData = readFileData(file, fileLength);
|
||||||
|
|
||||||
out.println("HTTP/1.1 404 File Not Found");
|
VerboseLogger.error("HTTP/1.1 404 File Not Found");
|
||||||
out.println("Server: Java HTTP Server from SSaurel : 1.0");
|
VerboseLogger.info("Server: Java HTTP Server from SSaurel : 1.0");
|
||||||
out.println("Date: " + new Date());
|
VerboseLogger.info("Date: " + new Date());
|
||||||
out.println("Content-type: " + content);
|
VerboseLogger.info("Content-type: " + content);
|
||||||
out.println("Content-length: " + fileLength);
|
VerboseLogger.info("Content-length: " + fileLength);
|
||||||
out.println(); // blank line between headers and content, very important !
|
VerboseLogger.info(""); // blank line between headers and content, very important !
|
||||||
out.flush(); // flush character output stream buffer
|
out.flush(); // flush character output stream buffer
|
||||||
|
|
||||||
dataOut.write(fileData, 0, fileLength);
|
dataOut.write(fileData, 0, fileLength);
|
||||||
dataOut.flush();
|
dataOut.flush();
|
||||||
|
|
||||||
VerboseLogger.info("File " + fileRequested + " not found");
|
VerboseLogger.error("File " + fileRequested + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue