aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-server-spring-boot/src/main
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-12-20 10:19:55 +0100
committerRobert Jaros <rjaros@finn.pl>2018-12-20 10:19:55 +0100
commitb995f4b927c230e0ae15d51920390dc6afff6caa (patch)
tree9ad79bf5ecdbb85cac89b20afb85e3e318a80136 /kvision-modules/kvision-server-spring-boot/src/main
parent474195d3aa862686712cfe6c800dc43f8fee8ec5 (diff)
downloadkvision-b995f4b927c230e0ae15d51920390dc6afff6caa.tar.gz
kvision-b995f4b927c230e0ae15d51920390dc6afff6caa.tar.bz2
kvision-b995f4b927c230e0ae15d51920390dc6afff6caa.zip
Refactor server side modules.
Diffstat (limited to 'kvision-modules/kvision-server-spring-boot/src/main')
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt121
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt2
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt (renamed from kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt)19
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt2
4 files changed, 14 insertions, 130 deletions
diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt
deleted file mode 100644
index 422c97ba..00000000
--- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2017-present Robert Jaros
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package pl.treksoft.kvision.remote
-
-/**
- * Multiplatform service manager for Jooby.
- * Not to be used in this module.
- */
-actual open class JoobyServiceManager<T : Any> actual constructor(val service: T) : ServiceManager {
- /**
- * Binds a given route with a function of the receiver.
- * @param function a function of the receiver
- * @param route a route
- * @param method a HTTP method
- */
- protected actual inline fun <reified RET> bind(
- noinline function: suspend T.(Request?) -> RET,
- route: String?,
- method: RpcHttpMethod
- ) {
- throw IllegalStateException("This class is for Jooby integration.")
- }
-
- /**
- * Binds a given route with a function of the receiver.
- * @param function a function of the receiver
- * @param route a route
- * @param method a HTTP method
- */
- protected actual inline fun <reified PAR, reified RET> bind(
- noinline function: suspend T.(PAR, Request?) -> RET,
- route: String?,
- method: RpcHttpMethod
- ) {
- throw IllegalStateException("This class is for Jooby integration.")
- }
-
- /**
- * Binds a given route with a function of the receiver.
- * @param function a function of the receiver
- * @param route a route
- * @param method a HTTP method
- */
- protected actual inline fun <reified PAR1, reified PAR2, reified RET> bind(
- noinline function: suspend T.(PAR1, PAR2, Request?) -> RET,
- route: String?,
- method: RpcHttpMethod
- ) {
- throw IllegalStateException("This class is for Jooby integration.")
- }
-
- /**
- * Binds a given route with a function of the receiver.
- * @param function a function of the receiver
- * @param route a route
- * @param method a HTTP method
- */
- protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET> bind(
- noinline function: suspend T.(PAR1, PAR2, PAR3, Request?) -> RET,
- route: String?,
- method: RpcHttpMethod
- ) {
- throw IllegalStateException("This class is for Jooby integration.")
- }
-
- /**
- * Binds a given route with a function of the receiver.
- * @param function a function of the receiver
- * @param route a route
- * @param method a HTTP method
- */
- protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind(
- noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, Request?) -> RET,
- route: String?,
- method: RpcHttpMethod
- ) {
- throw IllegalStateException("This class is for Jooby integration.")
- }
-
- /**
- * Binds a given route with a function of the receiver.
- * @param function a function of the receiver
- * @param route a route
- * @param method a HTTP method
- */
- protected actual inline fun <reified PAR1, reified PAR2, reified PAR3,
- reified PAR4, reified PAR5, reified RET> bind(
- noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> RET,
- route: String?,
- method: RpcHttpMethod
- ) {
- throw IllegalStateException("This class is for Jooby integration.")
- }
-
- /**
- * Applies all defined routes to the given server.
- * @param k a server
- */
- actual fun applyRoutes(k: KVServer) {
- throw IllegalStateException("This class is for Jooby integration.")
- }
-}
diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
index f2e3e951..ba7264e8 100644
--- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
+++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
@@ -33,7 +33,7 @@ import kotlinx.coroutines.async as coroutinesAsync
/**
* A Spring boot based server.
*/
-actual open class KVServer(val services: List<SpringServiceManager<*>>)
+actual open class KVServer(val services: List<KVServiceManager<*>>)
/**
* A server request.
diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 162b92dd..45c5c565 100644
--- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt
+++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -36,10 +36,10 @@ import kotlin.reflect.KClass
* Multiplatform service manager for Spring Boot.
*/
@UseExperimental(ExperimentalCoroutinesApi::class)
-actual open class SpringServiceManager<T : Any> actual constructor(val serviceClass: KClass<T>) : ServiceManager {
+actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: KClass<T>) : ServiceManager {
companion object {
- val LOG: Logger = LoggerFactory.getLogger(JoobyServiceManager::class.java.name)
+ val LOG: Logger = LoggerFactory.getLogger(KVServiceManager::class.java.name)
}
val postRequests: MutableMap<String, (Request, HttpServletResponse) -> Unit> = mutableMapOf()
@@ -379,16 +379,17 @@ actual open class SpringServiceManager<T : Any> actual constructor(val serviceCl
*/
@Suppress("TooGenericExceptionCaught")
protected actual fun bind(
- function: T.(String) -> List<RemoteSelectOption>
+ function: T.(String?, String?) -> List<RemoteSelectOption>
) {
val routeDef = "route${this::class.simpleName}${counter++}"
addRoute(RpcHttpMethod.POST, "/kv/$routeDef") { req, res ->
val service = SpringContext.getBean(serviceClass.java)
val jsonRpcRequest = mapper.readValue(req.inputStream, JsonRpcRequest::class.java)
- if (jsonRpcRequest.params.size == 1) {
- val param = getParameter<String>(jsonRpcRequest.params[0])
+ if (jsonRpcRequest.params.size == 2) {
+ val param1 = getParameter<String?>(jsonRpcRequest.params[0])
+ val param2 = getParameter<String?>(jsonRpcRequest.params[1])
try {
- val result = function.invoke(service, param)
+ val result = function.invoke(service, param1, param2)
res.writeJSON(
mapper.writeValueAsString(
JsonRpcResponse(
@@ -434,7 +435,6 @@ actual open class SpringServiceManager<T : Any> actual constructor(val serviceCl
}
}
- @Suppress("TooGenericExceptionCaught")
protected inline fun <reified T> getParameter(str: String?): T {
return str?.let {
if (T::class == String::class) {
@@ -444,6 +444,11 @@ actual open class SpringServiceManager<T : Any> actual constructor(val serviceCl
}
} ?: null as T
}
+
+ /**
+ * Applies all defined routes to the given server.
+ */
+ actual fun applyRoutes(k: KVServer) {}
}
fun HttpServletResponse.writeJSON(json: String) {
diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt
index 9d80beb0..abfef934 100644
--- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt
+++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt
@@ -23,7 +23,7 @@ package pl.treksoft.kvision.remote
import org.springframework.web.servlet.config.annotation.InterceptorRegistration
-fun InterceptorRegistration.addPathPatternsFromServices(services: List<SpringServiceManager<*>>) {
+fun InterceptorRegistration.addPathPatternsFromServices(services: List<KVServiceManager<*>>) {
val paths = services.flatMap {
it.postRequests.keys + it.putRequests.keys + it.optionsRequests.keys + it.optionsRequests.keys
}