Sergey
08/07/2023, 10:11 AMfun syncSubscribe() = runBlocking {
subscribe()
}
suspend fun subscribe() {
<http://logger.info|logger.info> { "Vault ws subscribed" }
val eventType = EventType.write
httpClient.wss(
method = HttpMethod.Get,
host = vaultHost,
path = "/v1/sys/events/subscribe/kv-v1/$eventType?json=true",
request = {
header("X-Vault-Token", vaultToken)
}
) {
while(true) {
val myDTO = receiveDeserialized<MyDTO>()
<http://logger.info|logger.info> { "Received: $myDTO" }
}
}
}
But I'm getting this error that I don't know how to resolve.
Caused by: kotlinx.serialization.SerializationException: Serializer for class 'DefaultClientWebSocketSession' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
p.s. ktor_version = 2.3.3Aleksei Tirman [JB]
08/07/2023, 10:18 AM/v1/sys/events/subscribe/kv-v1/$eventType?json=true
?Aleksei Tirman [JB]
08/07/2023, 10:21 AM/v1/sys/events/subscribe/kv-v1/$eventType?json=true
request returns a JSON response and the ContentNegotiation
plugin tries to deserialize itSergey
08/07/2023, 10:22 AMSergey
08/07/2023, 10:25 AM{
"id": "22f8c382-e893-d676-7249-949ee8b81107",
"source": "<https://vaultproject.io/>",
"specversion": "1.0",
"type": "*",
"data": {
"event": {
"id": "22f8c382-e893-d676-7249-949ee8b81107",
"metadata": {
"path": "test"
}
},
"event_type": "kv-v1/write",
"plugin_info": {
"mount_class": "secret",
"mount_accessor": "kv_52920ec2",
"mount_path": "kv/",
"plugin": "kv"
}
},
"datacontentype": "application/cloudevents",
"time": "2023-08-07T10:24:55.6183514Z"
}
Aleksei Tirman [JB]
08/07/2023, 10:25 AMSergey
08/07/2023, 10:26 AMAleksei Tirman [JB]
08/07/2023, 10:27 AMSergey
08/07/2023, 10:27 AMResponse Headers:
Cache-Control: no-store
Connection: Upgrade
Sec-Websocket-Accept: PphdjXw2+sPxNVBO7rsQYyO04SU=
Sec-Websocket-Extensions: permessage-deflate; client_no_context_takeover; server_no_context_takeover
Strict-Transport-Security: max-age=31536000; includeSubDomains
Upgrade: websocket
Aleksei Tirman [JB]
08/07/2023, 10:33 AMAleksei Tirman [JB]
08/07/2023, 10:33 AMSergey
08/07/2023, 10:34 AMval httpClient = HttpClient(CIO) {
install(WebSockets) {
contentConverter = KotlinxWebsocketSerializationConverter(Json)
}
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
defaultRequest {
url {
//protocol = URLProtocol.HTTPS
host = vaultHost
}
header("X-Vault-Token", vaultToken)
}
}
Full logAleksei Tirman [JB]
08/07/2023, 10:43 AMDefaultClientWebSocketSession
class to the list of ignored types:
install(ContentNegotiation) {
ignoreType<DefaultClientWebSocketSession>()
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
Sergey
08/07/2023, 11:02 AM