output-service-rdb/src/Application.kt

65 lines
1.5 KiB
Kotlin
Raw Normal View History

2020-04-04 18:47:24 +02:00
package com.kmalbz
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.gson.*
import io.ktor.features.*
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.auth.*
import kotlin.reflect.*
import java.util.*
2020-04-04 23:21:17 +02:00
import org.apache.http.HttpException
2020-04-04 18:47:24 +02:00
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
install(ContentNegotiation) {
gson {
}
}
val client = HttpClient(Apache) {
}
install(Authentication) {
}
routing {
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
}
get("/json/gson") {
call.respond(mapOf("hello" to "world"))
}
install(StatusPages) {
exception<AuthenticationException> { cause ->
call.respond(HttpStatusCode.Unauthorized)
}
2020-04-04 23:21:17 +02:00
2020-04-04 18:47:24 +02:00
exception<AuthorizationException> { cause ->
call.respond(HttpStatusCode.Forbidden)
}
2020-04-04 23:21:17 +02:00
exception<HttpException> { cause ->
call.respond(HttpStatusCode.BadRequest)
2020-04-04 18:47:24 +02:00
}
}
OutputServiceRDBServer().apply {
registerOutput()
}
}
}
class AuthenticationException : RuntimeException()
class AuthorizationException : RuntimeException()