ktorio / ktor-init-tools Goto Github PK
View Code? Open in Web Editor NEWktor project generator web page and IDEA plugin
Home Page: https://start.ktor.io
License: Other
ktor project generator web page and IDEA plugin
Home Page: https://start.ktor.io
License: Other
Try to create a new project. The New Project Wizard isn't opened, the exception is thrown:
java.lang.NoClassDefFoundError: io/ktor/start/ProjectType
at io.ktor.start.intellij.KtorModuleConfig.(KtorModuleConfig.kt:27)
at io.ktor.start.intellij.KtorModuleBuilder.(KtorModuleBuilder.kt:52)
at io.ktor.start.intellij.KtorModuleType.createModuleBuilder(KtorModuleType.kt:33)
at io.ktor.start.intellij.KtorModuleType.createModuleBuilder(KtorModuleType.kt:24)
at com.intellij.ide.util.projectWizard.ModuleBuilder.getAllBuilders(ModuleBuilder.java:57)
at com.intellij.ide.projectWizard.ProjectTypeStep.a(ProjectTypeStep.java:263)
at com.intellij.ide.projectWizard.ProjectTypeStep.(ProjectTypeStep.java:101)
at com.intellij.ide.projectWizard.NewProjectWizard.init(NewProjectWizard.java:50)
at com.intellij.ide.projectWizard.NewProjectWizard.(NewProjectWizard.java:39)
at com.intellij.ide.actions.NewProjectAction.actionPerformed(NewProjectAction.java:24)
at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:258)
at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:153)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:273)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:287)
at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:283)
at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:106)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:277)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:111)
at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111)
at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:120)
at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:122)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:111)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:308)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at com.apple.laf.ScreenMenuItemCheckbox.itemStateChanged(ScreenMenuItemCheckbox.java:193)
at java.awt.CheckboxMenuItem.processItemEvent(CheckboxMenuItem.java:389)
at java.awt.CheckboxMenuItem.processEvent(CheckboxMenuItem.java:357)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:355)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:343)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:767)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:737)
at java.awt.EventQueue$4.run(EventQueue.java:735)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:719)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:668)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:363)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: io.ktor.start.ProjectType PluginClassLoader[io.ktor.intellij.plugin, 1.1.4] com.intellij.ide.plugins.cl.PluginClassLoader@46a812b2
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:49)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 55 more
When I'm trying to upload swagger.yaml to https://start.ktor.io/# I receive RangeError: Maximum call stack size exceeded
. Idea plugin in such case throwing an error without messages.
I deleted optional start begin of yaml document ---
and file has uploaded successfully to https://start.ktor.io/#.
You can simply reproduce that by adding optional start begin of yaml document ---
to ktor-init-tools/ktor-generator/src/jvmTest/resources/swagger.yaml
and running ktor-init-tools/ktor-generator/src/jvmTest/kotlin/io/ktor/start/SwaggerGenerationTest.kt
Use Ktor Project Generator (1.3.2) with all the defaults, but select Mock HttpClient Engine
.
The generated test file contains import kotlinx.coroutines.io.*
. However, the io
namespace cannot be resolved, so the code does not compile.
This is likely the Intellij Kotlin project wizard, more than KTOR plugin, but I can't tell from outside which plugin adds the Kotlin "Full Stack Web" project creator. Anyways, it generates this code for serving the static content:
fun main() {
embeddedServer(Netty, port = 8080, host = "127.0.0.1") {
routing {
get("/") {
call.respondHtml(HttpStatusCode.OK, HTML::index)
}
static("/static") {
resources()
}
}
}.start(wait = true)
}
The resources()
seems dangerous, without a limit on the file extensions served, and without a package prefix, you could basically download class files and anything else in the class path, which could include configuration and other unintended files.
This is a bad practice to teach, and people won't question what this wizard creates.
The following problem happens when I want to load this swagger file in start.ktor.io (Version 1.2.2):
swagger (1).json.zip
RangeError: Maximum call stack size exceeded
at isInheritanceFromInterface (kotlin.js:1110)
at isInheritanceFromInterface (kotlin.js:1117)
at isInheritanceFromInterface (kotlin.js:1117)
at isInheritanceFromInterface (kotlin.js:1117)
at isInheritanceFromInterface (kotlin.js:1117)
at isInheritanceFromInterface (kotlin.js:1117)
at Object.Kotlin.isType (kotlin.js:1156)
at toList_8 (kotlin.js:15838)
at DynamicAccess.get_keys_mzud1t$ (ktor-generator.js:17168)
at DynamicAccess.get_strKeys_mzud1t$ (ktor-generator.js:17186)
After debugging quite a while it seems to happen when two models have relationships that point to each other. Simplified kotlin form:
data class Model(val otherModel: OtherModel)
data class OtherModel(val model: Model)
Hi,
I just tried to create a sample Project using IntelliJ with the KTor Init Tools.
Creating any Project led to having most dependencies twice in my pom.xml, such as "ktor-server-core" .
One without scope, one with scope "test".
This causes maven to use the test-scoped dependencies only and it won't build the sample application which is not in the test-scope.
Removing the duplictes makes the application build as supposed.
Please provide the dependencies just once in the pom.xml without a scope.
Regards Patrick
The ktor plugin generates the follow code as a raw sockets sample. It doesn't seem to work. The blocking operation happens without Dispatchers.IO context. The launch block is never started
object Client {
@JvmStatic
fun main(args: Array<String>) {
runBlocking {
val socket = aSocket(selectorManager).tcp().connect("127.0.0.1", port = DefaultPort)
val read = socket.openReadChannel()
val write = socket.openWriteChannel(autoFlush = true)
launch {
while (true) {
val line = read.readUTF8Line()
println("server: $line")
}
}
// No Dispatchers.IO context !!!!
for (line in System.`in`.lines()) {
println("client: $line")
write.writeStringUtf8("$line\n")
}
}
}
private fun InputStream.lines() = Scanner(this).lines()
private fun Scanner.lines() = sequence {
while (hasNext()) {
yield(readLine())
}
}
}
There are several compile errors in ApplicationTest when one chooses MockHttpEngine as feature. I am not sure, it seems to me the generated code is completely outdated.
In generated (from https://start.ktor.io) build.gradle
the $ktor_version
is used for ktor dependencies which has a value of 1.2.3
at the moment. The problem is that such version does not exist:
https://kotlin.bintray.com/ktor/io/ktor/ktor-client-websocket/
When one picks the HSTS and CORS plugins (IDEA plugin or online generator, doesn't matter), plugins/HTTP.kt
will not compile. This is due to two issues:
io.ktor.server.plugins.hsts.*
and io.ktor.server.plugins.cors.routing.*
should also be imported, with the latter being quite important, since someone might not read the documentation and import the deprecated option (cors.CORS).
The install(CORS)
call contains the following:
method(HttpMethod.Options)
method(HttpMethod.Put)
method(HttpMethod.Delete)
method(HttpMethod.Patch)
header(HttpHeaders.Authorization)
header("MyCustomHeader")
This doesn't work. method
should be allowMethod
, and header
should be allowHeader
https://ktor-plugin.europe-north1-gke.intellij.net/project/settings
route pretends to be unavailable and drops connection by timeout when requested from specific regions like Donetsk People Republic. For all other locations it works without any issues and response drop happens exactly on server, not some block on the route (ping can reach the same server freely).
Hi there,
Is there a way we can generate the common directory layout? (eg: src/main/kotlin
, src/main/resources
, src/test/kotlin
, src/test/resources
)
Maybe using checkbox? [x] Use standard/maven directory layout
Thanks!!
Use Ktor Project Generator (1.3.2) with all the defaults, but select ContentNegotiation
.
The generated file is missing import io.ktor.features.ContentNegotiation
, so the code does not compile.
Created a PR here - #7
Both http://start.ktor.io/ and IntelliJ plugin generators do not adhere to the typical Gradle project structure e.g
ktor-app/src/(main, test)/(kotlin, resources)
Rather I see a somewhat unfamiliar layout where the resources directory is located at the root of the project and there is also no main and test directories inside the src folder.
Why this design choice? Could you please include a checkbox for those who need (prefer) the typical default directory structure?
When generating a project using Maven
as build system on https://start.ktor.io/ , the wrapper files
are not included in the zip file.
This works fine for Gradle builds though.
Also, it is not possible to control this option va the UI, despite apparent support in the backend....
As erroneously opened in ktorio/ktor:867
1.1.1
io.ktor.server.netty.EngineMain
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
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.
I get an error when generating a client from openapi:
Couldn't generate ZIP. Reason: IllegalStateException: Unsupported 'Float'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.