I am using Ktor 3.3.1 with the `Jetty engine`. Cal...
# ktor
s
I am using Ktor 3.3.1 with the
Jetty engine
. Calling
call.request.servletRequestAttributes
from the call interceptor throws the following error. Any idea why it’s not set for the Jetty engine?
Copy code
Wrapped by: java.lang.IllegalStateException: No instance for key AttributeKey: ServletRequestAttributes
        at io.ktor.util.Attributes.get(Attributes.kt:77)
        at io.ktor.util.AttributesJvmBase.get(AttributesJvm.kt:17)
        at io.ktor.server.servlet.jakarta.AttributesKt.getServletRequestAttributes(Attributes.kt:19)
it’s getting called from
Copy code
intercept(ApplicationCallPipeline.Call) {
}
a
Unfortunately, I cannot reproduce the problem with the following code:
Copy code
embeddedServer(Jetty, port = 9000) {
    intercept(ApplicationCallPipeline.Call) {
        println("Attribs: ${context.request.servletRequestAttributes}")
    }
    routing {
        get("/test") {
            call.respondText("OK")
        }
    }
}.start(wait = true)
The stdout:
Copy code
Attribs: {jakarta.servlet.async.path_info=/test, jakarta.servlet.async.request_uri=/test}
s
which version are you using? ..i just created a sample project with the same code and still having the issue
Copy code
plugins {
    kotlin("jvm") version "2.2.20"
    id("io.ktor.plugin") version "3.3.1"
}
Copy code
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.jetty.jakarta.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.servlet.jakarta.*

fun main(args: Array<String>) {
    embeddedServer(Jetty, port = 9000) {
        intercept(ApplicationCallPipeline.Call) {
            println("Attribs: ${context.request.servletRequestAttributes}")
        }
        routing {
            get("/test") {
                call.respondText("OK")
            }
        }
    }.start(wait = true)
}
Copy code
$ curl -I <http://localhost:9000/test>
HTTP/1.1 500 Server Error
Content-Length: 0

2025-11-04 10:41:19.778 [ktor-jetty-9000-7] ERROR io.ktor.server.Application - Unhandled: GET - /test
java.lang.IllegalStateException: No instance for key AttributeKey: ServletRequestAttributes
	at io.ktor.util.Attributes.get(Attributes.kt:77)
	at io.ktor.util.AttributesJvmBase.get(AttributesJvm.kt:17)
	at io.ktor.server.servlet.jakarta.AttributesKt.getServletRequestAttributes(Attributes.kt:19)
	at dev.suresh.ApplicationKt$main$1$1.invokeSuspend(Application.kt:13)
	at dev.suresh.ApplicationKt$main$1$1.invoke(Application.kt)
	at dev.suresh.ApplicationKt$main$1$1.invoke(Application.kt)
	at io.ktor.util.pipeline.DebugPipelineContext.proceedLoop(DebugPipelineContext.kt:79)
	at io.ktor.util.pipeline.DebugPipelineContext.proceed(DebugPipelineContext.kt:57)
a
Thank you for providing the reproducer. In Ktor 3.3.0, Jetty was upgraded to version 12, which introduced changes to the API for accessing request and response objects. I believe the Jetty request object could be exposed to preserve the behavior from previous versions (KTOR-9005).
👍 1