hhariri
aleksey.tomin
06/01/2020, 1:02 PMkotlinx-serialization
in 1.3.0?
I have kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class DeviceItems
All examples for older versions
@Serializable
data class DeviceItems(val id: String, val rows: Set<DeviceItem>)
Aaron Todd
06/01/2020, 1:41 PMByteReadChannel
has been exhausted (or closed)?Michael Burbidge
06/01/2020, 2:55 PMThiyagu
06/01/2020, 6:29 PMhhariri
spand
06/02/2020, 12:39 PMaddamsson
06/02/2020, 1:48 PMThiyagu
06/02/2020, 6:35 PMandev
06/02/2020, 8:20 PMfun Application.module() {
val client = HttpClient(OkHttp) {
install(JsonFeature) {
serializer = GsonSerializer()
}
}
var cached: Data? = null
routing {
get("/") {
if (cached == null) {
val new = client.get<Data>("<https://my-host.com/message>")
cached = new
}
if (cached!!.expires < System.currentTimeMillis()) {
val new = client.get<Data>("<https://my-host.com/message>")
cached = new
}
call.respond(cached!!.message)
}
}
}
data class Data(val expires: Long, val message: String)
Jolas
06/03/2020, 3:50 AMtim
06/03/2020, 9:21 AMcookie.secure = true
as my server is throwing. I've been trying to work through this to no success. Here's the top of the stacktrace:
10:15:06.019 [ktor-jetty-10001-1] ERROR Application - 500 Internal Server Error: GET - /cloud/v1/vault
java.lang.IllegalArgumentException: You should set secure cookie only via secure transport (HTTPS)
at io.ktor.response.ResponseCookies.append(ResponseCookies.kt:30)
at io.ktor.sessions.SessionTransportCookie.send(SessionTransportCookie.kt:52)
at io.ktor.sessions.SessionsKt.sendSessionData(Sessions.kt:214)
at io.ktor.sessions.Sessions$Feature$install$2.invokeSuspend(Sessions.kt:76)
at io.ktor.sessions.Sessions$Feature$install$2.invoke(Sessions.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:318)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:163)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:183)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:27)
I'm running my ktor behind an nginx proxy which terminates https and passes the request on via reverse proxy to the ktor server. Nginx is forwarding these X-Forwarded headers:
"X-Forwarded-For": "[omitted]",
"X-Forwarded-Proto": "[https]",
And nginx conf block:
location /cloud/v1 {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded_Proto 'https';
proxy_pass <http://127.0.0.1:10001>;
}
In my ktor server setup i have:
install(XForwardedHeaderSupport)
As far as I have read, this should now be working but I am still getting the error. I have logged out call.request.origin.scheme
inside one of my controllers and its returning http
so it appears that the XForwadedHeaderSupport isn't setting the scheme to https
... any suggestions?! 🙏rudolf.hladik
06/04/2020, 11:49 AMandev
06/07/2020, 9:15 AMedwinRNDR
06/07/2020, 8:15 PMHamza
06/08/2020, 2:21 PMHttpClient().use { client ->
val response = client.submitForm<HttpResponse>(
url = "<https://discord.com/api/oauth2/token>",
formParameters = Parameters.build {
append("client_id", config.discord.client)
append("client_secret", config.discord.secret)
append("grant_type", "authorization_code")
append("redirect_uri", config.discord.redirect)
append("scope", "identify")
append("code", code)
})
println(response.readText()) // throws an error if response status is not 200.
}
Archie
06/08/2020, 2:56 PMHttpClient
set like so:
HttpClient(engine) {
defaultRequest {
header("A Header", headerValue)
}
}
I wanted to add a test to that ensures that everytime I make a request to the HttpClient
it would add the stated header. Is there a way to do this test?Anders Sveen
06/09/2020, 5:11 PMArchie
06/10/2020, 11:43 AMDoubleReceiveException
issue? How did you work around this?Philipp Mayer
06/10/2020, 12:38 PMclass MqttHandler : SensorExchangeUseCase {
/**
* Factory to read the application.conf file
* <https://stackoverflow.com/questions/53891189/how-do-i-use-custom-configuration-in-ktor>
*/
private val config: MqttConfig = with(ConfigFactory.load()) {
MqttConfig(
this.getString("mqtt.topic"),
getString("mqtt.brokerUrl"),
getInt("mqtt.port"),
getString("mqtt.clientId")
)
}
To test that, I created the following test:
class MqttHandlerTest : FunSpec({
withTestApplication {
(environment.config as MapApplicationConfig).apply {
put("mqtt.topic", "karlheinz")
put("mqtt.brokerUrl", container.host)
put("mqtt.port", port.toString())
put("mqtt.clientId", "Karl")
}
main()
}
test("should read correct Config from HOCON File") {
with(ConfigFactory.load()) {
getString("mqtt.topic") shouldBe "karlheinz"
getString("mqtt.brokerUrl") shouldBe container.host
getInt("mqtt.port") shouldBe port
getString("mqtt.clientId") shouldBe "Karl"
}
}
However, my test fails since it loads the values which are in my local file and not the values that I put there with withTestApplication
.
My Service is not an application module. How could I test the behaviour? It feels like I'm missing something.
Thanks in advance!jean
06/10/2020, 6:44 PMHttpClient(CIO) {
defaultRequest {
url {
host = "<https://my.host.com>"
port = 443
}
}
install(JsonFeature) {
serializer = GsonSerializer()
}
}
I does not work when I try to use it with client.get<ApiResponse<Character>>("/endpoint")
Am I doing anything wrong?e5l
06/11/2020, 8:41 AM1.3.2-1.4-M2
has been released with Kotlin 1.4-M2 supportSean Keane
06/11/2020, 4:07 PMbuild.gradle.kts
instead of build.gradle
. When I configure it from the wizard and build it works fine out of the box. When I convert the file I get the following error.
INFO Application - No ktor.deployment.watch patterns specified, automatic reload is not active
Exception in thread "DefaultDispatcher-worker-3" java.lang.ClassNotFoundException: Module function cannot be found for the fully qualified name 'com.example.ApplicationKt.module'
This is my build.gradle.kts
file
buildscript {
repositories {
jcenter()
mavenCentral()
maven{
url = uri("<https://kotlin.bintray.com/ktor>")
url = uri("<https://kotlin.bintray.com/kotlinx>")
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
}
}
//Setup the application plugins
plugins {
application
kotlin("jvm") version "1.3.72"
}
group = "com.example"
version = "0.0.1"
application {
mainClassName = "io.ktor.server.cio.EngineMain"
}
sourceSets["main"].resources.srcDirs("resources")
sourceSets["test"].resources.srcDirs("testresources")
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven{
url = uri("<https://kotlin.bintray.com/ktor>")
url = uri("<https://kotlin.bintray.com/kotlinx>")
}
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("io.ktor:ktor-server-cio:1.3.2")
implementation("ch.qos.logback:logback-classic:1.2.1")
implementation("io.ktor:ktor-server-core:1.3.2")
implementation("io.ktor:ktor-locations:1.3.2")
implementation("io.ktor:ktor-metrics:1.3.2")
implementation("io.ktor:ktor-client-core:1.3.2")
implementation("io.ktor:ktor-client-core-jvm:1.3.2")
implementation("io.ktor:ktor-client-cio:1.3.2")
implementation("io.ktor:ktor-client-json-jvm:1.3.2")
implementation("io.ktor:ktor-client-gson:1.3.2")
implementation("io.ktor:ktor-client-logging-jvm:1.3.2")
testImplementation("io.ktor:ktor-server-tests:1.3.2")
}
Im not really sure why its not picking it up.aleksey.tomin
06/11/2020, 5:02 PMktor-client-core
and ktor-http-cio
I’ve had a error Could not find "io.ktor:ktor-io-cinterop-bits" in...
2. When I add dependencies ktor-client-core
and ktor-client-cio
I’ve had a error No matching variant of io.ktor:ktor-client-cio:1.3.2-1.4-M2 was found
3. When I add dependencies ktor-client-core
and ktor-client-cio-kotlinMultiplatform
I’ve had a error Could not find "io.ktor:ktor-io-cinterop-bits" in...
How can I do it?CLOVIS
06/12/2020, 12:59 PMFile
or Blob
from a URL (it's a PNG image). I found the example that shows how to do this with Kotlin/JVM, but nothing for Kotlin/JS at the moment. Is it possible?addamsson
06/13/2020, 7:14 PMcall.receiveParameters()
when I use the content negotiation module? I get
kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class Parameters. For generic classes, such as lists, please provide serializer explicitly.
How do I provide a serializer for Parameters? Or a Map? I'm using the kotlinx.serialization serializer like this:
import io.ktor.application.Application
import io.ktor.application.install
import io.ktor.features.ContentNegotiation
import io.ktor.serialization.json
fun Application.configureContentNegotiation() {
install(ContentNegotiation) {
json()
}
}
I also checked the docs but I did not find any examples for this.waghanza
06/14/2020, 8:52 AMkotlin
skills, but I am trying to add it (in fact upgrade to 1.3) in https://github.com/the-benchmarker/web-frameworks/pull/2951
Could someone help me ?
I have some messages Class 'kotlin.Unit' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
on gradle
6.5 and kotlin
1.3.72GurpreetSK
06/14/2020, 1:31 PMCannot access '<http://java.io|java.io>.Closeable' which is a supertype of 'io.ktor.client.HttpClient'. Check your module classpath for missing or conflicting dependencies kotlin multiplatform
Can someone help?esdudnik
06/15/2020, 2:09 PMzalewski.se
06/15/2020, 3:40 PM