grace
10/29/2023, 8:08 AMTry running the client by hitting the little green arrow on line 11. You'll see thebut Im not able to see any response. I have also run my server. even if my server is not running, it should show some error like server unavailable, no? but it just hangs there I think. I even add a few logs to try debug. pls help thanksprinted to the console by theResponse
, followed by a repeat of the body content, which is printed by line 18.Filter
s4nchez
10/29/2023, 8:55 AMimport org.http4k.client.JavaHttpClient
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.core.then
import org.http4k.filter.DebuggingFilters.PrintResponse
import org.http4k.server.SunHttp
import org.http4k.server.asServer
fun main() {
val server = { _: Request -> Response(OK).body("pong") }
val runningServer = server.asServer(SunHttp(9000)).start()
val client = JavaHttpClient()
val printingClient = PrintResponse().then(client)
printingClient(Request(Method.GET, "<http://localhost:9000/ping>"))
runningServer.stop()
}
That code prints:
***** RESPONSE 200 to GET: <http://localhost:9000/ping> *****
HTTP/1.1 200
content-length: 4
date: Sun, 29 Oct 2023 08:54:56 GMT
pong
Process finished with exit code 0
grace
10/29/2023, 9:04 AMs4nchez
10/29/2023, 9:07 AMgrace
10/29/2023, 9:08 AMs4nchez
10/29/2023, 9:08 AMimport org.http4k.client.JavaHttpClient
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.core.then
import org.http4k.filter.DebuggingFilters.PrintResponse
import org.http4k.server.SunHttp
import org.http4k.server.Undertow
import org.http4k.server.asServer
fun main() {
val server = { _: Request -> Response(OK).body("pong") }
val runningServer = server.asServer(Undertow(0)).start()
val client = JavaHttpClient()
val printingClient = PrintResponse().then(client)
println("bb")
printingClient(Request(Method.GET, "<http://localhost>:${runningServer.port()}/ping"))
println("gogo")
runningServer.stop()
}
This starts a server and calls it on a different port on every execution.org.http4k:http4k-server-undertow
as a dependency)grace
10/29/2023, 9:11 AMs4nchez
10/29/2023, 9:12 AM