Get HttpServletRequest within extension module evaluator

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2012 11:40 AM
Hi @ll,
Simple question and simple answer (I believe
), is there any way to get access to the objects HttpServletRequest or HttpSession within either a extension module evaluator or a subcomponent evaluator? I don't see any method to do that in org.springframework.extensions.surf.extensibility.ExtensionModuleEvaluator or org.springframework.extensions.surf.extensibility.impl.DefaultSubComponentEvaluator.
This is a very stupid question, but whether getting one of these objects is impossible, would be possible to manipulate URL/parameters of the current request within a extension module? I don't know if I have invented it, but I remember to have read that anywhere :?
Thanks.
Regards.
Simple question and simple answer (I believe

This is a very stupid question, but whether getting one of these objects is impossible, would be possible to manipulate URL/parameters of the current request within a extension module? I don't know if I have invented it, but I remember to have read that anywhere :?
Thanks.
Regards.
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2012 06:59 AM
Hello,
I don't believe there is a direct way of accessing the HttpServletRequest via the provided parameters of the operations in these evaluators.
But you could make use of the RequestContextHolder utility of Spring and obtain the request attributes object of the current Thread via getRequestAttributes(). This yields a RequestAttributes (interface) object, which is AFAIK always a ServletRequestAttributes instance (specific class), which allows you to obtain the HttpServletRequest via getRequest().
Regards
Axel
I don't believe there is a direct way of accessing the HttpServletRequest via the provided parameters of the operations in these evaluators.
But you could make use of the RequestContextHolder utility of Spring and obtain the request attributes object of the current Thread via getRequestAttributes(). This yields a RequestAttributes (interface) object, which is AFAIK always a ServletRequestAttributes instance (specific class), which allows you to obtain the HttpServletRequest via getRequest().
Regards
Axel

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2012 05:01 AM
Hi Axel,
Thanks very much for your answer.
Correct me if I'm wrong, you are suggesting to inject RequestContextHolder in my custom evaluator and then follow the instructions you have detailed to get the HttpServletRequest from it, isn't it?
Regards.
Thanks very much for your answer.
Correct me if I'm wrong, you are suggesting to inject RequestContextHolder in my custom evaluator and then follow the instructions you have detailed to get the HttpServletRequest from it, isn't it?
Regards.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2012 05:12 AM
Hello,
no, the RequestContextHolder can be used without injecting it since it provides a static utility method to access the data it holds.
Regards
Axel
no, the RequestContextHolder can be used without injecting it since it provides a static utility method to access the data it holds.
Regards
Axel

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2012 07:18 AM
I have tried it out and works perfect! This is the coded I have in my evaluator:
Now I'm wondering whether it is a little bit tricky or not… I understand that for any specific reason the org.springframework.extensions.surf.RequestContext class doesn't provide direct access to the HttpServletRequest object. Do you think using the code above could be a issue?
Thanks very much Axel.
Regards.
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = requestAttributes.getRequest();
Now I'm wondering whether it is a little bit tricky or not… I understand that for any specific reason the org.springframework.extensions.surf.RequestContext class doesn't provide direct access to the HttpServletRequest object. Do you think using the code above could be a issue?
Thanks very much Axel.
Regards.
