Example usage for org.aspectj.lang ProceedingJoinPoint getSignature

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

Introduction

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

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:com.thesoftwareguild.flooringmaster.aop.Audit.java

private Object logOrder(ProceedingJoinPoint jp) throws IOException {
    PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("AuditLog.txt", true)));
    Object ret = null;//from  www  .ja v a2 s  .  c  om

    try {
        LocalDateTime logTime = LocalDateTime.now();
        String logTimeString = logTime.toString();
        writer.println(jp.getSignature().getName() + "::" + logTimeString);
        writer.flush();
        writer.close();
        ret = jp.proceed();
    } catch (Throwable ex) {
        System.out.println("Exception in Audit.logOrder()");

    }
    return ret;

}

From source file:com.thesoftwareguild.flooringmaster.aop.TimerAspect.java

public Object timeMethod(ProceedingJoinPoint jp) {

    Object ret = null;/*w w w .j  a va 2 s  .c  o  m*/
    try {

        long start = System.currentTimeMillis();
        ret = jp.proceed();
        long end = System.currentTimeMillis();
        System.out.println("+++++++++++++++++++++++++++++++++");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + "ms.");
        System.out.println("+++++++++++++++++++++++++++++++++");

    } catch (Throwable ex) {
        System.out.println("Exception in simpleTimerAspect.timeMethod()");

    }
    return ret;

}

From source file:com.thesoftwareguild.mavenflooringmastery.aspects.TimingAspect.java

public Object timeMethod(ProceedingJoinPoint jp) {

    Object ret = null;//  w w w .  j av a2s .  c  o  m

    try {
        long start = System.currentTimeMillis();

        ret = jp.proceed();

        long end = System.currentTimeMillis();
        System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + " ms to execute.");
        System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

    } catch (Throwable ex) {
        System.out.println("Exception in TimingAspect.timeMethod()");
    }

    return ret;
}

From source file:com.thesoftwareguild.olympian.SimpleTimerAspect.java

public Object timeMethod(ProceedingJoinPoint jp) {
    try {//from ww  w  .  j a  va2s . co  m
        //getArgs() get all args of whatever method you passed in
        Object retVal = null;

        long start = System.currentTimeMillis();

        retVal = jp.proceed();

        long end = System.currentTimeMillis();

        System.out.println("-----------------------------------------");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + "ms to execute");
        System.out.println("-----------------------------------------");

        return retVal;
    } catch (Throwable ex) {
        Logger.getLogger(SimpleTimerAspect.class.getName()).log(Level.SEVERE, null, ex);
    }

    return null;
}

From source file:com.thinkbiganalytics.install.inspector.aop.logging.LoggingAspect.java

License:Apache License

/**
 * Advice that logs when a method is entered and exited.
 *
 * @param joinPoint join point for advice
 * @return result/*  w  ww  .ja va2s  . co m*/
 * @throws Throwable throws IllegalArgumentException
 */
@Around("applicationPackagePointcut() && springBeanPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    if (log.isDebugEnabled()) {
        log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }
    try {
        Object result = joinPoint.proceed();
        if (log.isDebugEnabled()) {
            log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
                    joinPoint.getSignature().getName(), result);
        }
        return result;
    } catch (IllegalArgumentException e) {
        log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
                joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());

        throw e;
    }
}

From source file:com.tikal.tallerWeb.servicio.monitor.imp.EditorMonitorImpV3.java

License:Apache License

@Around("modelChange()")
public void updateProperty(ProceedingJoinPoint pjp) throws Throwable {
    if (encendido && activo) {
        Object target = pjp.getTarget();
        Object proxyTarget = AopContext.currentProxy();
        if (!(target instanceof Metadata)) {
            String methodName = pjp.getSignature().getName();
            String propertyName = StringUtils.substringAfter(methodName, "set");
            String primeraLetra = propertyName.charAt(0) + "";
            propertyName = primeraLetra.toLowerCase() + StringUtils.substringAfter(propertyName, primeraLetra);
            processChange(proxyTarget, propertyName, pjp.getArgs()[0]);
        }//from   w w w. jav  a2s. c  o m
    }
    pjp.proceed();
}

From source file:com.tsg.flooringmastery.consoleIO.TimeAspect.java

public Object timeMethod(ProceedingJoinPoint jp) {
    Object ret = null;/*from   w  w w  .  ja  v a  2s  .c  o m*/

    try {
        long start = System.currentTimeMillis();
        ret = jp.proceed();

        long end = System.currentTimeMillis();

        System.out.println("++++++++++++++++++++++++++++++++++");
        System.out.println(jp.getSignature().getName() + " " + (end - start) + " ms.");
        System.out.println("++++++++++++++++++++++++++++++++++");
    } catch (Throwable e) {
        System.out.println("Exception in SimpleTimperAspect.timeMethod()");
    }

    return ret;
}

From source file:com.tsg.flooringmasteryspring.TimingAspect.java

public Object timingMethod(ProceedingJoinPoint jp) throws Throwable {
    Object ret = null;//from  w ww. j  a v  a2 s.c o m

    try {
        long start = System.nanoTime();
        ret = jp.proceed();
        long end = System.nanoTime();
        System.out.println("[INFO] " + jp.getSignature().getName() + " took " + (end - start) + "ns");
    } catch (Throwable ex) {
        System.out.println("Exception in SimpleTimerMethodAspect.timeMethod");
        throw ex;
    }
    return ret;
}

From source file:com.vaadin.addon.jpacontainer.demo.aspects.ProviderLoggerAspect.java

License:Apache License

@Around("methodsToBeLogged()")
public Object log(ProceedingJoinPoint pjp) throws Throwable {
    if (logger.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder(pjp.getSignature().getName());
        sb.append("(");
        if (pjp.getArgs().length > 0) {
            for (int i = 0; i < pjp.getArgs().length - 2; i++) {
                sb.append(pjp.getArgs()[i]);
                sb.append(",");
            }//from   w w w  .java  2 s .  com
            sb.append(pjp.getArgs()[pjp.getArgs().length - 1]);
        }
        sb.append(")");
        logger.debug("Calling method: " + sb.toString());
    }
    Object result = pjp.proceed();
    if (logger.isDebugEnabled()) {
        logger.debug("Result of method " + pjp.getSignature().getName() + ": " + result);
    }
    return result;
}

From source file:com.vico.license.aop.SecurityAspect.java

@Around("needAnnotation()")
public Object execute(ProceedingJoinPoint pjp) throws Throwable {

    System.out.println("=====SysLogAspect =====");
    //??//w ww .j  a  v a2  s . c  o m
    MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();

    //,(ignore?)
    if (method.isAnnotationPresent(IgnoreSecurity.class)) {
        return pjp.proceed();
    }

    //request header??token
    System.out.println(WebContext.getRequest());
    String token = WebContext.getRequest().getHeader(tokenName); //,
    System.out.println(token);

    //token
    if (!tokenManager.checkToken(token)) {
        String message = String.format("token [%s] is invalid", token);
        throw new TokenException(message);
    }

    //
    return pjp.proceed();
}