https://kotlinlang.org logo
#ktor
Title
# ktor
a

Alexandre Brown

08/23/2021, 5:14 PM
[SOLVED] Hello, I am getting some errors when running a Ktor server that uses the Location feature, the ktor app was compiled into a GraalVM native image and upon running it I get the following :
Exception in thread "DefaultDispatcher-worker-2" kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unresolved class: class applications.web.routes.roadclassification.MyLocation
Copy code
import <http://io.ktor.locations.post|io.ktor.locations.post>

...
fun Routing.myFun() {
	route("/my-route") {
		post<MyLocation> {
			call.respondText { "hello" }
		}
	}
}
Copy code
import io.ktor.locations.Location

@Location("/mylocation")
class MyLocation
The app works when not running the native image (regular jar) or when running the native image without using the Location feature. Thanks
r

rocketraman

08/23/2021, 5:28 PM
a

Alexandre Brown

08/23/2021, 5:29 PM
Yes @rocketraman I have a reflection.json file that was inspired by the working example from ktor repo
r

rocketraman

08/23/2021, 5:30 PM
Ok. Never tried it myself, so unfortunately I have no more suggestions.
Hang on the sample reflection.json is just the classes needed for that sample. It wouldn't include your @Location classes.
Have you run your app with the tracing agent?
a

Alexandre Brown

08/23/2021, 6:10 PM
@rocketraman I ran the app with the tracing agent, I copied the content from reflect-config.json to add it to my reflection.json file. Now the app can run but when executing the path using the Location feature (the POST), I get
kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Could not compute caller for function: public constructor MyLocation() defined in applications.web.routes.MyLocation[DeserializedClassConstructorDescriptor@64e2d0d] (member = null)
I also noticed that sometimes the agent does not generate any json file, I tried recreating the jar and re-running the agent using
$JAVA_HOME/bin/java -agentlib:native-image-agent=config-output-dir=META-INF/native-image -jar mdAI-inference-1.0-all.jar
but now nothing is generated.
r

rocketraman

08/23/2021, 6:26 PM
Are you hitting the app endpoints while the agent is running?
a

Alexandre Brown

08/23/2021, 6:27 PM
yes
Ok I was able to re-generate the reflect-config.json. I will try again.
@rocketraman Ideally should I only use the content from
reflect-config.json
in my reflection.json file or add what is generated to what I currently have?
r

rocketraman

08/23/2021, 6:33 PM
The agent has a merge feature to merge separate configs together. However, I doubt you need to worry about the sample json -- those entries should get covered by your local agent run.
a

Alexandre Brown

08/23/2021, 6:34 PM
@rocketraman My issue seems to be fixed now, I deleted the content of my
reflection.json
file and copy pasted the content from the generated
reflect-config.json
file from the agent and now it works. Thanks a lot!
👍 1
193 Views