aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-02-01 11:54:25 +0100
committerRobert Jaros <rjaros@finn.pl>2019-02-01 11:54:25 +0100
commit110ba60c6557bf16a3bfc5f7ff5af46a98164c75 (patch)
treeea8a59ae9d7c2de94f36a4d75d00695bb75552e8 /kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision
parentcf0a609fc42b2356f50f32e03f02e2ace0d46e35 (diff)
downloadkvision-110ba60c6557bf16a3bfc5f7ff5af46a98164c75.tar.gz
kvision-110ba60c6557bf16a3bfc5f7ff5af46a98164c75.tar.bz2
kvision-110ba60c6557bf16a3bfc5f7ff5af46a98164c75.zip
Refactor server-side interfaces.
Diffstat (limited to 'kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision')
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt33
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt7
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt52
3 files changed, 54 insertions, 38 deletions
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 b0052be0..e8dee5cc 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
@@ -21,38 +21,7 @@
*/
package pl.treksoft.kvision.remote
-import org.pac4j.core.context.J2EContext
-import org.pac4j.core.context.session.J2ESessionStore
-import org.pac4j.core.profile.CommonProfile
-import org.pac4j.core.profile.ProfileManager
-import org.springframework.web.context.request.RequestContextHolder
-import org.springframework.web.context.request.ServletRequestAttributes
-import kotlinx.coroutines.async as coroutinesAsync
-
/**
* A Spring boot based server.
*/
-actual open class KVServer(val services: List<KVServiceManager<*>>)
-
-/**
- * A user profile.
- */
-actual typealias Profile = CommonProfile
-
-/**
- * A helper extension function for processing with authenticated user profile.
- */
-@Suppress("TooGenericExceptionCaught")
-fun <RESP> withProfile(block: (Profile) -> RESP): RESP {
- val profile = try {
- val requestAttributes = (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes)
- val req = requestAttributes.request
- val resp = requestAttributes.response
- ProfileManager<CommonProfile>(J2EContext(req, resp, J2ESessionStore())).get(true).get()
- } catch (e: Exception) {
- null
- }
- return profile?.let {
- block(it)
- } ?: throw IllegalStateException("Profile not set!")
-}
+open class KVServer(val services: List<KVServiceManager<*>>)
diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 6e8ee86e..4820fb2e 100644
--- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -38,7 +38,7 @@ import kotlin.reflect.KClass
* Multiplatform service manager for Spring Boot.
*/
@UseExperimental(ExperimentalCoroutinesApi::class)
-actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: KClass<T>) : ServiceManager {
+actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: KClass<T>) {
companion object {
val LOG: Logger = LoggerFactory.getLogger(KVServiceManager::class.java.name)
@@ -446,11 +446,6 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
}
} ?: 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/Profile.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt
new file mode 100644
index 00000000..02c0fe27
--- /dev/null
+++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt
@@ -0,0 +1,52 @@
+/*
+ * 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
+
+import org.pac4j.core.context.J2EContext
+import org.pac4j.core.context.session.J2ESessionStore
+import org.pac4j.core.profile.CommonProfile
+import org.pac4j.core.profile.ProfileManager
+import org.springframework.web.context.request.RequestContextHolder
+import org.springframework.web.context.request.ServletRequestAttributes
+
+/**
+ * A user profile.
+ */
+actual typealias Profile = CommonProfile
+
+/**
+ * A helper extension function for processing with authenticated user profile.
+ */
+@Suppress("TooGenericExceptionCaught")
+fun <RESP> withProfile(block: (Profile) -> RESP): RESP {
+ val profile = try {
+ val requestAttributes = (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes)
+ val req = requestAttributes.request
+ val resp = requestAttributes.response
+ ProfileManager<CommonProfile>(J2EContext(req, resp, J2ESessionStore())).get(true).get()
+ } catch (e: Exception) {
+ null
+ }
+ return profile?.let {
+ block(it)
+ } ?: throw IllegalStateException("Profile not set!")
+}