Questions tagged [ktor]
Ktor is a Kotlin Web framework developed by JetBrains
1,162
questions
0
votes
0
answers
4
views
ktor - resource (Unit' is deprecated. Please use `staticResources` instead), usage favicon.ico
The ktor 2.2.1 version was installed in the application, which had no problems with the following code:
routing {
static("/static") {
resources("static")
...
1
vote
0
answers
13
views
in-memory database is persisted between test of same class in ktor
I need to run unit test on my DAOs in ktor, so I'm using an H2 in-memory database, but the data seems to persist between test of the same class.
class TestUserDao : KoinTest {
private lateinit ...
0
votes
0
answers
34
views
Mocked Use Cases in Ktor/Kotest/Koin/Mockk Not Working as Expected in Endpoint Tests
I'm working on a Kotlin Ktor project and encountering an issue with mocking dependencies in my endpoint tests using Kotest, Koin, and Mockk. Specifically, the mocked use cases in my tests are not ...
2
votes
0
answers
34
views
Abruptly closing a Ktor connection
I want to close an ApplicationCall abruptly without sending a response back to the client to simulate a fault.
I cannot figure out how to do it since Ktor hides all the lower-level stuff from me.
I ...
0
votes
1
answer
28
views
Confused about elvis's it
I'm using ktor and for some reason, the elvis operator's it is the outer scope's it and not the left operand. Can someone help to explain?
0
votes
0
answers
29
views
KTOR API httpsredirect plugin does not redirect correct headers when behind reverse proxy (Apache)
I have a KTOR API ((https://github.com/Digital-Architects-Avans/rmc-api) which uses the authentication plugin to authenticate users accessing certain endpoints with an JWT token.
I'm also using the ...
-1
votes
1
answer
28
views
Rate limiter for specific client IP?
The Rate limiter plugin in KTor does not distinguish between client IPs i.e. all clients use the same token bucket.
Is there a way to have a unique bucket for each client IP address?
The rate limiter ...
1
vote
2
answers
52
views
How to serialize / deserialize BLOB images in Ktor with Exposed?
I am new to Ktor and am currently working on a project where I want to use blobs to store user's avatar images. Now there seems to be no decent documentation on how to achieve this.
As there is no ...
0
votes
1
answer
29
views
MongoDB .find() method doesn't work in Kotlin, in KTOR framework
I'm trying to use the .find() method with no arguments to return all the documents in my collection but it return 404 Not Found error.
Here's how the things is organized
In the interface for ...
1
vote
1
answer
34
views
Kotlin Language Server Does not recognize gradle dependencies
I have recently switched to using AstroNeoVim. I have installed the kotlin_language_server LSP, Treesitter on my nvim and I saw changes after that. Now only issue i have is that LSP seems not to ...
0
votes
0
answers
18
views
Reuse same TCP stream for multiple http requests in ktor
import io.ktor.client.*
import io.ktor.client.engine.java.*
import io.ktor.client.request.*
import kotlinx.coroutines.*
suspend fun main() {
val scope = CoroutineScope(Dispatchers.IO)
val ...
1
vote
0
answers
21
views
How to run Kafka Streams with Ktor
I'm deploying a Kafka Streams application to OpenShift, and I'm using Ktor + Netty as the server framework. I'm facing a problem where it seems like the Netty server (or Ktor application) blocks the ...
0
votes
0
answers
41
views
Video streaming with Kotlin and Ktor
I'm writing a backend application in Kotlin+Ktor. The task is that with an html form the user submits a video that needs to be saved in MinIO. Then, at the user’s request, you need to get this video ...
0
votes
1
answer
15
views
Where does KTor go to for undefined server routes/pages?
I am not able to understand where does KTor go to for pages/routes that are not defined in my code for a server?
For example, here is my routing code:
rounting
{
webSocket("/connect/{userid}&...
0
votes
1
answer
25
views
Handle non-SSL client bots for https netty server
I am using KTor https server for my Android app and I have noticed that bots trying to connect to my server fail because of TLS handshake didn't happen.
This is annoying because my log file is filled ...
0
votes
0
answers
12
views
Recommend me ways to route my PDF file to another service
I am writing a backend code in kotlin/micronaut. The scenario which I am facing is that my backend will recieve a PDF file from client and I have to redirect that PDF file to another endpoint(This ...
0
votes
1
answer
46
views
How to test Ktor host routing?
Here is my setup:
fun Application.configure() {
// ...
routing {
myApi()
}
}
fun Route.myApi() {
host("api.${environment?.config?.host}") {
get("v1"...
0
votes
0
answers
12
views
Unresolved reference: module in testApplication() from another subproject
I have a Ktor project, which has sub projects. The Application.kt is in one subproject and the routes are in another sub project. I am writing unit tests for the routes using testApplication(). ...
0
votes
1
answer
37
views
How to get the host from a URL in pure kotlin Common module
I need to know how to get the host from URL in "pure" Kotlin. It can be through a library but it can't be JVM. That is because, I am writing a Kotlin Multiplatform library completely in ...
-1
votes
1
answer
21
views
Why isn't my single-page website loading after deployment?
Serving my single page application works fine when run through IntelliJ. I can pull up the site on my dev computer using http://0.0.0.0:8080.
2023-11-17 16:41:04.791 [main] INFO Application - ...
0
votes
0
answers
28
views
ktor DuplicatePluginException – conflicting application plugin is already installed with the same key as `OpenTelemetry`
I am trying to integrate aspect.io (which acts as opentelmetry collector) into our microservice written using ktor-2.0
The changes are:
buid.gradle.kts
application {
mainClass.set(appMainClass)
...
0
votes
1
answer
40
views
How to download file from an api which returns streamable pdf file in KMM
I have a Kotlin Multiplatform Mobile library which is used in Android and iOS project and Ktor-client framework is being used. I have an api which returns a streamable pdf file. I want to write an api ...
0
votes
0
answers
29
views
method not found installing HttpClientPlugin for ktor for HttpClient
i have calss in my ktor server on Client module that i initialize http client inside that class as follow :
object KtorClient {
private val serializeJson = Json {
prettyPrint = true
isLenient ...
1
vote
1
answer
38
views
Ktor's function `staticResources` is not available on Kotlin native targets
I'm running a simple Ktor server on a Kotlin Native target.
The server should only serve a static html page. I checked the Ktor sample on delivering static content but neither staticResources nor ...
0
votes
0
answers
63
views
Why Request timeout occurs when a request is attempted beyond the "Ktor HttpClient(CIO) maxConnectionsCount" or "maxConnectionsPerRoute" value
"KtorBase2.kt"
open class KtorBase2()
{
private val _httpClient: HttpClient
val httpClient get() = _httpClient
init {
_httpClient = createHttpClient()
}
private ...
0
votes
1
answer
17
views
After I import "StatusPage" call.response and cause.localizedMessage are not recognized
fun main() {
embeddedServer(Netty, port = 8080) {
install(StatusPages) {
exception<IllegalArgumentException> { cause ->
call.respond(HttpStatusCode....
0
votes
1
answer
19
views
Ktor + Postgres - Exception: Function not implemented in LinuxWatchService
I get the following exception when trying to startup my Ktor server:
Exception in thread "main" java.io.IOException: Function not implemented
at java.base/sun.nio.fs.LinuxWatchService....
0
votes
0
answers
17
views
Cant find MongoDb @BsonId Annotation in specific package
I'm at my wits end with this one. I'm trying to learn how to create a web app right now and am using Kotlin, Ktor, React and MongoDb. I am trying to create a data class and give one of the attributes ...
0
votes
1
answer
23
views
Use serializable during taking data from api via ktor
I have problem which taking data from api. because my serializable is different then data classes and I don't know method which I can make it correctly.
How can I take data from this Json data. I try ...
0
votes
0
answers
22
views
JKS file location in KTor
After creating a JKS file for KTor ssl communication and configuring the following:
ktor:
deployment:
port: 8100
sslPort: 8181
application:
modules:
- com.mainmodule
...
0
votes
1
answer
80
views
How to generate OpenAPI specification (documentation.yaml) for all existing Ktor endpoints?
I have Ktor project with 100+ endpoints. How to generate documentation.yaml file with OpenAPI specifications for all existing endpoints? I'm using IntelliJ IDEA.
I can't find any information about how ...
0
votes
0
answers
36
views
Kotlin KTOR IPv4 only socket
We're using ktor-network for TCP sockets on iOS and Android and on some devices when trying to connect to IPv4 remote address, socket is binded tolocal IPv6 address. For me it looks like IPV6_V6ONLY ...
2
votes
0
answers
74
views
Kotlin - Deserializing json string with ktor
I consume a service answering object which contains a string of a json object as follow
{
"id":"13211",
"json":"{\"id\": \"5489491\", \&...
0
votes
0
answers
47
views
how to implement cache mechanism in kotlin multiplatform using ktor
I am using ktor library for network calls in one my kotlin multi platform project. Here we are sharing the business logic between iOS and Android. Is there a way to implement cache mechanism in ktor ? ...
1
vote
0
answers
33
views
Ktor MultiPartFormDataContent request
Hi I have formdata request with OkHttpClient and it is working I want to use it in Ktor but I am getting error when I use Ktor. What am I doing wrong in Ktor?
OkHttpClient (Working)
val client = ...
1
vote
1
answer
62
views
Serializer for class 'MultipartBody' is not found
Hi I am trying to make multiform request with ktor but I am getting above error. How can I serilize MultiPartBody?
val body = MultipartBody.Builder().setType(MultipartBody.FORM)
....
0
votes
0
answers
43
views
Ktor on App Engine with Java 17 runtime unable to read request headers
I just migrated from Java 8 runtime to Java 17 on my Ktor project that runs on Google App Engine Standard environment.
The project compiles and is being deployed without issues, the request response ...
0
votes
1
answer
58
views
KTor server - 400 error with azure app service
I am running ktor server with netty. We had EmbeddedServer() earlier and we moved to EngineMain() to accommodate yaml(conf) config file. It looks like we are getting 400 Bad Request after the changes. ...
0
votes
1
answer
62
views
How to make Ktor's Application.module() work in GraalVM
I am trying to get started with Ktor and GraalVM. I am trying to run a very dummy Ktor app (IntelliJ's default one) with GraalVM.
I've followed https://ktor.io/docs/graalvm.html#prepare-for-graalvm ...
0
votes
1
answer
111
views
Unable to deploy Google App Engine with Java 11 Runtime
I was using Java 8 runtime on my Ktor project until now and the project was getting deployed without issues but now as I migrate to Java 11 runtime, I am having issues.
I was using appengine-web.xml ...
-1
votes
1
answer
60
views
Ktor Response Headers showing null for Set-Cookies
I am making a Gradle KotlinJS App, and I am new to Kotlin. I am using Ktor to ping an API to log in, and from looking at the browser records, I am receiving the return token as a Set-Cookie in the ...
0
votes
1
answer
31
views
How to pass to FormData not a string? Ktor
suspend fun postGov(
number: Int,
closeLocation: String,
closeTime: String,
openLocation: String,
openTime: String,
attachments: List<Attachment>
...
0
votes
0
answers
44
views
How can strings be appended to environment variables in ktor application.yaml?
On https://ktor.io/docs/configuration-file.html#environment-variables merely a simple usage of an environment variable is demonstrated.
What I'd like to achieve is a concatenation of an env var and a ...
1
vote
0
answers
67
views
Setting up socket communication with ktor [closed]
Recently, I was given a task, where I have to open a socket communication over tcp channel using ktor. The connection should be to a given endpoint and port. I am also given a certificate, that I've ...
1
vote
1
answer
59
views
Junit5 annotated functions not executing with Ktor and Gardle
I am using Ktor 2.3.3, Kotlin 1.9.10 and Junit 5.10.0 with java version "20.0.2" 2023-07-18
I'm trying to get a server started and then execute a series of tests against it. Here's my test ...
0
votes
0
answers
72
views
Android Ktor Client Localhost or Local IP Not Working
Trying to call a local server API from Android app using Ktor Client with CIO engine.
When I am using localhost:8080 - at that time I am getting Connection Refused exception and when I am using Local ...
0
votes
1
answer
32
views
Read empty string ENV var to HOCON conf but getting weird double quoted empty string
I have tried to read empty string env var to HOCON conf but getting weird """" when I read it. Tried to read the official doc and tried different variations such as not setting env ...
0
votes
0
answers
51
views
Ktor server with my PC's public ip refuses to work
I tried to run ktor server on my personal computer with my public IP. But server gave me an error.
Here is a kotlin code:
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io....
0
votes
0
answers
66
views
How to rollback database for each e2e test using ktor, exposed, hikari and junit5?
I'm currently trying to create an integration test for my Ktor backend application by following Testing guide in the Ktor Documentation, where the target server is set to connect the MySQL database ...
1
vote
1
answer
78
views
Using Ktor, how do I deserialize JSON responses with lists of different types?
I am working on an Android app that uses Ktor for HTTP requests to an API. Depending upon the query, the response may contain a list of one of two types. The code works when I define four data classes:...