From 2ab0397484785894c0836d0ef341b0c6e3cbe9db Mon Sep 17 00:00:00 2001 From: ipcrm Date: Tue, 30 Jan 2018 10:11:28 -0500 Subject: [PATCH 1/3] init v2 --- pom.xml | 2 +- src/main/java/com/puppet/sample/App.java | 15 ++++++++++++++- src/main/resources/templates/index.html | 15 +++++++++++++++ src/test/java/com/puppet/sample/AppTest.java | 16 ++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/templates/index.html create mode 100644 src/test/java/com/puppet/sample/AppTest.java diff --git a/pom.xml b/pom.xml index 5b5aa8e..21f78e5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.puppet.sample java-webapp jar - 1.0 + 1.1 java-webapp http://maven.apache.org diff --git a/src/main/java/com/puppet/sample/App.java b/src/main/java/com/puppet/sample/App.java index 673c845..5f1c775 100644 --- a/src/main/java/com/puppet/sample/App.java +++ b/src/main/java/com/puppet/sample/App.java @@ -4,6 +4,7 @@ import spark.Request; import spark.Response; import spark.Spark; +import spark.template.thymeleaf.ThymeleafTemplateEngine; import java.util.HashMap; import java.util.Map; @@ -41,8 +42,20 @@ public static void main(String[] args) { System.out.println(requestInfoToString(request)); }); - get("/", (request,response) -> "Hello World!"); + get("/", App::helloWorld, new ThymeleafTemplateEngine()); } + public static ModelAndView helloWorld(Request req, Response res) { + Map params = new HashMap<>(); + + App t = new App(); + params.put("version", t.getClass().getPackage().getImplementationVersion() ); + + App test = new App(); + params.put("lang", test.enMsg()); + + return new ModelAndView(params, "index"); + } + } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..9ef0ad5 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,15 @@ + + + + Hello world + + + +
+
+

[[${lang}]]

+
+

Version: [[${version}]]

+
+ + diff --git a/src/test/java/com/puppet/sample/AppTest.java b/src/test/java/com/puppet/sample/AppTest.java new file mode 100644 index 0000000..faeb822 --- /dev/null +++ b/src/test/java/com/puppet/sample/AppTest.java @@ -0,0 +1,16 @@ +package com.puppet.sample; + +import org.junit.Test; +import org.junit.Rule; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import spark.servlet.SparkApplication; + +public class AppTest +{ + @Test + public void testMsg() { + assertEquals("Hello World!", new App().enMsg()); + } +} From 342e2811aa8392075c80e15a94c80a0b0afd876f Mon Sep 17 00:00:00 2001 From: ipcrm Date: Tue, 30 Jan 2018 10:11:50 -0500 Subject: [PATCH 2/3] init v3 --- pom.xml | 7 +++- src/main/java/com/puppet/sample/App.java | 32 ++++++++++++++----- src/main/resources/templates/index.html | 7 ++++ src/test/java/com/puppet/sample/AppTest.java | 16 ---------- .../java/com/puppet/sample/TestRoutes.java | 30 ++++++++++++++++- 5 files changed, 66 insertions(+), 26 deletions(-) delete mode 100644 src/test/java/com/puppet/sample/AppTest.java diff --git a/pom.xml b/pom.xml index 21f78e5..21a788f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,8 +4,8 @@ com.puppet.sample java-webapp jar - 1.1 java-webapp + 1.2 http://maven.apache.org @@ -46,6 +46,11 @@ spark-template-thymeleaf 2.3 + + com.puppet.sample.langs + polyglot + 1.0-SNAPSHOT + diff --git a/src/main/java/com/puppet/sample/App.java b/src/main/java/com/puppet/sample/App.java index 5f1c775..02da59e 100644 --- a/src/main/java/com/puppet/sample/App.java +++ b/src/main/java/com/puppet/sample/App.java @@ -1,4 +1,5 @@ package com.puppet.sample; +import com.puppet.sample.langs.Polyglot; import spark.ModelAndView; import spark.Request; @@ -15,11 +16,6 @@ public class App { - public String enMsg() - { - return "Hello World!"; - } - private static String requestInfoToString(Request request) { StringBuilder sb = new StringBuilder(); sb.append(request.requestMethod()); @@ -42,7 +38,12 @@ public static void main(String[] args) { System.out.println(requestInfoToString(request)); }); - get("/", App::helloWorld, new ThymeleafTemplateEngine()); + get("/", (request, response) -> { + response.redirect("/en"); + return null; + }); + + get("/:lang", App::helloWorld, new ThymeleafTemplateEngine()); } @@ -52,8 +53,23 @@ public static ModelAndView helloWorld(Request req, Response res) { App t = new App(); params.put("version", t.getClass().getPackage().getImplementationVersion() ); - App test = new App(); - params.put("lang", test.enMsg()); + Polyglot p = new Polyglot(); + + switch(req.params(":lang")) { + case "en": params.put("lang", p.enMsg()); + break; + case "sp": params.put("lang", p.spMsg()); + break; + case "zh": params.put("lang", p.zhMsg()); + break; + case "ar": params.put("lang", p.arMsg()); + break; + case "hi": params.put("lang", p.hiMsg()); + break; + default: String msg = "I don't know that language ~> "; + msg += req.params(":lang"); + params.put("lang", msg); + } return new ModelAndView(params, "index"); } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 9ef0ad5..4d41692 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -8,6 +8,13 @@

