Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda