cancel
Showing results for 
Search instead for 
Did you mean: 

Get HttpServletRequest within extension module evaluator

alejandrogarcia
Champ in-the-making
Champ in-the-making
Hi @ll,

Simple question and simple answer (I believe Smiley Very Happy), 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.
4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator
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

alejandrogarcia
Champ in-the-making
Champ in-the-making
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.

afaust
Legendary Innovator
Legendary Innovator
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

alejandrogarcia
Champ in-the-making
Champ in-the-making
I have tried it out and works perfect! This is the coded I have in my evaluator:


      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.