Pages: return not found when invalid URL
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 3 Oct 2016 12:33:54 +0000 (14:33 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 3 Oct 2016 12:33:54 +0000 (14:33 +0200)
src/main/java/com/prueba/core/context/security/handle/PagesHandler.java
src/main/java/com/prueba/resources/controllers/PagesController.java

index b10261a..ce27e95 100644 (file)
@@ -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;
index 167261c..deda099 100644 (file)
@@ -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());
                }