From 78d7078d97625e4a8d2d6863318c192f910f2ec9 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sun, 11 Apr 2021 11:09:36 +0000 Subject: [PATCH] UI-Verbesserungen in Arbeit --- src/de/uhilger/mediaz/api/AbstractHandler.java | 62 +++++++++++++++++++++++++++---- 1 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/de/uhilger/mediaz/api/AbstractHandler.java b/src/de/uhilger/mediaz/api/AbstractHandler.java index 45befae..728107a 100644 --- a/src/de/uhilger/mediaz/api/AbstractHandler.java +++ b/src/de/uhilger/mediaz/api/AbstractHandler.java @@ -1,7 +1,19 @@ /* - * 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. + Mediazentrale - Personal Media Center + Copyright (C) 2021 Ulrich Hilger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ package de.uhilger.mediaz.api; @@ -17,7 +29,8 @@ /** * - * @author ulrich + * @author Ulrich Hilger + * @version 1, 8.4.2021 */ public abstract class AbstractHandler extends JsonHelper implements HttpHandler { @@ -35,11 +48,19 @@ /** Name der HTTP Methode DELETE */ public static final String HTTP_DELETE = "DELETE"; + public static final int RTC_OK = 200; + public static final int RTC_NOT_FOUND = 404; + + protected int returnCode; + + public AbstractHandler() { + this.returnCode = RTC_OK; + } + @Override public void handle(HttpExchange e) throws IOException { String method = e.getRequestMethod(); String response = ""; - int code = 200; switch(method) { case HTTP_GET: String json = get(e); @@ -47,7 +68,7 @@ response = json; } else { response = "nicht gefunden"; - code = 404; + returnCode = RTC_NOT_FOUND; } break; @@ -57,7 +78,6 @@ case HTTP_POST: response = post(e); - code = 404; break; case HTTP_DELETE: @@ -69,10 +89,19 @@ } break; } - e.sendResponseHeaders(code, response.length()); + logger.fine(response); + e.sendResponseHeaders(getReturnCode(), response.length()); OutputStream os = e.getResponseBody(); os.write(response.getBytes()); os.close(); + } + + protected void setReturnCode(int code) { + this.returnCode = code; + } + + protected int getReturnCode() { + return returnCode; } protected String bodyLesen(HttpExchange e) throws IOException { @@ -89,10 +118,27 @@ return json; } + protected String put(HttpExchange e) throws IOException { + setReturnCode(RTC_NOT_FOUND); + return "nicht unterstuetzt"; + } + + protected String post(HttpExchange e) { + setReturnCode(RTC_NOT_FOUND); + return "nicht unterstuetzt"; + } + + protected boolean delete(HttpExchange e) { + setReturnCode(RTC_NOT_FOUND); + return false; + } + protected abstract String get(HttpExchange e); + /* protected abstract String put(HttpExchange e) throws IOException; protected abstract String post(HttpExchange e); protected abstract boolean delete(HttpExchange e); + */ } -- Gitblit v1.9.3