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
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);
}