diff --git a/pom.xml b/pom.xml
index 5b5aa8e..21a788f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,8 +4,8 @@
com.puppet.sample
java-webapp
jar
- 1.0
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/settings.xml b/settings.xml
new file mode 100644
index 0000000..0304c55
--- /dev/null
+++ b/settings.xml
@@ -0,0 +1,56 @@
+
+
+
+
+ admin
+ AP6Z7n7G62j4vbGmmw69sHW9nck
+ central
+
+
+ admin
+ AP6Z7n7G62j4vbGmmw69sHW9nck
+ 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
+
+
diff --git a/src/main/java/com/puppet/sample/App.java b/src/main/java/com/puppet/sample/App.java
index 673c845..02da59e 100644
--- a/src/main/java/com/puppet/sample/App.java
+++ b/src/main/java/com/puppet/sample/App.java
@@ -1,9 +1,11 @@
package com.puppet.sample;
+import com.puppet.sample.langs.Polyglot;
import spark.ModelAndView;
import spark.Request;
import spark.Response;
import spark.Spark;
+import spark.template.thymeleaf.ThymeleafTemplateEngine;
import java.util.HashMap;
import java.util.Map;
@@ -14,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());
@@ -41,8 +38,40 @@ public static void main(String[] args) {
System.out.println(requestInfoToString(request));
});
- get("/", (request,response) -> "Hello World!");
+ get("/", (request, response) -> {
+ response.redirect("/en");
+ return null;
+ });
+
+ get("/:lang", 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() );
+
+ 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
new file mode 100644
index 0000000..4d41692
--- /dev/null
+++ b/src/main/resources/templates/index.html
@@ -0,0 +1,22 @@
+
+
+
+ Hello world
+
+
+
+
+
+
Version: [[${version}]]
+
+
+
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);