Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
How to return from AOP before method on validation failed

I am trying to implement spring AOP @Before . Here is the method

 @Before("execution(* com.dummy.pkg..*.*(..))")
    public Response<Object> beforeServiceAspect(JoinPoint joinPoint) throws Exception {

            Object[] signatureArgs = joinPoint.getArgs();

           String sessionId=(String) signatureArgs[0];


         if(null==sessionId||sessionId.isEmpty()||!loginService.getUserInfo(sessionId))
           {
                Response.setStatusCode("401");
                Response.setC
                Response.setResultString("Unauthorized User");
                  return  Response;    
 //this is where i  want to  return in case of program enter here   
//**point 1** 
           }
   //**point 2**  where execution reaches then resume normal flow 
return "";
}

Here is two thing i wanat to achieve

  1. If flow reaches to point 1 then it return from that point itself.It should not go further and call should return back.
  2. If flow reaches to point 2 , it resume normal flow and call internal method. what happening now is in both cases it flowing normal flow and keep calling internal methods.
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need an @Around advice instead of a @Before advice, if you want to modify the control flow.

@Around("execution(* com.dummy.pkg..*.*(..))")
public Response<Object> beforeServiceAspect(ProceedingJoinPoint joinPoint) throws Exception {

        Object[] signatureArgs = joinPoint.getArgs();

       String sessionId=(String) signatureArgs[0];


     if(null==sessionId || sessionId.isEmpty() || !loginService.getUserInfo(sessionId))
       {
            Response.setStatusCode("401");
            Response.setResultString("Unauthorized User");
            return  Response;    
       }
    return joinPoint.proceed(args);
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!