in dsl/kotless/cloud/kotless-lang-aws/src/main/kotlin/io/kotless/dsl/HandlerAWS.kt [34:65]
override fun handleRequest(input: InputStream, output: OutputStream, @Suppress("UNUSED_PARAMETER") any: Context?) {
val response = try {
val jsonRequest = input.bufferedReader().use { it.readText() }
logger.debug("Started handling request")
logger.trace("Request is {}", jsonRequest)
Application.init()
if (jsonRequest.contains("Scheduled Event")) {
val event = JSON.parse(CloudWatch.serializer(), jsonRequest)
if (event.`detail-type` == "Scheduled Event" && event.source == "aws.events") {
logger.debug("Request is Scheduled Event")
EventsDispatcher.process(event)
return
}
}
logger.debug("Request is HTTP Event")
val request = JSON.parse(AwsHttpRequest.serializer(), jsonRequest)
val resourceKey = RouteKey(request.method, request.path)
RoutesDispatcher.dispatch(request.toRequest(), resourceKey)
} catch (e: Throwable) {
logger.error("Error occurred during handle of request and was not caught", e)
serverError("Internal error occurred")
}
output.write(JSON.bytes(HttpResponse.serializer(), response))
logger.debug("Ended handling request")
}