Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when using "logging feature": "java.lang.IllegalStateException: Failed to find HttpClientEngineContainer in classpath via ServiceLoader" #5

Open
karl-run opened this issue Jan 13, 2019 · 2 comments

Comments

@karl-run
Copy link

As erroneously opened in ktorio/ktor:867

Ktor Version

1.1.1

Ktor Engine Used(client or server and name)

io.ktor.server.netty.EngineMain

JVM Version, Operating System and Relevant Context

   openjdk version "1.8.0_192"
   OpenJDK Runtime Environment (build 1.8.0_192-b26)
   OpenJDK 64-Bit Server VM (build 25.192-b26, mixed mode)

OS: Linux 4.14.90-1-MANJARO

Feedback

I have created a completely fresh project using the IntelliJ Ktor-plugin's starter, only choosing "Logging feature" as additional features.

Starting the server without doing any changes gives me the following stack trace:

2019-01-13 16:51:11.390 [main] INFO  Application - No ktor.deployment.watch patterns specified, automatic reload is not active
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:71)
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:80)
	at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflect_api(KCallableImpl.kt:166)
	at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:347)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:297)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:273)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:126)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:245)
	at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:106)
	at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:18)
	at io.ktor.server.engine.ApplicationEngine$DefaultImpls.start$default(ApplicationEngine.kt:46)
	at io.ktor.server.netty.EngineMain.main(EngineMain.kt:17)
	at com.example.ApplicationKt.main(Application.kt:12)
Caused by: java.lang.ExceptionInInitializerError
	at com.example.ApplicationKt.module(Application.kt:27)
	at com.example.ApplicationKt.module$default(Application.kt:16)
	... 18 more
Caused by: java.lang.IllegalStateException: Failed to find HttpClientEngineContainer in classpath via ServiceLoader
	at io.ktor.client.HttpClientJvmKt.<clinit>(HttpClientJvm.kt:28)
	... 20 more

Removing this section in Application.kt:

val client = HttpClient() {
    install(Logging) {
        level = LogLevel.HEADERS
    }
}

Allows me to start the server successfully.

@karl-run
Copy link
Author

Checking "Apache" in the wizard creates a runnable application. Which makes sense to me now that I understand the signature of io.ktor.client.HttpClient. But, it could probably be made more obvious in the wizard, same way that that the base-HttpClient is automatically selected when you select any of the features.

Feel free to close this as "user error".

@cy6erGn0m
Copy link
Contributor

For sure this is usability problem that need to be resolved somehow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants