什么是覆盖参数的AspectJ声明性语法

问题描述:

之前已经使用注释语法解答了这个问题: Aspectj覆盖了一个参数方法

This has been answered before with annotation syntax: Aspectj overwrite an argument of a method

但我无法弄清楚如何使用AspectJ声明性语法。
以下内容应在方法中的每个字符串前添加Poop,但不包括。

But I can't figure out how to do it with the AspectJ declarative syntax. The following should add "Poop" in front of each string in the method but it does not.

public aspect UserInputSanitizerAdvisor {

    pointcut unSafeString() : execution(@RequestMapping * * (..));

    Object around() : unSafeString() {
        //thisJoinPoint.getArgs();
        //proceed();
        System.out.println("I'm Around");
        Object[] args = thisJoinPoint.getArgs();
        if (args != null) {
            for (int i = 0; i < args.length; i++) {
                Object o = args[i];
                if (o != null && o instanceof String) {
                    String s = (String) o;
                    args[i] = "poop: " + s;
                }
            }
        }

        return proceed();
    }

}

我无法弄清楚给proceed()所有参数。

I can't figure out how to give "proceed()" all the arguments.

我得到了注释版本:

@SuppressWarnings("unused")
@Aspect
public class UserInputSanitizerAdivsor {

    @Around("execution(@RequestMapping * * (..))")
    public Object check(final ProceedingJoinPoint jp) throws Throwable {
        Object[] args = jp.getArgs();
        if (args != null) {
            for (int i = 0; i < args.length; i++) {
                Object o = args[i];
                if (o != null && o instanceof String) {
                    String s = (String) o;
                    args[i] = UserInputSanitizer.sanitize(s);
                }
            }
        }
        return jp.proceed(args);
    }
}

现在我对所有Spring MVC控制器都有XSS保护。我希望得到aspectJ语法。

Now I have XSS protection for all my Spring MVC controllers. I was hoping to get the aspectJ syntax working though.