From d37f95b991af024350b2a9ccb71f318605f76bbd Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Fri, 21 Feb 2020 18:21:59 +0200 Subject: [PATCH] Takes - code --- libraries-3/pom.xml | 27 ++++++------- .../java/com/baeldung/takes/TakesApp.java | 38 +------------------ .../com/baeldung/takes/TakesCreateUser.java | 8 +--- .../com/baeldung/takes/TakesReadUser.java | 1 - 4 files changed, 17 insertions(+), 57 deletions(-) diff --git a/libraries-3/pom.xml b/libraries-3/pom.xml index b684f42c62..51c3f85414 100644 --- a/libraries-3/pom.xml +++ b/libraries-3/pom.xml @@ -120,19 +120,6 @@ - - - - src/main/webapp - true - - - src/main/resources - true - - - - libraries-3 @@ -161,6 +148,16 @@ + + + src/main/resources + true + + + src/main/webapp + true + + @@ -172,6 +169,10 @@ src/main/resources true + + src/main/webapp + true + diff --git a/libraries-3/src/main/java/com/baeldung/takes/TakesApp.java b/libraries-3/src/main/java/com/baeldung/takes/TakesApp.java index cba715846f..93c34f8aff 100644 --- a/libraries-3/src/main/java/com/baeldung/takes/TakesApp.java +++ b/libraries-3/src/main/java/com/baeldung/takes/TakesApp.java @@ -3,10 +3,7 @@ package com.baeldung.takes; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collection; -import org.takes.Request; import org.takes.Response; import org.takes.facets.fallback.Fallback; import org.takes.facets.fallback.FbChain; @@ -14,16 +11,11 @@ import org.takes.facets.fallback.FbStatus; import org.takes.facets.fallback.RqFallback; import org.takes.facets.fallback.TkFallback; import org.takes.facets.fork.FkRegex; -import org.takes.facets.fork.Fork; import org.takes.facets.fork.TkFork; import org.takes.http.Exit; import org.takes.http.FtBasic; import org.takes.misc.Opt; -import org.takes.rq.RqHref; import org.takes.rs.RsText; -import org.takes.rs.RsWithBody; -import org.takes.rs.RsWithStatus; -import org.takes.rs.RsWithType; import org.takes.tk.TkSlf4j; import com.zaxxer.hikari.HikariConfig; @@ -31,14 +23,6 @@ import com.zaxxer.hikari.HikariDataSource; public final class TakesApp { - // public static void main(final String... args) throws Exception { - // new FtBasic(new TkFork( - // new FkRegex("/", "Hello, World!"), - // new FkRegex("/index", new TakesIndex()), - // new FkRegex("/contact", new TakesContact()) - // ),6060).start(Exit.NEVER); - // } - public static void main(final String... args) throws IOException, SQLException { new FtBasic( new TkFallback( @@ -47,7 +31,7 @@ public final class TakesApp { new FkRegex("/", "Hello, World!"), new FkRegex("/index", new TakesIndex()), new FkRegex("/contact", new TakesContact()), - new FkRegex("\\A/createUser", new TakesCreateUser(TakesApp.dbConnection())), + new FkRegex("/createUser", new TakesCreateUser(TakesApp.dbConnection())), new FkRegex("\\A/readUser", new TakesReadUser(TakesApp.dbConnection())) ) ), @@ -67,26 +51,6 @@ public final class TakesApp { ).start(Exit.NEVER); } - - // public static void main(final String... args) throws IOException { - // - // new FtBasic( - // new TkFork( - // new Fork() { - // @Override - // public Opt route(Request req) throws Exception { - // if (new RqHref.Base(req).href().path().equals("/entry")) { - // return new Opt.Single(new RsWithStatus(new RsWithType(new RsWithBody("hello this is for request"), "text/html"), 200)); - // } else { - // return new Opt.Single(null); - // } - // } - // } - // ),6060).start(Exit.NEVER); - // - // - // } - private static Connection dbConnection() throws SQLException { HikariConfig config = new HikariConfig(); diff --git a/libraries-3/src/main/java/com/baeldung/takes/TakesCreateUser.java b/libraries-3/src/main/java/com/baeldung/takes/TakesCreateUser.java index 07b9d803db..5aae7f1ab4 100644 --- a/libraries-3/src/main/java/com/baeldung/takes/TakesCreateUser.java +++ b/libraries-3/src/main/java/com/baeldung/takes/TakesCreateUser.java @@ -1,7 +1,6 @@ package com.baeldung.takes; import java.io.IOException; -import java.net.URI; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -9,12 +8,9 @@ import java.sql.SQLException; import org.takes.Request; import org.takes.Response; import org.takes.Take; -import org.takes.misc.Href; import org.takes.rq.RqForm; -import org.takes.rq.RqHref; import org.takes.rq.form.RqFormSmart; -import org.takes.rs.RsHtml; -import org.takes.rs.RsVelocity; +import org.takes.rs.RsWithStatus; public final class TakesCreateUser implements Take { @@ -43,7 +39,7 @@ public final class TakesCreateUser implements Take { e.printStackTrace(); } - return new RsHtml(new RsVelocity(this.getClass().getResource("/templates/index.vm") ,new RsVelocity.Pair("userName", "Anshul"))); + return new RsWithStatus(200); } } diff --git a/libraries-3/src/main/java/com/baeldung/takes/TakesReadUser.java b/libraries-3/src/main/java/com/baeldung/takes/TakesReadUser.java index 3d0b85fef3..0fc2aa188e 100644 --- a/libraries-3/src/main/java/com/baeldung/takes/TakesReadUser.java +++ b/libraries-3/src/main/java/com/baeldung/takes/TakesReadUser.java @@ -13,7 +13,6 @@ import org.takes.Request; import org.takes.Response; import org.takes.Take; import org.takes.misc.Href; -import org.takes.misc.VerboseIterable; import org.takes.rq.RqHref; import org.takes.rs.RsJson;