REST API在Ktor中返回空响应

时间:2019-03-28 19:29:56

标签: java gradle kotlin netty ktor

在需要Netty框架之后,我在Koltin / Java类中使用Ktor

我当前的WebServer.kt类如下:

fun init(serviceProperties: ServerProperties) {

    val route = Routing(serviceProperties)

    val env = applicationEngineEnvironment {
        module {
            main()
        }

        connector {
            host = route.getInternalAddress()
            port = route.getPort()
        }

        connector {
            host = route.getExternalAddress()
            port = route.getPort()
        }
    }

    embeddedServer(Netty, env)
        .start(wait = true)
}

我处理所有请求的方法如下:

private fun Application.main() {
    install(CORS)
    routing {
        get("/") {
            call.respondText ("Test", ContentType.Text.Plain)
        }
    }
}

其他信息:

route.getInternalAddress() // 192.168.0.18 <-- (IPV4 IP) trying to test
route.getExternalAddress() // 0.0.0.0 <-- not yet needed
route.getPort() // 8080

我的输出如下:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.PlatformDependent0 (file:/C:/Users/Kye/.gradle/caches/modules-2/files-2.1/io.netty/netty-all/4.0.34.Final/e1e53fb0283cc6fbc0f3631e60f658ddebcf005/netty-all-4.0.34.Final.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.PlatformDependent0
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[19:18:46.084 INFO ] Application          | No ktor.deployment.watch patterns specified, automatic reload is not active
[19:18:46.256 INFO ] Application          | Responding at http://192.168.0.18:8080
[19:18:46.256 INFO ] Application          | Responding at http://0.0.0.0:8080

前往http://192.168.0.18:8080/时我会得到

  

192.168.0.18没有发送任何数据
  ERR_EMPTY_RESPONSE

我在做什么错了?

0 个答案:

没有答案