Server-Side Kotlin with Ktor · Sessions Part 3 | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2885892-server-side-kotlin-with-ktor/lessons/23

what is ${date?c} in the freemarker hidden input? Thanks!

Hi @eoin_a, thanks for the question. The “?c” applying the c Freemarker built-in to the date value specified in milliseconds. You can find out more about the c built-in here:

https://freemarker.apache.org/docs/ref_builtins_number.html#ref_builtin_c

Hi there, I am having this issue when running the app, any advice? thanks
Exception in thread “main” java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106)
at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:166)
at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:384)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:330)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:275)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:310)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:274)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartup(ApplicationEngineEnvironmentReloading.kt:290)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:272)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:125)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:245)
at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:126)
at io.ktor.server.netty.EngineMain.main(EngineMain.kt:26)
at com.raywenderlich.ApplicationKt.main(Application.kt:69)
Caused by: java.lang.ExceptionInInitializerError
at com.raywenderlich.ApplicationKt$module$4.invoke(Application.kt:98)
at com.raywenderlich.ApplicationKt$module$4.invoke(Application.kt)
at io.ktor.sessions.Sessions$Feature.install(Sessions.kt:52)
at io.ktor.sessions.Sessions$Feature.install(Sessions.kt:49)
at io.ktor.application.ApplicationFeatureKt.install(ApplicationFeature.kt:64)
at com.raywenderlich.ApplicationKt.module(Application.kt:96)
at com.raywenderlich.ApplicationKt.module$default(Application.kt:75)
… 24 more
Caused by: java.lang.NumberFormatException: For input string: “i” under radix 16
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at io.ktor.util.CryptoKt__CryptoKt.hex(Crypto.kt:44)
at io.ktor.util.CryptoKt.hex(Unknown Source)
at com.raywenderlich.AuthKt.(Auth.kt:12)

@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hey @bzzee, I just hit the same error! After some debugging I realized it was due to the value I was using for my SECRET_KEY. It wasn’t entirely clear from the video, however, the hex function expects a hex string meaning that you can only use the values 0-9 and a-f.

The relevant line in the stack trace above is Caused by: java.lang.NumberFormatException: For input string: “i” under radix 16

It appears you’re using the character “i” in your secret key.

I got an error when I try to show signup:
Type class java.util.Collections$SingletonMap is not supported in default data conversion service
did someone find this kind of error before?
UPDATE: I found the issue, I was redirecting instead of using respond

This solved it for me, I made sure my secret key is within 0 to 9, and A to F, and it worked.
Thanks!