recently I was searching for how to change the headers and body of the HttpServletRequest
object before starting the controller logic, the only way that I found of achieve this is with an aspect, all good with this solution but the problem is that I have a lot of controllers classes, I need to change the value of an specific header in these controllers, I have added all my classes in my aspect:
@Pointcut("execution(* com.mypackage.Controller1..*(..)) || " +
"execution(* com.mypackage.Controller3.someMethod*(..))
//A lot of methods and packages
private void anyMethodWithHeader(){
@Around("anyMethodWithHeader()")
public ResponseEntity<Map<String, Object>> changeHeaderValue(ProceedingJoinPoint jp) throws Throwable{
//Here I got the object array with the arguments that I need
So my question is:
There is a way in the @PointCut
to put a regex or conditional or something like that in just one line or two, to get a specific header?
I mean, I have a lot of controllers, and those controllers receive a lot of headers, but I just want to change the value of a header named test-token
, all I want is to avoid the addition of one more line in my aspect every time that I add a new controller in my project.
I was trying adding the package of the @RequestHeader
in my aspect and other things but nothing works.
Thanks for the comments.