String uri = null;
try {
HttpRequest requestFromBrowser = getRequestFromBrowser();
uri = requestFromBrowser.uri();
if (uri.indexOf("/dyn/stopserver") != -1) {
sendResponseToBrowser(new NoCacheHttpResponse(200, "OK", "Killing Server"));
System.exit(1);
}
String fileName = fileNamefromURI(uri);
sendResponseToBrowser(new HttpFileResponse(fileName, null, false, false));
} catch (FileIsDirectoryException dirEx) {
try {
if ("/".equals(uri)) uri = "/demo";
if (uri.endsWith("/")) uri = uri.substring(0, uri.length() - 1);
sendResponseToBrowser(new NoCacheHttpResponse(200, "OK", "<script>location.href='"+uri+"/index.htm'</script>"));
} catch (IOException e) {
logger.warning(dirEx.getMessage());
}
logger.warning(dirEx.getMessage());
} catch (FileNotFoundRuntimeException fnfre) {
try {
sendResponseToBrowser(new NoCacheHttpResponse(404, "FileNotFound", "<html><h2>404 File Not Found</h2></html>"));
} catch (IOException e) {
logger.warning(fnfre.getMessage());
}
logger.warning(fnfre.getMessage());
}