PDA

View Full Version : Intercepting a MultiActionController


marcell
May 18th, 2007, 03:18 PM
Hi,

How do I know inside a preHandle of a HandlerInterceptor which method is going to be called in a MultiActionController. I need this information to capture a method annotation.

I'm using convention over configuration. That is, my url is http://hostname/action/model/add therefore my add method of my ModelController whon extend MultiActionController is going to be called.

Today I have:


public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println(handler.getClass());
return super.preHandle(request, response, handler);
}


is printing:


br.gov.go.tj.projudi.mvc.controller.ModelControlle r


Tnx.

noon
May 19th, 2007, 03:13 AM
I think you can read the method name from the HttpRequest. The name of the parameter is configured in your application context (see the methodNameResolver).

E.g. in your preHandle-method:

System.out.println("action: " + req.getParameter("action"));

Where the parameter name is 'action'.

marcell
May 19th, 2007, 12:18 PM
I dont have the code here, but I think that would return the url, in my example http://hostname/action/model/add which is not acceptable because the mapping can be anything inside the multiactioncontroller (if you use PropertiesMethodNameResolver).

Hummmm... but now I got a idea. I can get the MethodNameResolver from the MultiActionController (with getMethodNameResolver() ) and evaluate with the request:


String method = ((MultiActionController) handler).getMethodNameResolver().getHandlerMethodN ame(request))


Tnx :)