0

I am using Spring Boot 2 for creating rest services. I am using @after aop to log some of user information who has accessed at the end. Here I want to log the user timezone, i.e. timezone of the client / consumer from which this api is called.

I am using below aspect method.

@Aspect
@Component
public class AuditAspect {

    @Pointcut("@annotation(auditEvent)")
    public void runAuditMethod(AuditEvent auditEvent) {}

    @After("runAuditMethod(auditEvent)")
    public void auditMethod(JoinPoint joinPoint, AuditEvent auditEvent) throws Throwable { 
       .... //get user timezone
    }
}

When I did some research I see that I can use RequestContextUtils.getTimeZone(httpServletRequest) to get the timezone. But is there a way I can get it in aop method?

halfer
  • 19,824
  • 17
  • 99
  • 186
Lolly
  • 34,250
  • 42
  • 115
  • 150
  • 1
    If you want to receive the client's time zone. It will need to be sent in the request from your front end client. This would be the cleanest way to handle that. Otherwise, you can infer it from the ip address (will need some sort of service or utility to do the geolookup) of the request (be cognizant of any cloud hosted middleware or load balancers) which may impede your results – shinjw Jul 15 '21 at 18:21
  • RequestContextutils.getTimeZone will give you server's time – shinjw Jul 15 '21 at 18:23

0 Answers0