Example usage for org.aspectj.lang ProceedingJoinPoint getTarget

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

Introduction

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

Prototype

Object getTarget();

Source Link

Document

Returns the target object.

Usage

From source file:com.googlecode.commonspringaspects.aspects.CachingAspect.java

License:Apache License

private String getCacheKey(ProceedingJoinPoint pjp) {
    String targetName = pjp.getTarget().getClass().getSimpleName();
    String methodName = pjp.getSignature().getName();
    Object[] arguments = pjp.getArgs();
    StringBuilder key = new StringBuilder();
    key.append(targetName).append(".").append(methodName);
    if (arguments != null) {
        for (Object argument : arguments) {
            key.append(".").append(argument);
        }/*from w w w  .ja v a2 s. co  m*/
    }
    return key.toString();
}

From source file:com.googlecode.easiest.cache.ever.CacheAspect.java

License:Apache License

private MethodCall buildMethodCall(ProceedingJoinPoint joinPoint) {
    final MethodSignature methodSignature;

    if (joinPoint.getSignature() instanceof MethodSignature) {
        methodSignature = (MethodSignature) joinPoint.getSignature();
    } else {/*  w w w .ja v  a  2 s .c om*/
        throw new RuntimeException(
                "Spring can only join on methods, so casting to MethodSignature should always work.");
    }

    final String concreteClassName = joinPoint.getTarget().getClass().getName();

    return new MethodCall(concreteClassName, methodSignature.getName(), methodSignature.getParameterTypes(),
            joinPoint.getArgs());
}

From source file:com.haulmont.cuba.core.sys.TransactionalInterceptor.java

License:Apache License

private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
    Method method = ((MethodSignature) ctx.getSignature()).getMethod();
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, ctx.getTarget().getClass());
    Transactional transactional = specificMethod.getAnnotation(Transactional.class);
    if (transactional == null)
        throw new IllegalStateException("Cannot determine data store of the current transaction");

    String storeName = Strings.isNullOrEmpty(transactional.value()) ? Stores.MAIN : transactional.value();

    log.trace("Entering transactional method, store='{}'", storeName);

    ((PersistenceImpl) persistence).registerSynchronizations(storeName);

    return ctx.proceed();
}

From source file:com.heliosmi.portal.aspect.LoggingAspect.java

License:Apache License

@Around("allBeans()")
public Object profiler(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.nanoTime();
    String classMethodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName();
    log.info(classMethodName + " - called with param(s) " + ToStringBuilder.reflectionToString(pjp.getArgs()));

    Object returnValue = null;/*from   w  w w  . jav a  2s .  com*/
    try {
        returnValue = pjp.proceed();
    } catch (Exception exception) {
        log.error(ToStringBuilder.reflectionToString(ExceptionUtils.getRootCause(exception)));
        log.error(ExceptionUtils.getStackTrace(exception));
        throw exception;
    }

    long end = System.nanoTime();
    log.info(classMethodName + " - finished. Took " + (end - start) + " milliseconds. ");

    return returnValue;
}

From source file:com.himanshu.um.impl.aop.performance.monitor.DBPerformanceMonitorAOP.java

License:Apache License

@Around("execution(@com.himanshu.um.api.performance.annotation.MonitorPerformance * *(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    long startTime = System.currentTimeMillis();
    /*LOG.debug("logAround() is running!");
    LOG.debug("hijacked method : " + joinPoint.getSignature().getName());
    LOG.debug("hijacked arguments : " + Arrays.toString(joinPoint.getArgs()));
    LOG.debug("Around before is running!");
    joinPoint.proceed(); // continue on the intercepted method
    LOG.debug("Around after is running!");
    LOG.debug("******");*///from  w  w  w.  j a va  2s  . c o  m
    joinPoint.proceed(); // continue on the intercepted method
    LOG.debug("{}, {}, {}", new Object[] { joinPoint.getTarget().getClass().getName(),
            joinPoint.getSignature().getName(), System.currentTimeMillis() - startTime });
}

From source file:com.ideabase.repository.webservice.advice.WebAuthenticationAndAuthorizationAdvice.java

License:Open Source License

