Controllers, improvements
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 4 Oct 2016 13:27:41 +0000 (15:27 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Tue, 4 Oct 2016 13:27:41 +0000 (15:27 +0200)
src/main/java/com/prueba/controllers/rest/ApiController.java
src/main/java/com/prueba/controllers/rest/LoginController.java
src/main/java/com/prueba/controllers/rest/PagesController.java
src/main/java/com/prueba/controllers/rest/RestController.java [new file with mode: 0644]
src/main/java/com/prueba/core/web/controller/Controller.java [deleted file]
src/main/java/com/prueba/view/login/PageImpl.java [deleted file]
src/main/java/com/prueba/view/page/PageImpl.java [new file with mode: 0644]

index 3eeb5ad..f003452 100644 (file)
@@ -12,13 +12,12 @@ import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.prueba.core.context.util.AntPathMatcher;
-import com.prueba.core.web.controller.Controller;
 import com.prueba.model.domain.AccountResource;
 import com.prueba.services.impl.ApiServiceImpl;
 import com.sun.net.httpserver.Headers;
 import com.sun.net.httpserver.HttpExchange;
 
-public class ApiController implements Controller {
+public class ApiController implements RestController {
        private static final String CONTENT_TYPE_JSON = "application/json";
        private static final String CONTENT_TYPE_HEADER = "Content-Type";
        private static final Logger LOGGER = LoggerFactory.getLogger(ApiController.class);
index e0ef2d4..663b524 100644 (file)
@@ -2,11 +2,10 @@ package com.prueba.controllers.rest;
 
 import java.io.IOException;
 
-import com.prueba.core.web.controller.Controller;
 import com.prueba.services.impl.LoginServiceImpl;
 import com.sun.net.httpserver.HttpExchange;
 
-public class LoginController implements Controller {
+public class LoginController implements RestController {
        
        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
index 38c10d9..376ce77 100644 (file)
@@ -5,11 +5,10 @@ import java.io.OutputStream;
 
 import com.prueba.core.context.security.persistence.SessionInfo;
 import com.prueba.core.context.security.persistence.context.SessionContext;
-import com.prueba.core.web.controller.Controller;
-import com.prueba.view.login.PageImpl;
+import com.prueba.view.page.PageImpl;
 import com.sun.net.httpserver.HttpExchange;
 
-public class PagesController implements Controller {
+public class PagesController implements RestController {
 
        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
diff --git a/src/main/java/com/prueba/controllers/rest/RestController.java b/src/main/java/com/prueba/controllers/rest/RestController.java
new file mode 100644 (file)
index 0000000..4324091
--- /dev/null
@@ -0,0 +1,7 @@
+package com.prueba.controllers.rest;
+
+import com.sun.net.httpserver.HttpHandler;
+
+public interface RestController extends HttpHandler {
+
+}
diff --git a/src/main/java/com/prueba/core/web/controller/Controller.java b/src/main/java/com/prueba/core/web/controller/Controller.java
deleted file mode 100644 (file)
index 2584910..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.prueba.core.web.controller;
-
-import com.sun.net.httpserver.HttpHandler;
-
-public interface Controller extends HttpHandler {
-
-}
diff --git a/src/main/java/com/prueba/view/login/PageImpl.java b/src/main/java/com/prueba/view/login/PageImpl.java
deleted file mode 100644 (file)
index aa03c46..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.prueba.view.login;
-
-import java.io.IOException;
-
-import org.rendersnake.HtmlCanvas;
-
-public class PageImpl {
-
-       public String doPage(int number, String userName) throws IOException {
-               final HtmlCanvas html = new HtmlCanvas();
-               return html
-                         .html()
-                           .body()
-                              .h1().content("PAGE: " + number)
-                              .output().content("Hello: " + userName)
-                           ._body()
-                         ._html()
-                         .toHtml();
-       }
-
-}
diff --git a/src/main/java/com/prueba/view/page/PageImpl.java b/src/main/java/com/prueba/view/page/PageImpl.java
new file mode 100644 (file)
index 0000000..d0de79f
--- /dev/null
@@ -0,0 +1,24 @@
+package com.prueba.view.page;
+
+import static org.rendersnake.HtmlAttributesFactory.href;
+
+import java.io.IOException;
+
+import org.rendersnake.HtmlCanvas;
+
+public class PageImpl {
+
+       public String doPage(int number, String userName) throws IOException {
+               final HtmlCanvas html = new HtmlCanvas();
+               return html
+                         .html()
+                           .body()
+                              .h1().content("PAGE: " + number)
+                              .h1().content("Hello: " + userName)
+                              .h1().a(href("/app/login/logout.html"))
+                           ._body()
+                         ._html()
+                         .toHtml();
+       }
+
+}