Feras Odeh
Feras Odeh

Reputation: 9306

Get calling action and action's arguments from Hibernate Event listener in Grails

I would like to create custom annotation for my domain classes in Grails for auditing. I'm thinking about listening to hibernate events and then save those annotated classes actions.

I still have problem with how could I get the action that called this domain class method and what was its arguments? How could I got them? Any ideas?

Thanks, Feras

Upvotes: 0

Views: 179

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122394

You can use the RequestContextHolder to access the current GrailsWebRequest

GrailsWebRequest req = (GrailsWebRequest)RequestContextHolder.getRequestAttributes();
if(req != null) {
  log.info("controller = " + req.getControllerName());
} else {
  log.info("Not in a web request thread");
}

You also have req.getParams() if you need the whole parameter map.

Upvotes: 1

Related Questions