aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-10-13 03:37:40 +0200
committerRobert Jaros <rjaros@finn.pl>2018-10-13 03:37:40 +0200
commitebce2c4b839c0b2f8be78bc31c1ce12c45a0164c (patch)
tree7cac3c5449eb8aa398b279d62d9a67ed34fa4115 /kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote
parent470953c78c2509224bb452c16f8bbea54e53b3d7 (diff)
downloadkvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.gz
kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.bz2
kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.zip
Major refactoring of the multi-platform components.
Dependencies upgrade. A lot of code style fixes.
Diffstat (limited to 'kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote')
-rw-r--r--kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt7
-rw-r--r--kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt40
2 files changed, 30 insertions, 17 deletions
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
index 76f1ee30..38edc1b8 100644
--- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
+++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
@@ -19,8 +19,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-@file:Suppress("EXPERIMENTAL_FEATURE_WARNING")
-
package pl.treksoft.kvision.remote
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
@@ -31,6 +29,7 @@ import org.jooby.Kooby
import org.jooby.Session
import org.jooby.json.Jackson
import org.pac4j.core.profile.CommonProfile
+import java.text.SimpleDateFormat
import kotlinx.coroutines.async as coroutinesAsync
/**
@@ -42,7 +41,9 @@ actual open class KVServer(init: KVServer.() -> Unit) : Kooby() {
assets("/", "index.html")
@Suppress("LeakingThis")
assets("/**").onMissing(0)
- val mapper = jacksonObjectMapper()
+ val mapper = jacksonObjectMapper().apply {
+ dateFormat = SimpleDateFormat("YYYY-MM-DD HH:mm:ss")
+ }
@Suppress("LeakingThis")
use(Jackson(mapper))
@Suppress("LeakingThis")
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
index b37d7319..3091ce26 100644
--- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
+++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
@@ -28,11 +28,11 @@ import org.jooby.Response
import org.jooby.Status
import org.slf4j.Logger
import org.slf4j.LoggerFactory
+import java.text.SimpleDateFormat
/**
* Multiplatform service manager.
*/
-@Suppress("EXPERIMENTAL_FEATURE_WARNING")
actual open class ServiceManager<out T> actual constructor(val service: T) {
companion object {
@@ -40,7 +40,9 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
}
protected val routes: MutableList<KVServer.() -> Unit> = mutableListOf()
- val mapper = jacksonObjectMapper()
+ val mapper = jacksonObjectMapper().apply {
+ dateFormat = SimpleDateFormat("YYYY-MM-DD HH:mm:ss")
+ }
var counter: Int = 0
/**
@@ -50,12 +52,13 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified RET> bind(
noinline function: T.(Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
@@ -75,7 +78,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -85,12 +88,13 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR, reified RET> bind(
noinline function: T.(PAR, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
@@ -115,7 +119,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -125,12 +129,13 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified RET> bind(
noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
@@ -156,7 +161,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -166,15 +171,17 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET> bind(
noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
+ @Suppress("MagicNumber")
if (jsonRpcRequest.params.size == 3) {
val param1 = getParameter<PAR1>(jsonRpcRequest.params[0])
val param2 = getParameter<PAR2>(jsonRpcRequest.params[1])
@@ -198,7 +205,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -208,15 +215,17 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind(
noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
+ @Suppress("MagicNumber")
if (jsonRpcRequest.params.size == 4) {
val param1 = getParameter<PAR1>(jsonRpcRequest.params[0])
val param2 = getParameter<PAR2>(jsonRpcRequest.params[1])
@@ -242,7 +251,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -252,6 +261,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified PAR3,
reified PAR4, reified PAR5, reified RET> bind(
noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<RET>,
@@ -260,10 +270,11 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
+ @Suppress("MagicNumber")
if (jsonRpcRequest.params.size == 5) {
val param1 = getParameter<PAR1>(jsonRpcRequest.params[0])
val param2 = getParameter<PAR2>(jsonRpcRequest.params[1])
@@ -292,7 +303,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
fun call(
@@ -310,6 +321,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
}
}
+ @Suppress("TooGenericExceptionCaught")
protected inline fun <reified T> getParameter(str: String?): T {
return str?.let {
if (T::class == String::class) {