Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda