Sourabh Rawat
07/18/2021, 8:48 PMbody
, which is of type Any
?
When I do something like this, it fails..
@Serializable
class Foo(val bar: String)
@Test
fun test() {
val any: Any = Foo("asd")
Json.encodeToString(any).also { println(it) }
}
CLOVIS
07/19/2021, 8:35 AMSecure
flag on cookies. What is a working workaround?csieflyman
07/19/2021, 9:59 AMŁukasz Bednarczyk
07/19/2021, 1:08 PMnordiauwu
07/20/2021, 8:14 PMFernando Avanzo
07/21/2021, 11:22 PMRobert Jaros
07/22/2021, 6:20 AMkotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 66: Unexpected 'null' value instead of string literal
JSON input: {"id":1,"method":"/kv/routeNumberServiceManager0","params":["null","\"ENGLISH\""]}
Paul Woitaschek
07/22/2021, 10:05 AMJgafner
07/22/2021, 12:57 PMimplementation
and not testImplementation
is it a mistake or this is how things work with ktor ?
Thankschristophsturm
07/22/2021, 12:59 PMJgafner
07/22/2021, 1:02 PMCarlos Santos
07/23/2021, 8:21 AMLg
07/23/2021, 7:26 PMval client = HttpClient {
install(WebSockets)
}
client.webSocket(HttpMethod.Get, host, port, path) { … }
Bradford Canonigo
07/23/2021, 10:51 PMimplementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion"
implementation "io.ktor:ktor-client-serialization:$ktorVersion"
I believe both are serialization dependencies for kotlin, or both are kotlinx serializers.Łukasz Bednarczyk
07/24/2021, 6:50 AMsubashz
07/25/2021, 10:23 AMval createdAt = datetime("created_at").default(LocalDateTime.now())
This auto adds the createdAt to the table. But how to forwards this as unix timestamp for the client side. Also, how to configure the time zone while using defaultsubashz
07/25/2021, 10:38 AMJgafner
07/25/2021, 5:22 PMcptneko
07/25/2021, 8:31 PMsmallufo
07/27/2021, 9:56 AMjstack 45158 | grep Ktor-client-apache | wc -l
125 // there are 125 threads generated !
And the thread number starts from #19 to #144
jstack 45158 | grep Ktor-client-apache
"Ktor-client-apache" #19 daemon prio=5 os_prio=31 cpu=12.09ms elapsed=513.05s tid=0x0000000135bc4c00 nid=0x8403 runnable [0x0000000172df2000]
"Ktor-client-apache" #20 daemon prio=5 os_prio=31 cpu=11.36ms elapsed=513.05s tid=0x0000000144e30200 nid=0x7b03 runnable [0x0000000172ffe000]
...
...
"Ktor-client-apache" #143 daemon prio=5 os_prio=31 cpu=8.96ms elapsed=510.76s tid=0x0000000142a3d400 nid=0x1fe03 runnable [0x0000000292bea000]
"Ktor-client-apache" #144 daemon prio=5 os_prio=31 cpu=7.24ms elapsed=510.76s tid=0x0000000142a3ce00 nid=0x21903 runnable [0x0000000292df6000]
And I cannot figure out how it starts … :
"Ktor-client-apache" #144 daemon prio=5 os_prio=31 cpu=8.90ms elapsed=591.80s tid=0x0000000142a3ce00 nid=0x21903 runnable [0x0000000292df6000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.KQueue.poll(java.base@15.0.2/Native Method)
at sun.nio.ch.KQueueSelectorImpl.doSelect(java.base@15.0.2/KQueueSelectorImpl.java:122)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(java.base@15.0.2/SelectorImpl.java:129)
- locked <0x00000006c6b79ec0> (a sun.nio.ch.Util$2)
- locked <0x00000006c6b79e68> (a sun.nio.ch.KQueueSelectorImpl)
at sun.nio.ch.SelectorImpl.select(java.base@15.0.2/SelectorImpl.java:141)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:255)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
at java.lang.Thread.run(java.base@15.0.2/Thread.java:832)
Is it normal ?
I have many beans defining ktor like this :
@Named
class SomeBean {
private val ktorClient = HttpClient {
followRedirects = false
expectSuccess = false
}
}
It seems there is engine
block can override threadsCount
, but I never invoked it.
Environments :
<ktor.version>1.6.1</ktor.version>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-apache</artifactId>
<version>${ktor.version}</version>
</dependency>
openjdk version "15.0.2" 2021-01-19
OpenJDK Runtime Environment Zulu15.29+15-CA (build 15.0.2+7)
OpenJDK 64-Bit Server VM Zulu15.29+15-CA (build 15.0.2+7, mixed mode)
These threads are all green (RUNNING) when viewing in VisualVM , but they are not transmitting anything.Andre Servidoni
07/27/2021, 2:55 PMval bytes = this
val byteBufferSize = 1024 * 100
val byteBuffer = ByteArray(byteBufferSize)
do {
val currentRead = bytes.readAvailable(byteBuffer, 0, byteBufferSize)
if (currentRead > 0) {
println("received: $currentRead")
}
} while (currentRead > 0)
John O'Reilly
07/27/2021, 4:49 PMMockEngine
in 1.5.1.....we're updating a client here from a 1.4.x version and have isolated issue we're seeing to update from 1.5.0 to 1.5.1.....we have unit tests that are using runBlockingTest
and getting IllegalStateException: This job has not completed yet
after that update....digging deeper to try and narrow in on what's changed but just in case anyone encountered this before....Javier
07/28/2021, 12:55 PMIdo Flax
07/28/2021, 7:15 PMcom.papsign.ktor.openapigen
for swagger generation
server endpoint with response (works):
route("stuff"){
jwtAuth {
route("thing").post<Unit, Response, Request, UserPrincipal>(
info("Do a thing")
) { _, request ->
thingService.createThing(
principal().username,
request.thingName
)
status(HttpStatusCode.NoContent)
respond(Response())
}
}
}
Server endpoint without response (404ing):
route("stuff"){
jwtAuth {
route("thing").post<Unit, Unit, Request, UserPrincipal>(
info("Do a thing")
) { _, request ->
thingService.createThing(
principal().username,
request.thingName
)
status(HttpStatusCode.NoContent)
respond(Unit)
}
}
}
Client:
fun createHttpClient(
authConfig: HttpAuthConfig? = null,
connectionTimeout: Int = 5_000
) = HttpClient(Apache) {
if (authConfig != null) {
Auth {
basic {
credentials {
BasicAuthCredentials(authConfig.username, authConfig.password)
}
}
}
}
engine {
socketTimeout = connectionTimeout
connectTimeout = connectionTimeout
connectionRequestTimeout = connectionTimeout * 2
}
expectSuccess = false
}
...
fun HttpClient.withJsonSupport() = config {
Json {
serializer = KotlinxSerializer(kotlinx.serialization.json.Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
accept(ContentType.Any)
}
}
...
private val jsonClient = createHttpClient().withJsonSupport()
...
<http://jsonClient.post|jsonClient.post>("$url/stuff/thing") {
headers {
append(
HttpHeaders.Authorization,
"Bearer $jwtToken"
)
}
contentType(ContentType.Application.Json)
body = Request(thingName)
}
Is it possible that ktor client doesn’t respect Unit responses?grigala
07/28/2021, 9:52 PMinstall(CORS) {
header(HttpHeaders.Range)
header(HttpHeaders.XForwardedProto)
header(HttpHeaders.AccessControlRequestHeaders)
header("x-csrf-token")
header("Authorization")
anyHost()
allowCredentials = true
method(<http://HttpMethod.Post|HttpMethod.Post>)
method(HttpMethod.Get)
method(HttpMethod.Put)
method(HttpMethod.Delete)
method(HttpMethod.Head)
method(HttpMethod.Options)
}
Anders Oedlund
07/29/2021, 10:55 PMlog("BODY START")
in the below function.
private suspend fun logResponseBody(contentType: ContentType?, content: ByteReadChannel): Unit = with(logger) {
log("BODY Content-Type: $contentType")
log("BODY START")
val message = content.tryReadText(contentType?.charset() ?: Charsets.UTF_8) ?: "[response body omitted]"
log(message)
log("BODY END")
}
Does anyone else have a similar experience, or any pointer how to avoid this (other than not installing the Logging plugin)?Marc Knaup
07/30/2021, 10:40 AMinstall()
to intercept the call.Dominick
08/01/2021, 1:57 AMEhtesham Shahzad
08/01/2021, 11:21 AMJgafner
08/01/2021, 3:45 PMJgafner
08/01/2021, 3:45 PMAleksei Tirman [JB]
08/01/2021, 3:56 PMIs it possible to let ktor decide which modules to load based on development mode ?No. The best thing you can do is to wrap a module's code with a check for the
developmentMode
or custom property condition. Here is an example:
embeddedServer(Netty, applicationEngineEnvironment {
connector {
port = 7070
}
module {
if (developmentMode) {
routing {
get("/") {
call.respondText { "You will see it in the development mode" }
}
}
}
}
}).start()
Jgafner
08/01/2021, 4:01 PMAleksei Tirman [JB]
08/01/2021, 4:03 PM-config
CLI argument to specify the path to a HOCON file.Jgafner
08/01/2021, 4:04 PMAleksei Tirman [JB]
08/01/2021, 4:04 PMor maybe some feature like spring config profiles?I don't know about such a feature.