From: Gustavo Martin Morcuende Date: Mon, 3 Oct 2016 12:33:54 +0000 (+0200) Subject: Pages: return not found when invalid URL X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=e9573cb37bc0620e0288bfe7c41c6253d2a851df;p=WebAppTest%2F.git Pages: return not found when invalid URL --- diff --git a/src/main/java/com/prueba/core/context/security/handle/PagesHandler.java b/src/main/java/com/prueba/core/context/security/handle/PagesHandler.java index b10261a..ce27e95 100644 --- a/src/main/java/com/prueba/core/context/security/handle/PagesHandler.java +++ b/src/main/java/com/prueba/core/context/security/handle/PagesHandler.java @@ -2,10 +2,6 @@ package com.prueba.core.context.security.handle; import java.io.IOException; import java.net.URI; -import java.time.LocalDateTime; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import com.prueba.core.context.security.persistence.SessionInfo; import com.prueba.core.context.security.persistence.Sessions; diff --git a/src/main/java/com/prueba/resources/controllers/PagesController.java b/src/main/java/com/prueba/resources/controllers/PagesController.java index 167261c..deda099 100644 --- a/src/main/java/com/prueba/resources/controllers/PagesController.java +++ b/src/main/java/com/prueba/resources/controllers/PagesController.java @@ -30,6 +30,7 @@ public class PagesController implements Controller { final String requestedURI = httpExchange.getRequestURI().toString(); final PageImpl pageImpl = new PageImpl(); + int responseStatus = 200; String html = ""; switch (requestedURI) { case "/app/pages/page_1.html": @@ -42,12 +43,11 @@ public class PagesController implements Controller { html = pageImpl.doPage(2, getSafeUserName()); break; default: - httpExchange.sendResponseHeaders(404, 0); + responseStatus = 404; break; } - httpExchange.sendResponseHeaders(200, html.length()); - + httpExchange.sendResponseHeaders(responseStatus, html.length()); try (final OutputStream os = httpExchange.getResponseBody()) { os.write(html.getBytes()); }