Andreas Scheja
07/29/2022, 4:06 PMSSLSession
after we got the ability to configure mutual tls with ktor 2.0? I've found a workaround, but I'm not sure if the involved APIs are stable enough to rely on them so it doesn't break during a random update...
intercept(ApplicationCallPipeline.Call) {
val nettyCall = (call.attributes[baseApplicationResponse.EngineRersponseAttributeKey].call) as NettyApplicationCall
val sslHandler = nettyCall.context.pipeline().get(SslHandler::class.java)
try {
val peerPrincipal = sslHandler.engine().session.peerPrincipal as X500Principal
call.attributes.put(PeerPrincipalKey, peerPrincipal)
proceed()
catch (e: SSLPeerUnverifiedException) {
return@intercept call.respondText("No client certificate provided", status = HttpStatusCode.BadRequest)
}
}
I've tried it the other way round too (adding a custom handler to netty), but I couldn't find a way to inject the principal into the ktor call.Joe Altidore
08/01/2022, 8:54 AMError: A JNI error has occurred, please check your installation and try again
2022-08-01T00:00:03.922254+00:00 app[web.1]: Exception in thread "main" java.lang.UnsupportedClassVersionError: com/impact/ApplicationKt has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
2022-08-01T00:00:03.922349+00:00 app[web.1]: at java.lang.ClassLoader.defineClass1(Native Method)
2022-08-01T00:00:03.922384+00:00 app[web.1]: at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
2022-08-01T00:00:03.922539+00:00 app[web.1]: at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
2022-08-01T00:00:03.922575+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader.defineClass(URLClassLoader.java:473)
2022-08-01T00:00:03.922623+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader.access$100(URLClassLoader.java:74)
2022-08-01T00:00:03.922664+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader$1.run(URLClassLoader.java:369)
2022-08-01T00:00:03.922700+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader$1.run(URLClassLoader.java:363)
2022-08-01T00:00:03.922740+00:00 app[web.1]: at java.security.AccessController.doPrivileged(Native Method)
2022-08-01T00:00:03.922774+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader.findClass(URLClassLoader.java:362)
2022-08-01T00:00:03.922808+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
2022-08-01T00:00:03.922842+00:00 app[web.1]: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
2022-08-01T00:00:03.922883+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
2022-08-01T00:00:03.922922+00:00 app[web.1]: at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
Jerry Yion
08/02/2022, 1:46 AMRekha
08/01/2022, 7:05 AMRohan Maity
08/02/2022, 7:50 AMktor-server-resources
)
suspend fun ApplicationCall.redirect(resource: Any) {
val path = application.href(resource)
respondRedirect(path)
}
And here is the file where redirect is used
const val PHRASES = "/phrases"
@Serializable
@Resource(PHRASES)
class Phrases
fun Route.phrases(db: Repository) {
authenticate("auth") {
get<Phrases> {
val user = call.authentication.principal as User
val phrases = db.phrases().toTypedArray()
call.respond(
FreeMarkerContent(
"phrases.ftl",
mapOf("phrases" to phrases, "displayName" to user.displayName)
)
)
}
post<Phrases> {
val params = call.receiveParameters()
val action = params["action"] ?: throw IllegalArgumentException("Missing parameter: action")
when(action) {
"delete" -> {
val id = params["id"] ?: throw IllegalArgumentException("Missing parameter: id")
db.remove(id)
}
"add" -> {
val emoji = params["emoji"] ?: throw IllegalArgumentException("Missing parameter: emoji")
val phrase = params["phrase"] ?: throw IllegalArgumentException("Missing parameter: phrase")
db.add(EmojiPhrase(emoji, phrase))
}
}
call.redirect(Phrases)
}
}
}
Initial page loads fine
But on redirect it fails
on browser console I see this 405 error
Now I am not sure what is wrong here
Update
Actually on further checking its POST
method which is not working
I am not sure what's wrong
when I simply use post(StringUrl)
it works but when server-resources
it does not work
Solved
It was the issue of imports, I used the <http://server.routing.post|server.routing.post>
instead of <http://server.resources.post|server.resources.post>
When using server-resources
plugin in ktor, one needs to use HTTP methods from server.resources
package and not from server.routing
package
Thanks @Aleksei Tirman [JB] helping me heremudasar187
08/01/2022, 11:36 AMJerry Yion
08/02/2022, 1:45 AMOllis
08/02/2022, 8:54 AMktor
? https://github.com/kotest/kotest/issues/3134mp
08/02/2022, 9:10 AMptsiogas
08/02/2022, 10:39 AMLuiz Aguiar
08/02/2022, 2:46 PMSunny
08/03/2022, 7:04 AMSerializer for class 'JsonLiteral' is not found.
Mark the class as @Serializable or provide the serializer explicitly.HttpClientUtils
Request is of type JsonElement
. Anyone faced something similar / any leads to look into.cafonsomota
08/03/2022, 4:57 PMFunkyMuse
08/03/2022, 5:33 PMChad Gregory
08/04/2022, 4:19 PMdefaultRequest
block. has anyone else did this? How did you go about it?MJegorovas
08/05/2022, 7:02 AMRohde Fischer
08/05/2022, 12:32 PMsocketTimeout
has no effect, and my socket just keeps waiting, and I cannot find any parameters or settings for thatPoisonedYouth
08/07/2022, 11:57 AMJoe Altidore
08/07/2022, 2:11 PMRohde Fischer
08/07/2022, 2:56 PMTrey
08/08/2022, 8:59 PMMarc Knaup
08/09/2022, 9:28 AMUTF-8 is not supported.
exception when using Url(String)
constructor on K/JS? I’m trying to figure out why it’s not working 😞
I’m on Cloudflare Workers.Ovsyannikov Alexey
08/09/2022, 5:56 PMNick Halase
08/10/2022, 4:27 PMcall.request.accept()
value, it's a CSV of content types.amadeu01
08/11/2022, 8:46 AMDidier Villevalois
08/11/2022, 8:54 AMio.ktor.utils.io.ByteBufferChannel
reuses the`kotlinx.coroutines.channels.ClosedReceiveChannelException` exception to signal all its EOF errors. It is quite confusing and hard to catch
when you use both `Channel`s and `ByteBufferChannel`s in the same coroutines. Shouldn't ByteBufferChannel
use a custom exception inheriting from IOException
? Should I open a YT issue?Mati Galli
08/11/2022, 7:02 PMtest task
configured on my build.gradle.kts
. It seems that the tests are passing, but an exception is thrown anywayzt
08/11/2022, 7:34 PM<https://youtube.com>
but not when I make a request to another URL such as <https://github.com>
On an actual phone this crash doesn't happen.
The code im using is this in my MainActivity
HttpClient(CIO).get("<https://youtube.com/>")
The crash
Caused by: java.net.SocketException: Network is unreachable
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:762)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:50)
at io.ktor.network.sockets.SocketImpl$connect$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Lucas
08/12/2022, 3:34 AMhhariri
08/12/2022, 9:19 AMhhariri
08/12/2022, 9:19 AM