/**
 * Retrieve {@see RESTfulController} and http request response object.<Br>
 * verify whether user session contains the valid {@see Subject} object.<br>
 * if user is already authenticated, verify user authorization.<br>
 * if user is authorized, invoke {@code processAuthorizedAction} method from
 * {@see RESTfulController}.<br>//  ww  w .j a va  2 s.  co m
 * otherwise invoke {@code processUnauthorizedAction} method.<br>
 *
 * @param pProceedingJoinPoint intermediate join point state.
 */
@Around("com.ideabase.repository.core.aspect.ArchitecturePointcuts." + "webServiceOperation()")
public void verifyAuthentication(final ProceedingJoinPoint pProceedingJoinPoint) {
    LOG.debug("Verify authentication.");

    // find target object instance.
    final RESTfulController controller = (RESTfulController) pProceedingJoinPoint.getTarget();

    // find http servlet request and response
    final Object[] arguments = pProceedingJoinPoint.getArgs();
    final HttpServletRequest request = (HttpServletRequest) arguments[0];
    final HttpServletResponse response = (HttpServletResponse) arguments[1];
    final HttpSession session = request.getSession();

    if (DEBUG) {
        LOG.debug("Request object - " + request);
    }
    // logged on user must contain subject object on session context.
    try {
        if (DEBUG) {
            LOG.debug("Request uri - " + request.getRequestURI());
        }
        // Build restful action object from request context.
        final RESTfulAction action = URIParameterHelper.buildRESTfulAction(request);
        try {
            verifyAuthenticationAndAuthorization(action, session, request, response, controller);
        } catch (Throwable e) {
            if (DEBUG) {
                LOG.debug("Failed to process an action.", e);
            }
            if (e instanceof AuthorizationException) {
                controller.processErrorAction(action, RESTfulController.ErrorCode.UNAUTHORIZED_ACTION, request,
                        response);
            } else if (e instanceof ActionExecutionException) {
                controller.processErrorAction(action, RESTfulController.ErrorCode.FAILURE_EXECUTION, request,
                        response);
            } else if ((e instanceof AuthenticationException) || (e instanceof LoginException)) {
                controller.processErrorAction(action, RESTfulController.ErrorCode.LOGIN_FAILED, request,
                        response);
            } else {
                controller.processErrorAction(action, RESTfulController.ErrorCode.INVALID_ACTION, request,
                        response);
            }
        }
    } catch (Throwable t) {
        if (DEBUG) {
            LOG.debug("Exception stacktrace - ", t);
        }
        controller.processErrorAction(null, RESTfulController.ErrorCode.INVALID_ACTION, request, response);
    }
}

From source file:com.iisigroup.cap.base.aop.CapAuditLog4HandlerAdvice.java

License:Open Source License

/**
 * Log Around AjaxHandler execute./*from  ww w.  ja v a 2 s  . c  o  m*/
 * 
 * @param pjp
 *            the join point
 * @param data
 *            the data
 * @param parent
 *            the parent
 * @throws Throwable
 * @return Object
 */
