Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute a function before each new request is submitted to a controller in grails

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..

like image 740
pri_dev Avatar asked Dec 12 '22 04:12

pri_dev


1 Answers

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

like image 68
Bagira Avatar answered Jan 31 '23 01:01

Bagira