James Black
04/10/2022, 6:41 AMcurl -H "Accept: application/json" -v 0.0.0.0:8080/hello
* Trying 0.0.0.0:8080...
* Connected to 0.0.0.0 (127.0.0.1) port 8080 (#0)
> GET /hello HTTP/1.1
> Host: 0.0.0.0:8080
> User-Agent: curl/7.79.1
> Accept: application/json
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Length: 0
<
* Connection #0 to host 0.0.0.0 left intact
when I start the server and the first line here is the last line, until I make the curl call then it outputs the rest of the lines:
01:34:22.888 [DefaultDispatcher-worker-1] INFO Application - Responding at <http://0.0.0.0:8080>
01:34:30.926 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
01:34:30.929 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true
01:34:30.930 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2383b23
01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
01:34:31.007 [eventLoopGroupProxy-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.chunkSize: 32
This is my Application set up and with or without serialization same error:
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
fun Application.module() {
configureRouting()
configureStatusPages()
configureCallLogging()
// configureSerialization()
}
Status pages I was hoping would get called but it doesn't, so the 404 I am not certain where it is coming from.
fun Application.configureStatusPages() {
install(StatusPages) {
exception<Throwable> { call, cause ->
if(cause is RuntimeException) {
call.respondText(text = "403: $cause" , status = HttpStatusCode.Forbidden)
} else {
call.respondText(text = "500: $cause" , status = HttpStatusCode.InternalServerError)
}
}
status(HttpStatusCode.NotFound) { call, status ->
call.respondText(text = "404: Page Not Found", status = status)
}
}
}
I was hoping to see the logging requests but this doesn't seem to help:
fun Application.configureCallLogging() {
install(CallLogging) {
level = <http://Level.INFO|Level.INFO>
format { call ->
val status = call.response.status()
val httpMethod = call.request.httpMethod.value
val userAgent = call.request.headers["User-Agent"]
"Status: $status, HTTP method: $httpMethod, User agent: $userAgent"
}
}
}
And at the moment the routing is very simple:
fun Application.configureRouting() {
install(Routing) {
routing {
get("/") {
val uri = call.request.uri
call.respondText("Request uri: $uri")
}
get("/hello") {
call.respondText("Hello")
}
get("/weather") {
call.respondText("current weather")
}
}
}
}
Aleksei Tirman [JB]
04/10/2022, 10:35 AMJames Black
04/10/2022, 8:22 PMktor {
deployment {
port = 8060
}
application {
modules = [ com.blackfox.myoutfitpicker.ApplicationKt.module ]
}
}
and I had this in the log, but I get the same error.
15:18:30.997 [DefaultDispatcher-worker-1] INFO Application - Responding at <http://0.0.0.0:8060>
15:18:38.588 [eventLoopGroupProxy-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
This is the output:
curl -v 0.0.0.0:8060/
* Trying 0.0.0.0:8060...
* Connected to 0.0.0.0 (127.0.0.1) port 8060 (#0)
> GET / HTTP/1.1
> Host: 0.0.0.0:8060
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Length: 0
Aleksei Tirman [JB]
04/11/2022, 12:29 PMe: /Users/Aleksei.Tirman/projects/MyOutfitPicker/server/src/main/kotlin/com/blackfox/myoutfitpicker/plugins/Routing.kt: (4, 36): Unresolved reference: api
e: /Users/Aleksei.Tirman/projects/MyOutfitPicker/server/src/main/kotlin/com/blackfox/myoutfitpicker/plugins/Routing.kt: (36, 19): Unresolved reference: WeatherApi
e: /Users/Aleksei.Tirman/projects/MyOutfitPicker/server/src/main/kotlin/com/blackfox/myoutfitpicker/plugins/Routing.kt: (37, 9): Overload resolution ambiguity:
James Black
04/11/2022, 5:23 PM* Trying 0.0.0.0:8080...
* Connected to 0.0.0.0 (127.0.0.1) port 8080 (#0)
> GET /hello HTTP/1.1
> Host: 0.0.0.0:8080
> User-Agent: curl/7.79.1
> Accept: application/json
>
* Empty reply from server
This is now my router.
routing {
get("/") {
val uri = call.request.uri
call.respondText("Request uri: $uri")
}
get("/hello") {
call.respondText("Hello")
}
get("/weather") {
call.respondText("current weather")
//currentWeather()
}
}
James Black
04/11/2022, 6:00 PMinstall(Routing) {
get("/") {
val uri = call.request.uri
call.respondText("Request uri: $uri")
}