[[${lang}]]

+

Version: [[${version}]]

diff --git a/src/test/java/com/puppet/sample/AppTest.java b/src/test/java/com/puppet/sample/AppTest.java deleted file mode 100644 index faeb822..0000000 --- a/src/test/java/com/puppet/sample/AppTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.puppet.sample; - -import org.junit.Test; -import org.junit.Rule; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import spark.servlet.SparkApplication; - -public class AppTest -{ - @Test - public void testMsg() { - assertEquals("Hello World!", new App().enMsg()); - } -} diff --git a/src/test/java/com/puppet/sample/TestRoutes.java b/src/test/java/com/puppet/sample/TestRoutes.java index b8eee6c..ef84065 100644 --- a/src/test/java/com/puppet/sample/TestRoutes.java +++ b/src/test/java/com/puppet/sample/TestRoutes.java @@ -35,11 +35,39 @@ public static void afterClass() throws Exception { @Test public void testEnMsg() throws IOException { - TestResponse res = request("GET", "/"); + TestResponse res = request("GET", "/en"); assertEquals(200, res.status); assertTrue(res.body.contains("Hello World!")); } + @Test + public void testSpMsg() throws IOException { + TestResponse res = request("GET", "/sp"); + assertEquals(200, res.status); + assertTrue(res.body.contains("¡Hola Mundo!")); + } + + @Test + public void testZhMsg() throws IOException { + TestResponse res = request("GET", "/zh"); + assertEquals(200, res.status); + assertTrue(res.body.contains("你好,世界!")); + } + + @Test + public void testHiMsg() throws IOException { + TestResponse res = request("GET", "/hi"); + assertEquals(200, res.status); + assertTrue(res.body.contains("नमस्ते दुनिया")); + } + + @Test + public void testArMsg() throws IOException { + TestResponse res = request("GET", "/ar"); + assertEquals(200, res.status); + assertTrue(res.body.contains("مرحبا بالعالم!")); + } + private TestResponse request(String method, String path) throws java.io.IOException { try { URL url = new URL("http://localhost:9999" + path); From eae8c6e200ca8c6d18dc05ecb9657bdbe913a535 Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Mon, 12 Feb 2018 16:22:00 -0800 Subject: [PATCH 3/3] add settings file --- settings.xml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 settings.xml diff --git a/settings.xml b/settings.xml new file mode 100644 index 0000000..118db07 --- /dev/null +++ b/settings.xml @@ -0,0 +1,56 @@ + + + + + admin + AP35rKDVCxZ1hiyvw14NLDLwBcX + central + + + admin + AP35rKDVCxZ1hiyvw14NLDLwBcX + snapshots + + + + + + + + false + + central + libs-release + http://localhost:8081/artifactory/libs-release + + + + snapshots + libs-snapshot + http://localhost:8081/artifactory/libs-snapshot + + + + + + false + + central + libs-release + http://localhost:8081/artifactory/libs-release + + + + snapshots + libs-snapshot + http://localhost:8081/artifactory/libs-snapshot + + + artifactory + + + + artifactory + +