Example usage for org.aspectj.lang ProceedingJoinPoint getArgs

List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getArgs.

Prototype

Object[] getArgs();

Source Link

Usage

From source file:com.rover12421.shaka.smali.baksmali.baksmaliMainAj.java

License:Apache License

@Around("execution(* org.jf.baksmali.main.main(..))" + "&& args(args)")
public void main(ProceedingJoinPoint joinPoint, String[] args) throws Throwable {
    try {// w ww.  ja va 2 s .  c om
        CommandLineParser parser = new PosixParser();
        CommandLine cli = parser.parse(org.jf.baksmali.main.getOptions(), args);
        if (CommandLineArgEnum.InlieMethodResolverFromFile.hasMatch(cli)) {
            ShakaBaksmaliOption.setInlineMethodResolverFile(
                    cli.getOptionValue(CommandLineArgEnum.InlieMethodResolverFromFile.getOpt()));
            int index = Arrays.binarySearch(args, CommandLineArgEnum.InlieMethodResolverFromFile.getOpt());
            if (index < 0) {
                index = Arrays.binarySearch(args, CommandLineArgEnum.InlieMethodResolverFromFile.getLongOpt());
            }

            if (index >= 0) {
                String[] nArgs = new String[args.length - 2];
                if (index > 0) {
                    System.arraycopy(args, 0, nArgs, 0, index);
                }
                System.arraycopy(args, index + 2, nArgs, index, nArgs.length - index);
                joinPoint.proceed(nArgs);
            } else {
                LogHelper.warning("args error!!!");
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    joinPoint.proceed(joinPoint.getArgs());
}

From source file:com.rover12421.shaka.smali.util.StringUtilsAj.java

License:Apache License

@Around("execution(* org.jf.util.StringUtils.writeEscapedChar(..))" + "&& args(writer, c)")
public void writeEscapedChar(ProceedingJoinPoint joinPoint, Writer writer, char c) throws Throwable {

    if (!ShakaDecodeOption.getInstance().isShowMoreRecognizableCharacters()) {
        joinPoint.proceed(joinPoint.getArgs());
        return;/*from  w  w  w  . java  2  s .  c  om*/
    }

    writer.write(ShakaStringUtil.escaped(c));
}

From source file:com.rover12421.shaka.smali.util.StringUtilsAj.java

License:Apache License

@Around("execution(* org.jf.util.StringUtils.writeEscapedString(..))" + "&& args(writer, value)")
public void writeEscapedString(ProceedingJoinPoint joinPoint, Writer writer, String value) throws Throwable {
    if (!ShakaDecodeOption.getInstance().isShowMoreRecognizableCharacters()) {
        joinPoint.proceed(joinPoint.getArgs());
        return;/*w  w  w .  j a  va 2s.  co m*/
    }

    for (int i = 0; i < value.length(); i++) {
        char c = value.charAt(i);
        writer.write(ShakaStringUtil.escaped(c));
    }
}

From source file:com.rover12421.shaka.smali.util.StringUtilsAj.java

License:Apache License

@Around("execution(* org.jf.util.StringUtils.escapeString(..))" + "&& args(value)")
public String escapeString(ProceedingJoinPoint joinPoint, String value) throws Throwable {
    if (!ShakaDecodeOption.getInstance().isShowMoreRecognizableCharacters()) {
        return (String) joinPoint.proceed(joinPoint.getArgs());
    }// www . ja v a 2s.  c  o  m

    int len = value.length();
    StringBuilder sb = new StringBuilder(len * 3 / 2);

    for (int i = 0; i < len; i++) {
        char c = value.charAt(i);
        sb.append(ShakaStringUtil.escaped(c));
    }

    return sb.toString();
}

From source file:com.sastix.cms.common.services.aop.MethodMonitor.java

License:Apache License

@Around("execution(* com.sastix..services..*.*(..))")
public Object logServiceAccess(ProceedingJoinPoint joinPoint) throws Throwable {
    if (!LOG.isDebugEnabled()) {
        return joinPoint.proceed(); // if not on DEBUG, no point in writing anything
    }/*  ww w. j a v  a2s .  co  m*/

    String name = joinPoint.getSignature().getName();
    LOG.debug("==> {}({})", name, argsAsStrings(joinPoint.getArgs()));

    try {
        Object obj = joinPoint.proceed(); //continue on the intercepted method
        LOG.debug("<==  {}(...) = {}", name, argsAsStrings(obj));
        return obj;
    } catch (Throwable t) {
        LOG.error("<==! {}(...) => EXCEPTION {}", new Object[] { name, t.getMessage() });
        if (t.getCause() != null) {
            LOG.error("<==! caused by: {} - message: {}", t.getCause(), t.getCause().getMessage());
        }
        LOG.error("<==! exception log: ", t);
        throw t;
    }

}

From source file:com.sccl.attech.common.advice.CustomJsonFilterAdvice.java

License:Open Source License

/**
 * Do around.//  w  w  w . j  a  v a2  s .com
 * 
 * @param pjp the pjp
 * @return the object
 * @throws Throwable the throwable
 */
@Around("execution(* com.sccl.attech.modules.template.web.*.*(..))")
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
    MethodSignature msig = (MethodSignature) pjp.getSignature();
    HttpServletResponse response = getResponse(pjp.getArgs());
    CustomJsonFilter annotation = msig.getMethod().getAnnotation(CustomJsonFilter.class);
    CustomJsonFilters annotations = msig.getMethod().getAnnotation(CustomJsonFilters.class);

    if ((annotation == null && annotations == null) || null == response) {
        return pjp.proceed();
    }

    JsonMapper mapper = new JsonMapper();
    if (annotation != null) {
        Class<?> mixin = annotation.mixin();
        Class<?> target = annotation.target();

        if (target != null) {
            mapper.addMixInAnnotations(target, mixin);
        } else {
            mapper.addMixInAnnotations(msig.getMethod().getReturnType(), mixin);
        }
    }

    if (annotations != null) {
        CustomJsonFilter[] filters = annotations.filters();
        for (CustomJsonFilter filter : filters) {
            Class<?> mixin = filter.mixin();
            Class<?> target = filter.target();
            if (target != null) {
                mapper.addMixInAnnotations(target, mixin);
            } else {
                mapper.addMixInAnnotations(msig.getMethod().getReturnType(), mixin);
            }
        }

    }

    try {
        //         response.setCharacterEncoding("UTF-8");
        mapper.writeValue(response.getOutputStream(), pjp.proceed());
        return null;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    // return null;
}

From source file:com.seleniumtests.core.aspects.LogAction.java

License:Apache License

@Around("execution(public * com.seleniumtests.uipage.PageObject+.* (..)) "
        + "|| execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))")
public Object logDebug(ProceedingJoinPoint joinPoint) throws Throwable {
    if (LogAction.indent.get(Thread.currentThread()) == null) {
        LogAction.indent.put(Thread.currentThread(), 0);
    }//from  w  w w.java  2 s .  c  om

    String currentIndent = StringUtils.repeat(" ", LogAction.indent.get(Thread.currentThread()));
    logger.debug(String.format("%sEntering %s", currentIndent, joinPoint.getSignature()));
    Object reply = null;
    try {
        LogAction.indent.put(Thread.currentThread(), LogAction.indent.get(Thread.currentThread()) + 2);
        reply = joinPoint.proceed(joinPoint.getArgs());
    } catch (Throwable e) {
        logger.debug(String.format("%sError in %s: %s - %s", currentIndent, joinPoint.getSignature(),
                e.getClass().getName(), e.getMessage()));
        throw e;
    } finally {
        LogAction.indent.put(Thread.currentThread(), LogAction.indent.get(Thread.currentThread()) - 2);
        logger.debug(String.format("%sFinishing %s: %s", currentIndent, joinPoint.getSignature(),
                buildReplyValues(reply)));
    }
    return reply;
}

From source file:com.seleniumtests.core.aspects.LogAction.java

License:Apache License

/**
 * Log any call to test steps (page object calls inside a PageObject subclass)
 * @param joinPoint//  www . j a  va 2 s  . c o m
 * @throws Throwable 
 */
@Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject
        "(call(public * com.seleniumtests.uipage.PageObject+.* (..))"
        + "&& !call(public * com.seleniumtests.uipage.PageObject.* (..)))")
public Object logSubTestStep(ProceedingJoinPoint joinPoint) throws Throwable {
    if (SeleniumTestsContextManager.getThreadContext().isManualTestSteps()) {
        return joinPoint.proceed(joinPoint.getArgs());
    }

    return commonLogTestStep(joinPoint, "", false);
}

From source file:com.seleniumtests.core.aspects.LogAction.java

License:Apache License

/**
 * Log this method call as a test step//  w  ww  .  j a  v  a2 s .c o  m
 * @param joinPoint         the join point
 * @param stepNamePrefix   string to add before step name
 * @param configStep      is this method call a TestNG configuration method (\@BeforeXXX or \@AfterXXX)
 * @return
 * @throws Throwable
 */
private Object logTestStep(ProceedingJoinPoint joinPoint, String stepNamePrefix, boolean configStep)
        throws Throwable {

    // skip test logging when manual steps are active. This avoid having steps logged twice.
    // do not skip configuration step logging so that debugging remains easy
    if ((SeleniumTestsContextManager.getThreadContext().isManualTestSteps() && !configStep)
            // skip internal configuration steps
            || joinPoint.getSignature().getDeclaringTypeName().startsWith("com.seleniumtests.core")) {
        return joinPoint.proceed(joinPoint.getArgs());
    }

    return commonLogTestStep(joinPoint, stepNamePrefix, configStep);
}

From source file:com.seleniumtests.core.aspects.LogAction.java

License:Apache License

/**
 * Log an action inside a TestStep//  w  w w  .  j  a v a  2  s. com
 * @param joinPoint      the joinPoint
 * @param targetName   target on which action is done (page or element)
 * @return
 * @throws Throwable 
 */
private Object logAction(ProceedingJoinPoint joinPoint, String targetName) throws Throwable {
    List<String> pwdToReplace = new ArrayList<>();
    String actionName = String.format("%s on %s %s", joinPoint.getSignature().getName(), targetName,
            buildArgString(joinPoint, pwdToReplace, new HashMap<>()));
    Object reply = null;
    boolean actionFailed = false;
    TestAction currentAction = new TestAction(actionName, false, pwdToReplace);

    // log action before its started. By default, it's OK. Then result may be overwritten if step fails
    // order of steps is the right one (first called is first displayed)   
    if (TestLogging.getParentTestStep() != null) {
        TestLogging.getParentTestStep().addAction(currentAction);
    }

    try {
        reply = joinPoint.proceed(joinPoint.getArgs());
    } catch (Throwable e) {
        actionFailed = true;
        throw e;
    } finally {
        if (TestLogging.getParentTestStep() != null) {
            currentAction.setFailed(actionFailed);
        }
    }
    return reply;
}