KamilH
02/19/2021, 12:52 PMContent-Type
header is application/octet-stream
. That is why when I’m requesting this resource, I’m getting No transformation found
exception, because Json serializer doesn’t know it should parse this file. When I tell serializer to handle also this content type it works properly:
install(JsonFeature) {
serializer = serializerProvider.get()
accept(ContentType.Application.Json, ContentType.Application.OctetStream)
}
but it fell a little bit hacky to do it for all requests
Is there a better solution? (of course the best it would be to fix it on the API side, but I don’t have an access to it)melatonina
02/21/2021, 6:00 PMTrustManager
in a ktor client?TheOnlyTails
02/21/2021, 7:30 PMERROR ktor.application - Unhandled: GET - /favicon.ico
java.lang.NumberFormatException: For input string: "favicon.ico"
Why is this happening? I never make a GET request for that file.TheOnlyTails
02/22/2021, 10:04 AMinstall(ContentNegotiation) { gson { this.setPrettyPrinting() } }
:
Cannot access class 'com.google.gson.GsonBuilder'. Check your module classpath for missing or conflicting dependencies
Why is this happening? I have ktor-gson
included as a gradle dependency.Justin Moy
02/23/2021, 3:32 PMHttpResponse
from a <http://client.post|client.post><HttpResponse>(url) {}
it does not seem to throw any exceptions on 4xx or 5xx response codes. Is this the intended behavior? It doesn’t mention on the docs that the default response validator doesn’t fire in this scenario. If the type is switched from HttpResponse
to String
it throws the errorPaul Woitaschek
02/23/2021, 5:03 PMFor most efficiency, you'll have one ConnectionPool and one Dispatcher in your process. These can be shared by many OkHttpClient instances.https://github.com/square/okhttp/issues/3372#issuecomment-304830644
Vladimir
02/24/2021, 3:15 PMShan
02/25/2021, 1:41 AMHEAD
request with Ktor's HttpClient
specifically with using CIO engine? This request:
httpClient.head<HttpResponse> {
url {
protocol = URLProtocol.HTTPS
host = "<http://www.website.com/trying/to/get/etag/outta/here|www.website.com/trying/to/get/etag/outta/here>"
}
}
Returns java.nio.channels.UnresolvedAddressException
only when using CIO engine. When using another engine, e.g. Android, its completes fine. Wondering if there's something special I need to be doing with CIO head requests.melatonina
02/26/2021, 8:39 PMjson.encodeToString()
explicitly, the serialization work as expected. I'm using ktor 1.5.1. Why is this happening?ql562482472
02/27/2021, 3:25 AMJoost Klitsie
02/27/2021, 5:27 PMIan Arbuckle
02/28/2021, 8:58 PMTheOnlyTails
03/01/2021, 7:29 AMappengineRun
task and re-launch, I get Caused by: <http://java.net|java.net>.BindException: Address already in use: bind
, and when I refresh localhost:8080
, it still works, even though the task is stopped. What is going on?Jose A.
03/01/2021, 12:44 PMjava.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)
at io.netty.handler.codec.http.HttpVersion.valueOf(HttpVersion.java:64)
at io.netty.handler.codec.http.HttpRequestDecoder.createMessage(HttpRequestDecoder.java:95)
at io.netty.handler.codec.http.HttpObjectDecoder.decode(HttpObjectDecoder.java:250)
...
2021-03-01 12:39:12.067 [eventLoopGroupProxy-4-31] TRACE Application - Failed to decode request
java.lang.IllegalArgumentException: invalid version format: D|¢Þ:À/ÀÀ'À0ÀÀ(/<5=AÀ+À À#À,À
at io.netty.handler.codec.http.HttpVersion.<init>(HttpVersion.java:120)
...
INFO Application - >>> REQUEST: Unhandled: GET - /templates <- I added these logs for debugging
The requests are made using Chrome (so it's not HTTP/0.9 for sure). It seems even I get the exceptions the requests are received. Any ideas?spierce7
03/01/2021, 6:17 PMmarzelwidmer
03/02/2021, 6:58 AMspand
03/02/2021, 8:57 AMJeff Tycz
03/03/2021, 1:43 AMprivate val _client: HttpClient = HttpClient(engine) {
install(JsonFeature) {
val json = kotlinx.serialization.json.Json {
this.isLenient = true
this.ignoreUnknownKeys = true
}
serializer = KotlinxSerializer(json)
}
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
}
Peter Ertl
03/05/2021, 11:34 AMcrummy
03/05/2021, 8:31 PMuli
03/06/2021, 11:51 PMLuca Sas
03/07/2021, 1:36 PMcall.receive<Data>()
throws a JsonDecodingException
instead of a ContentTransformationException
if the data passed with the request doesnt match the data type i try to receive. Is this normal? What I want to do is use StatusPage
to handle errors in my route handlers.Peter Ertl
03/08/2021, 12:57 PMJoost Klitsie
03/08/2021, 5:02 PMabstract class BaseClient<T> constructor(private val httpClient: HttpClient) {
suspend fun get(): T = httpClient.get<T>("/api/") // T is a reified type: HttpClient.get<reified T>(path: String)
}
Rightly, it will not work and Intellij gives me a warning: Use a class instead! I have the issue, that I cannot pass a class as the httpclient doesn't support that (at least out of the box)
Is there any way I can make this work? Or add some kind of 1 line code I should add/override in the child class that extends from BaseClient?Massimiliano Bertinetti
03/09/2021, 6:18 AMribesg
03/09/2021, 10:13 AMBertram Kirsch
03/09/2021, 12:12 PMResponding at <http://0.0.0.0:9090>
Failed to initialize a channel. Closing: [id: 0xce532d4b, L:/[0:0:0:0:0:0:0:1]:9090 - R:/[0:0:0:0:0:0:0:1]:62473]
java.lang.NoSuchMethodError: 'kotlinx.coroutines.channels.Channel kotlinx.coroutines.channels.ChannelKt.Channel$default(int, kotlinx.coroutines.channels.BufferOverflow, kotlin.jvm.functions.Function1, int, java.lang.Object)'
at io.ktor.server.netty.cio.NettyRequestQueue.<init>(NettyRequestQueue.kt:19)
at io.ktor.server.netty.NettyChannelInitializer.configurePipeline(NettyChannelInitializer.kt:104)
at io.ktor.server.netty.NettyChannelInitializer.initChannel(NettyChannelInitializer.kt:89)
at io.ktor.server.netty.NettyChannelInitializer.initChannel(NettyChannelInitializer.kt:28)
at io.netty.channel.ChannelInitializer.initChannel(ChannelInitializer.java:129)
at io.netty.channel.ChannelInitializer.handlerAdded(ChannelInitializer.java:112)
at io.netty.channel.AbstractChannelHandlerContext.callHandlerAdded(AbstractChannelHandlerContext.java:938)
at io.netty.channel.DefaultChannelPipeline.callHandlerAdded0(DefaultChannelPipeline.java:609)
at io.netty.channel.DefaultChannelPipeline.access$100(DefaultChannelPipeline.java:46)
at io.netty.channel.DefaultChannelPipeline$PendingHandlerAddedTask.execute(DefaultChannelPipeline.java:1463)
at io.netty.channel.DefaultChannelPipeline.callHandlerAddedForAllHandlers(DefaultChannelPipeline.java:1115)
at io.netty.channel.DefaultChannelPipeline.invokeHandlerAddedIfNeeded(DefaultChannelPipeline.java:650)
at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:502)
at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:417)
at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:474)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.ktor.server.netty.EventLoopGroupProxy$Companion$create$factory$1$1.run(NettyApplicationEngine.kt:227)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:832)
Jon Miller
03/09/2021, 9:08 PMAlejandro Rios
03/09/2021, 9:12 PMBertram Kirsch
03/11/2021, 7:50 AMclass SomeApp {
fun Application.main(testing: Boolean = false) {
install(ContentNegotiation) {
gson {
setPrettyPrinting()
}
}
routing {
underpants() // serves context "/underpants"
staticResources() // serves root context "/"
groot() // serves context "/groot"
}
}
}
// Route for static context
fun Routing.staticResources() {
// Serves frontend resources embedded in application jar
static("/") {
defaultResource("index.html", "web-resource")
resources("web-resource")
}
}
fun Routing.underpants(
) {
route("/underpants") {
get {
val map: HashMap<Int, String> = hashMapOf(1 to "Collect underpants.", 2 to "?", 3 to "Profit!")
call.respond(map)
}
}
}
fun Routing.groot(
) {
route("/groot") {
get {
val map: HashMap<Int, String> = hashMapOf(1 to "I", 2 to "am", 3 to "Groot!")
call.respond(map)
}
}
}
Bertram Kirsch
03/11/2021, 7:50 AMclass SomeApp {
fun Application.main(testing: Boolean = false) {
install(ContentNegotiation) {
gson {
setPrettyPrinting()
}
}
routing {
underpants() // serves context "/underpants"
staticResources() // serves root context "/"
groot() // serves context "/groot"
}
}
}
// Route for static context
fun Routing.staticResources() {
// Serves frontend resources embedded in application jar
static("/") {
defaultResource("index.html", "web-resource")
resources("web-resource")
}
}
fun Routing.underpants(
) {
route("/underpants") {
get {
val map: HashMap<Int, String> = hashMapOf(1 to "Collect underpants.", 2 to "?", 3 to "Profit!")
call.respond(map)
}
}
}
fun Routing.groot(
) {
route("/groot") {
get {
val map: HashMap<Int, String> = hashMapOf(1 to "I", 2 to "am", 3 to "Groot!")
call.respond(map)
}
}
}
Rustam Siniukov
03/11/2021, 12:18 PMBertram Kirsch
03/11/2021, 1:25 PMJoost Klitsie
03/12/2021, 4:02 PM