Browse Source

Update to Hexagon 1.4.0 (#6760)

* Fix error with URLs in JEE servers

* Clean up

* Avoid classpath URLs

* Fix template loading error

* Fix template loading error

* Chores

* Fix template loading error
Juanjo Aguililla 4 years ago
parent
commit
0ff3ff999a

+ 4 - 4
frameworks/Kotlin/hexagon/build.gradle

@@ -4,13 +4,13 @@ plugins {
 }
 
 ext {
-    gradleScripts = "https://raw.githubusercontent.com/hexagonkt/hexagon/1.3.20/gradle"
+    gradleScripts = "https://raw.githubusercontent.com/hexagonkt/hexagon/1.4.0/gradle"
 
-    hexagonVersion = "1.3.20"
-    hikariVersion = "4.0.3" // TODO Check with 3.4.5, 4.0.3 or 5.0.0
+    hexagonVersion = "1.4.0"
+    hikariVersion = "5.0.0"
     jettyVersion = "10.0.6"
     postgresqlVersion = "42.2.23"
-    cache2kVersion = "2.0.0.Final"
+    cache2kVersion = "2.2.1.Final"
     jacksonBlackbirdVersion = "2.12.4"
 }
 

+ 1 - 0
frameworks/Kotlin/hexagon/hexagon-resin-mongodb.dockerfile

@@ -21,5 +21,6 @@ WORKDIR /resin
 RUN curl -sL $RESIN | tar xz --strip-components=1
 RUN rm -rf webapps/*
 COPY --from=gradle_build /hexagon/build/libs/ROOT.war webapps/ROOT.war
+COPY src/main/resources/fortunes.pebble.html fortunes.pebble.html
 EXPOSE 9090
 CMD ["java", "-jar", "lib/resin.jar", "console"]

+ 1 - 0
frameworks/Kotlin/hexagon/hexagon-resin-postgresql.dockerfile

@@ -21,5 +21,6 @@ WORKDIR /resin
 RUN curl -sL $RESIN | tar xz --strip-components=1
 RUN rm -rf webapps/*
 COPY --from=gradle_build /hexagon/build/libs/ROOT.war webapps/ROOT.war
+COPY src/main/resources/fortunes.pebble.html fortunes.pebble.html
 EXPOSE 8080
 CMD ["java", "-jar", "lib/resin.jar", "console"]

+ 15 - 1
frameworks/Kotlin/hexagon/src/main/kotlin/Controller.kt

@@ -1,15 +1,21 @@
 package com.hexagonkt
 
+import com.hexagonkt.helpers.require
 import com.hexagonkt.http.server.Call
 import com.hexagonkt.http.server.Router
 import com.hexagonkt.serialization.Json
 import com.hexagonkt.serialization.toFieldsMap
 import com.hexagonkt.store.BenchmarkStore
 import com.hexagonkt.templates.TemplatePort
+import java.net.URL
 import java.util.concurrent.ThreadLocalRandom
 
 class Controller(private val settings: Settings) {
 
+    private val templates: Map<String, URL> = mapOf(
+        "pebble" to (urlOrNull("classpath:fortunes.pebble.html") ?: URL("file:/resin/fortunes.pebble.html"))
+    )
+
     internal val router: Router by lazy {
         Router {
             before {
@@ -42,7 +48,7 @@ class Controller(private val settings: Settings) {
         val context = mapOf("fortunes" to sortedFortunes)
 
         response.contentType = "text/html;charset=utf-8"
-        ok(templateAdapter.render("fortunes.$templateKind.html", context))
+        ok(templateAdapter.render(templates.require(templateKind), context))
     }
 
     private fun Call.dbQuery(store: BenchmarkStore) {
@@ -77,4 +83,12 @@ class Controller(private val settings: Settings) {
 
     private fun randomWorld(): Int =
         ThreadLocalRandom.current().nextInt(settings.worldRows) + 1
+
+    private fun urlOrNull(path: String): URL? =
+        try {
+            URL(path)
+        }
+        catch (e: Exception) {
+            null
+        }
 }

+ 0 - 2
frameworks/Kotlin/hexagon/src/main/kotlin/WebListenerServer.kt

@@ -14,6 +14,4 @@ import javax.servlet.annotation.WebListener
         SerializationManager.mapper = JacksonMapper
         SerializationManager.formats = linkedSetOf(Json)
     }
-
-    val webRouter = super.router
 }