You probably want classpath instead of directory i...
# http4k
d
You probably want classpath instead of directory if you're deploying an app
n
Yeah I just wanted to get something working quickly. What’s the easiest way to take a generated
swagger.json
and add it to the classpath?
d
You've got 2 options here. Either run it through a test to retrieve/manipulate the JSON and put it in a place that ends up in the JAR file, or proxy a call from another route through to the contract handler and alter it on the way through
n
Cool; I started working on the second piece a little bit ago. although the HTTP client is timing out, even though it’s a relatively small swagger file
d
you don't need to use an http client to do it.
you can just hard wire the call from one handler to the contract
or even wrap the contract in a filter to check the path and then translate the result
n
this is what i was going for
d
yeah - that's probably overkill. give me a mo
try this:
Copy code
val overallApp = Filter { next ->
        {
            next(it).run {
                if (it.uri.path == "/") body(bodyString().reversed()) else this
            }
        }
    }.then(
        contract {
            renderer = SimpleJson(Jackson)
            routes += "/foo" bindContract Method.GET to { Response(Status.OK) }
        }
    )

    println(overallApp(Request(Method.GET, "/")))
@Nezteb your filter wraps the entire contract and manipulates the JSON on the way out
(that's the other renderer we ship with I'm using there)
but you get the idea
outputs:
Copy code
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

}}">nwonknu<":"oof/:TEG"{:"secruoser"{
n
ahhh, okay. so i’m doing this now. although i stepped over the breakpoint and the request is taking forever to finish. 🤔
even if i have it hit
/health
, which just blindly returns response OK
d
can you reduce the problem a bit - there is a lot going on there? for a start, which server is it hitting, Ktor or SunHttp?
n
Right now SunHTTP. The ktor one was my idea for prod since the docs suggest not using SunHTTP
d
So it hangs? that's weird. What happens if you call the Handler without turning it into a server? presumably that works ok?
n
d
your logging filter seems to be attempting to serialise the entire response?
(suspect it's getting the input stream from the response body)
n
🤦 I owe you a beer. Or kombucha.
d
all good then?
(beer definitely 🙂 )
n
Yeah, I forgot I even had that logging filter, let alone that all it was doing was printing the request to the console 😄
d
there's
DebuggingFilter.PrintResponse()
for that kind of thing. by default it doesn't print out streams
(you'll notice that a lot of these problems we've come across before! 🙂 )
n
Now that I know about the
Filter.NoOp
thing, I can definitely use that to conditionally apply filters 😄