File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes controller superclass method invocation in spring 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "controller superclass method invocation in spring 3.0" Watch "controller superclass method invocation in spring 3.0" New topic
Author

controller superclass method invocation in spring 3.0

Yogesh Mashalkar
Greenhorn

Joined: Sep 20, 2005
Posts: 25
I have a abstract superclass controller as below:


There is another controller which extends this class and has a request mapping specified for one of its methods:


Now the issue here is that when dispatcher servlet redirects the request to the specific method (populateBeta in this case), i need to check for some request parameters modified in a separate interceptor class first.
So essentially i have to invoke the throwInterceptorExceptionForRedirection() method before the normal execution of populateBeta() begins.

The reason to eliminate the explicit call in the controller method is because i have multiple controllers & their mapped methods. All controllers extend the BaseController.
It would be great to have throwInterceptorExceptionForRedirection() executed before any URL mapped methods are invoked by the applicationcontext directly.

using point cuts as an option doesnt help as i need the HttpServletRequest object in throwInterceptorExceptionForRedirection().

Any suggestion/help?
Mudassar Hakim
Greenhorn

Joined: Jul 04, 2010
Posts: 25
Hi, you can try using filter with url pattern "/*" & you still have access to the request object. Let me know if you something better & specific in Spring for the mentioned task.
Apart from this I could really understand why exactly are using InterceptorExceptionForRedirection() ?.
Regards


Mudassar Hakim, hakim_mudassar@rediffmail.com
SCJP, SCWCD
Yogesh Mashalkar
Greenhorn

Joined: Sep 20, 2005
Posts: 25
Mudassar,

cannot use filters as i am using the @ExceptionHandler annotation which is applicable only for the specific class(BetaController in this case). this annotation handles all exceptions in all the controllers.
but i am already invoking a interceptor on the "/*" url pattern, which essentially does some loading stuff. if any exception occurs there i am setting a flag in the request object which i can access in the controller.

when the flag is true i am deliberately throwing an exception in the controller, which is handled by the @ExceptionHandler annotation. thats the reason i need to invoke the throwInterceptorExceptionForRedirection() before any other invocations in the controller

i am achieving this but have to add throwInterceptorExceptionForRedirection() call as the first line of all child controllers, since i do not know a way to make spring invoke it automatically for every controller

below is the complete BaseController class:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: controller superclass method invocation in spring 3.0