Marcus Cvjeticanin
03/28/2023, 5:41 PMOsman Saral
03/29/2023, 8:05 AMAssertionFailedError
?
@Test
fun test() = testApplication {
install(io.ktor.server.websocket.WebSockets) {
contentConverter = KotlinxWebsocketSerializationConverter(
Json {
ignoreUnknownKeys = true
}
)
}
routing {
webSocket("/") {
sendSerialized(Incoming.Ping("123"))
val outgoing = receiveDeserialized<Outgoing.Pong>()
val a = "3"
assertEquals("2", a) //this throws AssertionFailedError but test passes
}
}
val client = createClient {
install(WebSockets) {
contentConverter = KotlinxWebsocketSerializationConverter(
Json {
ignoreUnknownKeys = true
}
)
}
}
client
.wss("/") {
val received = receiveDeserialized<Incoming.Ping>()
assertIs<Incoming.Ping>(received)
sendSerialized(Outgoing.Pong(received.id))
val a = "3"
assertEquals("3", a) //if this fails, test doesn't pass as expected.
}
}
Elena van Engelen
03/29/2023, 9:53 AMval response = <http://httpClient.post|httpClient.post><MyClass1> {
url("$myUrl")
contentType(ContentType.Application.Json)
body = MyClass2(MyClass3(param1, param2))
}
Michael
03/29/2023, 11:40 AM@OptIn(ExperimentalCoroutinesApi::class)
private fun asFlow(session: DefaultClientWebSocketSession) = flow<Event> {
try {
session.incoming.consume {
while (!isClosedForReceive) {
val value = session.receiveDeserialized<Event>()
println("Emitting event: $value")
emit(value)
}
}
} catch (ignore: CancellationException) {
//reading was stopped from somewhere else, ignore
}
}
Martin Harvan
03/29/2023, 12:49 PMMahesh Bhatt
03/29/2023, 8:20 PMval meterId = varchar("meter_id")
Sergio Sanchez
03/29/2023, 8:38 PMQuap
03/30/2023, 12:21 AMdave08
03/30/2023, 9:35 AMCan not resolve request to <http://localhost:8080>. Main app runs at 0.0.0.0:8080, 127.0.0.1:8090 and external services are
io.ktor.server.testing.client.InvalidTestRequestException: Can not resolve request to <http://localhost:8080>. Main app runs at 0.0.0.0:8080, 127.0.0.1:8090 and external services are
at app//io.ktor.server.testing.client.DelegatingTestClientEngine.execute(DelegatingTestClientEngine.kt:59)
at app//io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:99)
Sergio Sanchez
03/30/2023, 4:53 PMSam
03/31/2023, 1:37 AMsendWithoutRequest
block, it looks for a 401 response with a WWW-Authenticate
header with a matching realm
and then sends that token? Is there any way to short-circuit or restrict that?Quap
03/31/2023, 10:13 AMegor
03/31/2023, 12:09 PMDaniel
03/31/2023, 12:54 PMBendik Standal
03/31/2023, 1:18 PMtestApplication
hosting a jwks.json file with something like this:
@Test
fun `test that cases are correctly added to database`() = testApplication {
routing {
static(".well-known") {
staticRootFolder = File("certs")
file("jwks.json")
}
}
<...>
}
However, that does not seem to work, and my theory is that the application sets up the routing defined here after the authentication is installed and configured(?). So my question is, does someone know a way of setting up this route before the authentication in the application is configured? Or alternatively, if someone has experience in writing integration tests for apis that are secured with (RSA signed) JSON web tokens, perhaps you can point me to a better solution for solving this. Hopefully that made sense to someone :-)bodo
04/01/2023, 2:57 PM@Serializable
@SerialName("modules")
data class Modules(
val resId: String?,
val contentUrl: String?,
)
val httpClient = HttpClient(Android) {
install(ContentNegotiation) {
xml()
}
}
lifecycleScope.launch {
val modules = httpClient.get("...").body<Modules>()
Log.d("MODULES", modules.toString())
}
But when i do the httpClient.get(url).body<Modules>()
i get the following error. can you please tell me what i am doing wrong.
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class com.example.ktor.Modules
Quap
04/01/2023, 9:44 PMclose(CloseReason)
method, the connection is closed fine, but I never receive the text of the CloseReason in any browser. How can I make this work?Axel
04/03/2023, 8:07 AMleandro
04/03/2023, 12:56 PMJson
through an instance of HttpClient
if I can guarantee that there is a ContentNegotiation
plugin installed with json
configuration?Randy Tang
04/03/2023, 8:07 PMIgor Milakovic
04/03/2023, 9:56 PMapplication/json
?
install(ContentNegotiation) {
json()
}
The API I'm working with wants to deal with application/vnd.api+json
only, and however I try to manipulate the headers, my requests are always sent with both (Accept: application/vnd.api+json; application/json
)
Thanks!Axel
04/04/2023, 8:47 AMHttpClient.prepareGet()
?Dmitry Skorbovenko
04/04/2023, 9:31 AMspierce7
04/04/2023, 2:16 PMrocketraman
04/04/2023, 9:45 PMKalpesh Chandora
04/05/2023, 5:30 AMMichael
04/05/2023, 11:51 AMpublic fun main(): Unit = runBlocking {
val client = HttpClient(WinHttp) {
install(WebSockets)
}
println("Connecting now")
val session = client.webSocketSession("<wss://ws.postman-echo.com/raw>")
println("sending")
session.outgoing.send(Frame.Text("test"))
println("Receiving")
println(session.incoming.receive().data.decodeToString())
}
Nazar Pohonchuk
04/05/2023, 3:21 PMrocketraman
04/05/2023, 3:28 PMrocketraman
04/05/2023, 5:07 PMAuthenticationContext.principal
is now deprecated. What if I don't know the provider of my principals and I just want to get a list of them? That doesn't seem possible anymore?