I am trying to call my server endpoints and I keep...
# ktor
j
I am trying to call my server endpoints and I keep getting this, if I call "/", "/hello" with or without the accept header. What does it mean to make the bundle as not supporting multiuse? This is my version of Ktor: 2.0.0-beta-1
Copy code
curl -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:
Copy code
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:
Copy code
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.
Copy code
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:
Copy code
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:
Copy code
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")
            }
        }
    }
}
a
Could you please try to change a server port and make a request again? If this doesn’t help, please share your project to troubleshoot this issue.
j
My server part of my project is at: https://github.com/jblack975/MyOutfitPicker/tree/master/server I changed it to this:
Copy code
ktor {
    deployment {
        port = 8060
    }
    application {
        modules = [ com.blackfox.myoutfitpicker.ApplicationKt.module ]
    }
}
and I had this in the log, but I get the same error.
Copy code
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:
Copy code
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
a
When I run a server application I get the following compilation errors:
Copy code
e: /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:
j
I removed the parts that are causing an issue, as building the entire application may be problematic. I am staying on the beta1 version as when I briefly tried to switch to 2.0.0 it had an error and I would rather not troubleshoot that right now. If you want we can meet on google hangout and I can work with you to figure this out, as I am off this week so I can meet at any time. Thanks I no longer get the 404 but it also isn't returning what I expected.
Copy code
* 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.
Copy code
routing {
    get("/") {
        val uri = call.request.uri
        call.respondText("Request uri: $uri")
    }

    get("/hello") {
        call.respondText("Hello")
    }
    get("/weather") {
        call.respondText("current weather")
            //currentWeather()
    }
}
I changed to ktor 2.0.0 and changed my routing to get rid of the "routing {" element and now it works. Thanks
Copy code
install(Routing) {
    get("/") {
        val uri = call.request.uri
        call.respondText("Request uri: $uri")
    }