cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] ModuleEvaluator

smcardle
Champ in-the-making
Champ in-the-making
Hi All

Not sure if this is the right thread for this but it looked about as relevant as one or two others.

Anyway, I have developed and deployed several ModuleEvaluator's for a project I am on such as HeaderPresentModuleEvaluator & ParameterPresentModuleEvaluator that lets you define a request header or request parameter and only enables the module if present.

However, I have a scenario where I need to use a request Cookie in the evaluation and if present, with a defined value enable the module.

Here is the code I would like to implement

public class CookieModuleEvaluator implements ExtensionModuleEvaluator  {
   
   private static final String COOKIE_PROP = "Cookie";
   private static final String COOKIE_VAL = "Value";

   public boolean applyModule(RequestContext context, Map<String, String> evaluationProperties) {
      
      String cookieWereLookingFor = evaluationProperties.get(COOKIE_PROP);
      String cookieValueWereLookingFor = evaluationProperties.get(COOKIE_VAL);
          
      // HOW do I get the COOKIES from the context ????
      // String cookieValue = context.getCookie(cookieWereLookingFor);
      
      String cookieValue = context.getHeader(cookieWereLookingFor);
      return cookieValueWereLookingFor.equals(cookieValue);
   }
   
   public String [] getRequiredProperties() {
      return new String [] {COOKIE_PROP, COOKIE_VAL};
   }
}

As you can see above I am actually using a header at the moment because I can't find any method on the RequestContext to get either the cookies or the HttpServletRequest from which to get the cookies and the documentation in this area is just about non existent.

Can somebody tell me how to achieve this….

Thanks

Steve

NOTE. I removed the test for the header/cookie not being available to make things clearer.
1 REPLY 1

smcardle
Champ in-the-making
Champ in-the-making
Reply to my own thread…..

The cookies are infact in the headers as a single header named "cookie"

With this information I was able to do exactly what I needed.