Kotlin binding for xml-rpc
implementation("org.ascheja.xmlrpc:ktor-client-xmlrpc:VERSION")
implementation("org.ascheja.xmlrpc:ktor-server-xmlrpc:VERSION")
implementation("org.ascheja.xmlrpc:protocol:VERSION")
val client: HttpClient = createHttpClient()
val call = MethodCall("some-method", IntegerValue(42), StringValue("some-string"))
val response = client.xmlRpc("https://some-server/rpc", call) as MethodResponseSuccess // or check for MethodResponseFault if you set the parameter `throwOnFault = false`
val firstParam = response.params.firstOrNull() as? StringValue ?: error("expected first parameter of response to be a StringValue")
embeddedServer(Netty) {
routing {
xmlRpc("/rpc") { request ->
when (request.methodName) {
"ping" -> MethodResponseSuccess(StringValue("pong"))
else -> MethodResponseFault(42, "unknown method ${request.methodName}")
}
}
}
}.start(wait = true)