Loading src/dlt/src/main/kotlin/Main.kt +16 −5 Original line number Diff line number Diff line import io.ktor.client.* import io.ktor.client.engine.cio.* import io.ktor.client.features.* import io.ktor.client.request.* import io.ktor.http.* import kotlinx.serialization.ExperimentalSerializationApi Loading Loading @@ -43,10 +44,20 @@ suspend fun main(args: Array<String>) { .build() val cfgBytes = cfg.toByteArray() val client = HttpClient(CIO) val config = client.post<ByteArray>("http://localhost:8080/dlt/configure") { val client = HttpClient(CIO) { HttpResponseValidator { validateResponse { response -> println(response.status) } } } try { client.post<ByteArray>("http://localhost:8080/dlt/configure") { contentType(ContentType.Any) body = cfgBytes } println(DltConfig.parseFrom(config)) } catch (e: ClientRequestException) { println(e.response.status) } } No newline at end of file src/dlt/src/main/kotlin/http/Server.kt +14 −8 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ package http import fabric.FabricConnector import io.ktor.application.* import io.ktor.features.* import io.ktor.http.* import io.ktor.request.* import io.ktor.response.* import io.ktor.routing.* import io.ktor.server.engine.* import io.ktor.server.netty.* Loading @@ -18,13 +18,19 @@ fun main() { routing { post("/dlt/configure") { withContext(Dispatchers.IO) { try { val data = call.receiveStream() val config = parseFrom(data) println(config) val connector = FabricConnector(config) connector.connect() val encodedBack = config.toByteArray() call.respond(encodedBack) call.response.status(HttpStatusCode.Created) } // TODO: catch exceptions one by one catch (e: Exception) { call.response.status(HttpStatusCode.BadRequest) e.printStackTrace() } } } } Loading Loading
src/dlt/src/main/kotlin/Main.kt +16 −5 Original line number Diff line number Diff line import io.ktor.client.* import io.ktor.client.engine.cio.* import io.ktor.client.features.* import io.ktor.client.request.* import io.ktor.http.* import kotlinx.serialization.ExperimentalSerializationApi Loading Loading @@ -43,10 +44,20 @@ suspend fun main(args: Array<String>) { .build() val cfgBytes = cfg.toByteArray() val client = HttpClient(CIO) val config = client.post<ByteArray>("http://localhost:8080/dlt/configure") { val client = HttpClient(CIO) { HttpResponseValidator { validateResponse { response -> println(response.status) } } } try { client.post<ByteArray>("http://localhost:8080/dlt/configure") { contentType(ContentType.Any) body = cfgBytes } println(DltConfig.parseFrom(config)) } catch (e: ClientRequestException) { println(e.response.status) } } No newline at end of file
src/dlt/src/main/kotlin/http/Server.kt +14 −8 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ package http import fabric.FabricConnector import io.ktor.application.* import io.ktor.features.* import io.ktor.http.* import io.ktor.request.* import io.ktor.response.* import io.ktor.routing.* import io.ktor.server.engine.* import io.ktor.server.netty.* Loading @@ -18,13 +18,19 @@ fun main() { routing { post("/dlt/configure") { withContext(Dispatchers.IO) { try { val data = call.receiveStream() val config = parseFrom(data) println(config) val connector = FabricConnector(config) connector.connect() val encodedBack = config.toByteArray() call.respond(encodedBack) call.response.status(HttpStatusCode.Created) } // TODO: catch exceptions one by one catch (e: Exception) { call.response.status(HttpStatusCode.BadRequest) e.printStackTrace() } } } } Loading