I started with a boilerplate http4k project generated by the Project Wizard. I have a Web App user i...
a

Anthony Whitford

over 2 years ago
I started with a boilerplate http4k project generated by the Project Wizard. I have a Web App user interface that needs to make REST calls to the http4k backend. This initially failed because CORS is required. As a result, I added the CORS Filter to the http4k project to get the Web App REST calls working. Alas, while CORS enabled the Web App UI to talk to the http4k server, this broke the simple Unit Test. I get an error like:
Ping test() FAILED
    org.opentest4j.AssertionFailedError: expected: <HTTP/1.1 200 OK
    access-control-allow-origin: null
    access-control-allow-headers: 
    access-control-allow-methods: GET, POST

    pong> but was: <HTTP/1.1 200 OK


    pong>
        at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
        at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
        at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
        at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
        at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
        at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1142)
        at app//com.perusal.Perusalhttp4kTest.Ping test(Perusalhttp4kTest.kt:14)

1 test completed, 1 failed
How can I enable CORS but also make the Unit Test work? I tried adding headers like:
.header("access-control-request-method", "GET")
              .header("origin", "<http://localhost:3000>"),
but I get a similar failure:
Ping test() FAILED
    org.opentest4j.AssertionFailedError: expected: <HTTP/1.1 200 OK
    access-control-allow-origin: null
    access-control-allow-headers: 
    access-control-allow-methods: GET, POST
    access-control-request-method: GET
    origin: <http://localhost:3000>

    pong> but was: <HTTP/1.1 200 OK


    pong>
        at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
        at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
        at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
        at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
        at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
        at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1142)
        at app//com.perusal.Perusalhttp4kTest.Ping test(Perusalhttp4kTest.kt:14)

1 test completed, 1 failed
Good morning. I’ve set up a new Project with: - Gradle *7.5.1* - Kotlin *1.7.20* - Android Gradle pl...
d

Davide Giuseppe Farella

about 3 years ago
Good morning. I’ve set up a new Project with: • Gradle 7.5.1 • Kotlin 1.7.20 • Android Gradle plugin 7.1.3 • Compose 1.3.0 • Compose compiler 1.3.2 Copying the setup from my previous project, but when building, I got
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:47)
Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn’t inline method call: CALL ‘public final fun <get-current> (): T of androidx.compose.runtime.CompositionLocal [inline] declared in androidx.compose.runtime.CompositionLocal’ type=android.content.Context origin=GET_PROPERTY
Method: null
File is unknown
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.codegen.inline.SourceCompilerForInlineKt.getMethodNode(SourceCompilerForInline.kt:118)
Caused by: java.lang.IllegalStateException: couldn’t find inline method Landroidx/compose/runtime/CompositionLocal;.getCurrent()Ljava/lang/Object;
Any idea? I’m already going crazy 😄 Currently, I got a couple of KMP modules and a couple of Android one, but I also tried changing the KMP to plain JVM, without any improvement
Hello, please help I'm trying to use Koin in a KMM project with Voyager lib My Screen ```@OptIn(Expe...
r

Romão

almost 2 years ago
Hello, please help I'm trying to use Koin in a KMM project with Voyager lib My Screen
@OptIn(ExperimentalVoyagerApi::class)
data object QuestionScreen : Screen {

    override val key : ScreenKey
        get() = KEY_QUESTION_SCREEN

    @Composable
    override fun Content() {
        val navigator = LocalNavigator.currentOrThrow

        val screenModel = navigator.getNavigatorScreenModel<QuestionScreenModel>()
        //var screenModel = getScreenModel<QuestionScreenModel>()

        //objects are a list of questions
        //val objects by screenModel.getObject().collectAsState()

        val state by screenModel.state.collectAsState()
My Koin
val screenModelsModule = module {
    factoryOf(::ListScreenModel)
    factoryOf(::DetailScreenModel)
    factoryOf(::QuestionScreenModel)
}
ViewModel
class QuestionScreenModel(
    questionDataSource: SqlDelightQuestionDataSource,
) : ScreenModel {
getting the following
FATAL EXCEPTION: main
                                                                                                    Process: com.jetbrains.kmpapp, PID: 7162
                                                                                                    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
                                                                                                    	at
                                                                                                    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
                                                                                                    Caused by: java.lang.reflect.InvocationTargetException
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at
                                                                                                    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
                                                                                                    Caused by: org.koin.core.error.InstanceCreationException: Could not create
                                                                                                    instance for
                                                                                                    '[Factory:'com.jetbrains.kmpapp.screens.components.QuestionScreenModel']'
                                                                                                    	at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:57)
                                                                                                    	at
                                                                                                    org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
                                                                                                    	at
                                                                                                    org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:116)
                                                                                                    	at org.koin.core.scope.Scope.resolveValue(Scope.kt:247)
                                                                                                    	at org.koin.core.scope.Scope.resolveInstance(Scope.kt:233)
                                                                                                    	at org.koin.core.scope.Scope.get(Scope.kt:212)
                                                                                                    	at
                                                                                                    com.jetbrains.kmpapp.screens.components.QuestionScreen.Content(QuestionScreen.kt:113)
                                                                                                    	at
                                                                                                    cafe.adriel.voyager.navigator.NavigatorKt$CurrentScreen$1.invoke(Navigator.kt:48)
                                                                                                    	at
                                                                                                    cafe.adriel.voyager.navigator.NavigatorKt$CurrentScreen$1.invoke(Navigator.kt:47)
                                                                                                    	at
                                                                                                    androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                                                                                                    	at
Any clue about what iam doing wrong? thanks