Coder Social home page Coder Social logo

ktor-init-tools's People

Contributors

cy6ergn0m avatar dmitrievanthony avatar e5l avatar hhariri avatar louis-saglio avatar nikolajakshic avatar ololoshechkin avatar orangain avatar orangy avatar paslavsky avatar raj-saxena avatar robstoll avatar rsinukov avatar soywiz avatar stexxe avatar t-kameyama avatar unlikemars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ktor-init-tools's Issues

Raw sockets sample issue

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())
            }
        }
    }

ContentNegotiation not imported

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.

Ktor plugin 1.1.4 breaks New Project Wizard in IDEA

  • IDEA 2018.3.6 Release (183.6156.11),
  • IDEA 2019.1.1 RC (191.6707.31)
    Ktor plugin 1.1.4

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

RangeError: Maximum call stack size exceeded

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

ByteReadChannel: Unresolved reference

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.

Duplicate Maven Dependencies with scope "test" cause build failures

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

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

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.

Intellij IDEA generates unsafe code for new project

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.

Relationship problem: Maximum call stack size exceeded

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)

Generated code for HTTP plugins is broken

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:

Missing imports

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).

Out-of-date code

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

Allow to generate the common directory layout

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!!

Generator does not follow typical project structure.

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?

Ktor web generator blocks specific regions

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.