I need to execute a function before each def in the controller is invoked (before each new request is sent to the server). In this function I will 1) do a session check if valid forward the request to the appropriate action & controller with the params 2) do a sanitization check for user submitted params
I am aware of per controller interceptor, how can I write a global common interceptor.
how and where can I invoke this function in grails? Thanks in advance..
You can use beforeInterceptor in the Controller for exactly the same purpose. Put this into a new controller say BaseController and put in all the stuff which you want to do and then extend all your existing Controllers with BaseController and you are ready to go. For more information on beforeInterceptor Click here
Note: If you already have some common controller which is extended by all other controllers, no need to implement a new controller. Just implement the beforeInterceptor in that controller itself.
Alternatively, you can have a filter implemented and do all your stuff in that filter. For more information on filters in Grails Click Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With