In my aspect class's method I want to get the values of the parameters and the name of the parameters. Names are still ok if I don't get but I need to get the values of the parameters passed is it possible? (There is not issue with ptCut expression , the method is getting called i checked with sysouts)
My Aspect method is something like this :
public void excpetionHappened(Exception e) {
// Log the exception
// log the name of the method name/signature which caused the exception
// log the value of the input parameters to the method
// wrap and throw new exctn
}
Thanks in advance.
You can use a around advice.
This makes it possible to access the parameter while handling the exception.
public aspect ExceptionReporterAspect {
/** The name of the used logger. */
public final static String LOGGER_NAME = "AspectJExceptionLogger";
/** Logger used to log messages. */
private static final Log LOGGER = LogFactory.getLog(LOGGER_NAME);
pointcut stringRequestHandler() :
execution (@RequestMapping Object the.package..*(..));
Object around(): objectRequestHandler(){
try {
return proceed();
} catch (Exception ex){
Signature sig = thisJoinPointStaticPart.getSignature();
Object[] args = thisJoinPoint.getArgs();
String location = sig.getDeclaringTypeName() + '.' + sig.getName() + ", args=" + Arrays.toString(args);
LOGGER.warn("(AOP detected) exception within " + location, ex);
throw(ex)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With