public Object logAroundAjaxHandlerExecute(ProceedingJoinPoint pjp, Request params) throws Throwable {
    long start = System.currentTimeMillis();
    params.put(CapConstants.C_AUDITLOG_START_TS, String.valueOf(System.currentTimeMillis()));
    final String TITLE = StrUtils.concat("#[AL_AROUND][", System.nanoTime(), "]");

    String targetName = pjp.getTarget().getClass().getName();

    Method method = CapBeanUtil.findMethod(pjp.getTarget().getClass(), params.get(CapConstants.P_FORM_ACTION),
            (Class<?>) null);
    String logAuditInfo = "none";
    if (method != null) {
        String action = null, function = null;
        CapAuditLogAction auditLogAction = method.getAnnotation(CapAuditLogAction.class);

        action = (auditLogAction != null && auditLogAction.actionType() != null)
                ? auditLogAction.actionType().toString()
                : null;
        function = (auditLogAction != null && auditLogAction.functionCode() != null)
                ? auditLogAction.functionCode().getCode()
                : null;
        if (action != null && function != null) {
            logAuditInfo = StrUtils.concat(auditLogAction.actionType().name(), CapConstants.SPACE,
                    auditLogAction.functionCode().name(), CapConstants.SPACE,
                    auditLogAction.functionCode().getUrlPath());
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("{} ENTRY: {} Start Time: {} Audit Information: {}",
                new Object[] { TITLE, targetName, new Date(start), logAuditInfo });
    }

    Object obj = pjp.proceed();

    logger.info("{} TOTAL_COST= {} ms", TITLE, (System.currentTimeMillis() - start));

    return obj;
}

From source file:com.isotrol.impe3.pms.core.impl.AuthorizationAspect.java

License:Open Source License

@Around("@annotation(com.isotrol.impe3.pms.core.impl.Authorized)")
public Object global(ProceedingJoinPoint pjp) throws Throwable {
    final Authorization a = component.getAuthorization();
    if (a == null) {
        log(pjp, "Not logged in. Not authorized");
        throw new NoSessionException();
    }/*  w w w . j  a v  a 2s . com*/
    final Method m = ((MethodSignature) (pjp.getSignature())).getMethod();
    final Method targetMethod = pjp.getTarget().getClass().getMethod(m.getName(), m.getParameterTypes());
    final Authorized ann = targetMethod.getAnnotation(Authorized.class);
    // Required global authorities
    final boolean hasGA = ann.global().length > 0;
    // Required portal authorities
    final boolean hasPA = ann.portal().length > 0;
    // If no authorities are required the operation is allowed to proceed.
    if (!hasGA && !hasPA) {
        log(pjp, "No required authorities. Proceed");
        return pjp.proceed();
    }
    // If the user is root and the operation is allowed to root, let it go
    if (a.isRoot() && ann.root()) {
        log(pjp, "Root access allowed. Proceed");
        return pjp.proceed();
    }
    // Global authorities.
    if (hasGA && a.hasGlobal(Arrays.asList(ann.global()))) {
        log(pjp, "Global authorities checked. Proceed");
        return pjp.proceed();
    }
    if (hasPA && a.hasPortal(getPortalId(pjp), Arrays.asList(ann.portal()))) {
        log(pjp, "Portal authorities checked. Proceed");
        return pjp.proceed();
    }
    log(pjp, "Not authorized");
    throw new AuthorizationException();
}

From source file:com.isotrol.impe3.pms.core.impl.TimingAspect.java

License:Open Source License

@Around("@within(org.springframework.stereotype.Service)")
public Object time(ProceedingJoinPoint pjp) throws Throwable {
    final Stopwatch w = Stopwatch.createStarted();
    try {//from  ww  w  .java 2  s .  c o  m
        return pjp.proceed();
    } finally {
        final long t = w.elapsed(TimeUnit.MILLISECONDS);
        final String key = pjp.getTarget().getClass().getName() + "." + pjp.getSignature().toShortString();
        map.add(key, t);
        if (t > 500) {
            logger.warn(String.format("[%s] took [%d] ms", key, t));
        }
    }
}

From source file:com.jmmd.biz.shared.aspect.BizAspect.java

License:Open Source License

/**
 * .//ww  w.j a  v a  2s  . c  o  m
 * 
 * @param jionpoint
 * @return
 * @throws Throwable
 */
@Around("bizPointcut() &&  @annotation(aspectLogger)")
public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable {
    /*
     * .
     */
    long l1 = System.currentTimeMillis();

    /*
     * ??.
     */
    String desc = aspectLogger.value();
    /*
     * ??.
     */
    //boolean discover = aspectLogger.discover();

    /*
     * ???.  
     */
    String targetMethodName = jionpoint.getSignature().getName();
    /*
     * ???.
     */
    String targetClassName = jionpoint.getTarget().getClass().getName();
    /*
     * ?.
     */
    Object o = jionpoint.proceed();
    /*
     * ?.
     */
    long l2 = System.currentTimeMillis();
    /*
     * ?.
     */
    StringBuilder aspectMessage = new StringBuilder();

    aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName)
            .append(".").append(targetMethodName).append("),(").append((l2 - l1)).append("ms)")
            .append(",?()");

    /*
     * .
     */
    logger.info(aspectMessage.toString());

    return o;
}