| | |
| | | /* Statuscodes */ |
| | | public static final int SC_OK = 200; |
| | | public static final int SC_PARTIAL_CONTENT = 206; |
| | | public static final int SC_FORBIDDEN = 403; |
| | | public static final int SC_NOT_FOUND = 404; |
| | | public static final int SC_METHOD_NOT_ALLOWED = 405; |
| | | public static final int SC_UNPROCESSABLE_ENTITY = 422; |
| | |
| | | public static final String WELCOME_FILE = "index.html"; |
| | | |
| | | /* Ablageort fuer Webinhalte */ |
| | | protected final String fileBase; |
| | | //protected final String fileBase; |
| | | |
| | | public static final String ATTR_FILE_BASE = "fileBase"; |
| | | |
| | | /** |
| | | * Ein neues Objekt der Klasse FileHandler erzeugen |
| | |
| | | * Ordners im Dateisystem, der die Inhalte enthaelt, die von diesem |
| | | * Handler ausgeliefert werden sollen |
| | | */ |
| | | /* |
| | | public FileHandler(String absoluteDirectoryPathAndName) { |
| | | this.fileBase = absoluteDirectoryPathAndName; |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * Die Datei ermitteln, die sich aus dem angefragten URL ergibt, prüfen, |
| | |
| | | Headers headers = e.getRequestHeaders(); |
| | | if (headers.containsKey(RANGE_HEADER)) { |
| | | FileActor fa = new FileActor(); |
| | | fa.serveFileParts(e, new File(fileBase, fName)); |
| | | fa.serveFileParts(e, new File(e.getHttpContext().getAttributes().get(ATTR_FILE_BASE).toString(), fName)); |
| | | } else { |
| | | if (fName.length() < 1 || fName.endsWith(STR_SLASH)) { |
| | | fName += WELCOME_FILE; |
| | | } |
| | | HttpResponder fs = new HttpResponder(); |
| | | fs.serveFile(e, new File(fileBase, fName)); |
| | | fs.serveFile(e, new File(e.getHttpContext().getAttributes().get(ATTR_FILE_BASE).toString(), fName)); |
| | | } |
| | | } |
| | | } |
| | |
| | | * Anfertigen und Senden der Antwort |
| | | * @return Name der gewünschten Datei |
| | | */ |
| | | protected String getFileName(HttpExchange e) { |
| | | public String getFileName(HttpExchange e) { |
| | | String ctxPath = e.getHttpContext().getPath(); |
| | | String uriPath = e.getRequestURI().getPath(); |
| | | logger.info(uriPath); |
| | | return uriPath.substring(ctxPath.length()); |
| | | } |
| | | |
| | | /*public String getFileBase() { |
| | | return this.e.getHttpContext().getAttributes().get(ATTR_FILE_BASE).toString(); |
| | | }*/ |
| | | |
| | | } |