Is there any way to intercept the ratpack request?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there any way to intercept the ratpack request?

Ankit Patel
Hi Team,

I have configured the  handler chain as below.

chain.all(interceptHandler)
    .prefix("demo",
      chain1 -> chain1.prefix("items",
        chain2 -> chain2.prefix(":item_id",
          chain3 -> chain3.path("attributes", attributeHandler)
           
I want to intercept all the request and need to access the pathtokens in that interceptor.

Is there any way to access the pathtokens in the interceptor? because, I am only getting the pathTokens in "attributeHandler".

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Is there any way to intercept the ratpack request?

Luke Daley
Administrator
Hi Ankit,

Handlers operate where they are injected into the handler graph. Since your interceptor is earlier than the path binding handlers, it doesn't know what the tokens are.

If you need to get in front of the actual handler, you can compose the interceptor with the actual via https://ratpack.io/manual/current/api/ratpack/handling/Handlers.html#chain-ratpack.handling.Handler...- (and there are also other ways).

If you need to do something before the response is sent, you can use https://ratpack.io/manual/current/api/ratpack/http/Response.html#beforeSend-ratpack.func.Action-.