Hi All,
I have tried to find the answer to this question on both the Spring forum and by searching StackOverflow. I have found a lot of pages describing horrible architectures and asking for about the same thing as I do, but my intended usage is different so please bear with me :-)
I have a Spring 2.5 project using annotation based form controllers basically like this:
@RequestMapping("/edit/someObject")
public String handleSubmit(HttpServletRequest request, HttpServletResponse response, SomeObject someObject, BindingResult result) {
// Some check here
if(result.hasErrors()) {
return "form";
} else {
SomeObjectService.update(someObject);
return "redirect:/view/someObject";
}
}
In this I check for some http property in the HttpServletRequest and use the HttpServletResponse to send a redirect if this property has a certain value. This check is done is a lot (but not all) of the form controllers in this application. What I would like to do is create a @CheckedSubmit annotation handled by some AOP advice to do this check and then drop the HttpServletRequest and HttpServletResponse parameters from the controller.
My problem is that I have no idea how to access the current HttpServletRequest and HttpServletResponse from this AOP advice without using these two as (unused) parameters to the annotated method, which is what I tried to avoid in the first place.
Summary: How to access the HttpServletRequest/Response from AOP advice on an @RequestMapping annotated method?