From: Gustavo Martin Morcuende Date: Tue, 4 Oct 2016 13:27:41 +0000 (+0200) Subject: Controllers, improvements X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=ce70f92998ebfd0791bdd8ea8ec3cd1b2c9da426;p=WebAppTest%2F.git Controllers, improvements --- diff --git a/src/main/java/com/prueba/controllers/rest/ApiController.java b/src/main/java/com/prueba/controllers/rest/ApiController.java index 3eeb5ad..f003452 100644 --- a/src/main/java/com/prueba/controllers/rest/ApiController.java +++ b/src/main/java/com/prueba/controllers/rest/ApiController.java @@ -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); diff --git a/src/main/java/com/prueba/controllers/rest/LoginController.java b/src/main/java/com/prueba/controllers/rest/LoginController.java index e0ef2d4..663b524 100644 --- a/src/main/java/com/prueba/controllers/rest/LoginController.java +++ b/src/main/java/com/prueba/controllers/rest/LoginController.java @@ -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 { diff --git a/src/main/java/com/prueba/controllers/rest/PagesController.java b/src/main/java/com/prueba/controllers/rest/PagesController.java index 38c10d9..376ce77 100644 --- a/src/main/java/com/prueba/controllers/rest/PagesController.java +++ b/src/main/java/com/prueba/controllers/rest/PagesController.java @@ -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 index 0000000..4324091 --- /dev/null +++ b/src/main/java/com/prueba/controllers/rest/RestController.java @@ -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 index 2584910..0000000 --- a/src/main/java/com/prueba/core/web/controller/Controller.java +++ /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 index aa03c46..0000000 --- a/src/main/java/com/prueba/view/login/PageImpl.java +++ /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 index 0000000..d0de79f --- /dev/null +++ b/src/main/java/com/prueba/view/page/PageImpl.java @@ -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(); + } + +}