Negative Lookahead RegEx at Class Level RequestMapping

892 views Asked by At

I'm using Spring 3.0.1 and developing some REST calls. I have a regular expression I used earlier at the method level and it worked fine. However, due to changes in design I decided to separate all such calls into a separate controller. So, I configured the RequestMapping at the class level with the same RegEx but it does not seem to work. Is there a limitation to the type of RegEx that can be matched at the class level mappings? Below are the 2 calls:

@Controller
@RequestMapping("/abcd")
public class ControllerClass 
{....
  @RequestMapping(value="/{var1}/{var2:(?!(ABC|XYZ).+/{var3}")
  public @ResponseBody SomeObject doSomething(@PathVariable("var1") String var1, @PathVariable("var2") String var2), @PathVariable("var3") String var3 {.....}
}

The above works fine and matches anything e.g. /abcd/random/HJGK/ and does not match /abcd/random/ABC/ as expected.

The below does not work in the same fashion though:

@Controller
@RequestMapping("/abcd/{var1}/{var2:(?!(ABC|XYZ).+}/")
public class ControllerClass 
{....
  @RequestMapping(value="{var3}/")
  public @ResponseBody SomeObject doSomething(@PathVariable("var1") String var1, @PathVariable("var2") String var2, @PathVariable("var3") String var3) {.....}
}

Any idea what might be different or wrong here?

0

There are 0 answers