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:io.renren.common.aspect.SysLogAspect.java

License:Apache License

private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();

    SysLogEntity sysLog = new SysLogEntity();
    SysLog syslog = method.getAnnotation(SysLog.class);
    if (syslog != null) {
        //??/*from  w w  w.  java2  s  .  c  om*/
        sysLog.setOperation(syslog.value());
    }

    //??
    String className = joinPoint.getTarget().getClass().getName();
    String methodName = signature.getName();
    sysLog.setMethod(className + "." + methodName + "()");

    //?
    Object[] args = joinPoint.getArgs();
    try {
        String params = new Gson().toJson(args[0]);
        sysLog.setParams(params);
    } catch (Exception e) {

    }

    //?request
    HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
    //IP?
    sysLog.setIp(IPUtils.getIpAddr(request));

    //??
    String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
    sysLog.setUsername(username);

    sysLog.setTime(time);
    sysLog.setCreateDate(new Date());
    //?
    sysLogService.insert(sysLog);
}

From source file:io.starter.security.securefield.SecureFieldAspect.java

@Around(FIELD_GET)
public Object getSecureField(ProceedingJoinPoint pjp) throws Throwable {
    String cnm = Thread.currentThread().getStackTrace()[8].getClassName();

    // System.err.println("Calling: " + cnm);
    // if iBatis is calling, do not decrypt
    if (cnm.toLowerCase().contains("ibatis") && SKIP_IBATIS_CALLER) {
        return pjp.proceed(pjp.getArgs());
    }//from  ww  w.  j  a v a2  s  .co  m

    Logger.debug("Get Secure Field for: " + pjp.toLongString());
    Object targetObject = pjp.getTarget();
    String secureFieldName = pjp.getSignature().getName();
    Field secureField = targetObject.getClass().getDeclaredField(secureFieldName);
    secureField.setAccessible(true);
    Object encryptedObject = secureField.get(targetObject);
    secureField.setAccessible(false);
    return SecureEncrypter.decrypt(String.valueOf(encryptedObject));
}

From source file:io.starter.security.securefield.SecureFieldAspect.java

@Around(FIELD_SET)
public Object setSecureField(ProceedingJoinPoint pjp) throws Throwable {
    String cnm = Thread.currentThread().getStackTrace()[8].getClassName();

    // System.err.println("Calling: " + cnm);
    // if iBatis is calling, do not encrypt
    if (cnm.toLowerCase().contains("ibatis") && SKIP_IBATIS_CALLER) {
        return pjp.proceed(pjp.getArgs());
    }//from w  w  w . java 2 s. com
    Logger.debug("Set Secure Field for: " + pjp.toLongString());
    String clearTextValue = String.valueOf(pjp.getArgs()[0]);
    String encryptedValue = SecureEncrypter.encrypt(clearTextValue);
    Object targetObject = pjp.getTarget();
    String secureFieldName = pjp.getSignature().getName();
    Field secureField = targetObject.getClass().getDeclaredField(secureFieldName);
    secureField.setAccessible(true);
    secureField.set(targetObject, encryptedValue);
    secureField.setAccessible(false);
    return null;
}

From source file:it.tidalwave.northernwind.aspect.DebugProfilingAspect.java

License:Apache License

@Nonnull
private static <T extends Annotation> T getAnnotation(final @Nonnull ProceedingJoinPoint pjp,
        final @Nonnull Class<T> annotationClass) throws NoSuchMethodException {
    final MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();

    if (method.getDeclaringClass().isInterface()) // FIXME && annotation inheritance -- FIXME also ancestor class
    {//from w w  w . ja  va  2 s  . c  o m
        final String methodName = pjp.getSignature().getName();
        method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
    }

    return method.getAnnotation(annotationClass);
}

From source file:it.tidalwave.role.spring.spi.DciContextWithAutoThreadBindingAspect.java

License:Apache License

@Around("within(@it.tidalwave.dci.annotation.DciContext *) && execution(* *(..))")
public Object advice(final @Nonnull ProceedingJoinPoint pjp) throws Throwable {
    final Object context = pjp.getTarget();

    if (!context.getClass().getAnnotation(DciContext.class).autoThreadBinding()) {
        return pjp.proceed();
    } else {/*www  .ja va  2s.  c om*/
        if (log.isTraceEnabled()) {
            log.trace("executing {}.{}() with context thread binding", shortId(context),
                    pjp.getSignature().getName());
        }

        // It looks like the @Inject approach creates bogus multiple instance of ContextManager
        final ContextManager contextManager = ContextManager.Locator.find();
        return contextManager.runWithContext(context, new Task<Object, Throwable>() {
            @Override
            public Object run() throws Throwable {
                return pjp.proceed();
            }
        });
    }
}

From source file:jenergy.agent.aop.aspectj.aspects.FileOutputStreamAspect.java

License:Apache License

/**
 * /*from   w w w  .j a va  2s  .  com*/
 * @param thisJoinPoint
 *            The joint point reference.
 * @return Returns <code>null</code> since the return type of the advice method is {@link Void}.
 * @throws Throwable
 *             May throw any exceptions declared by the joinpoint itself. If this exception is not declared and is not a runtime exception, it
 *             will be encapsulated in a {@link RuntimeException} before being thrown to the basis system.
 */
@Around(value = "execution(void jenergy.agent.common.io.FileOutputStreamDelegate.write(..))")
public Object aroundFileOutputStreamWriteOperation(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
    Object[] args = thisJoinPoint.getArgs();
    Subject observable = (Subject) thisJoinPoint.getTarget();

    Object methodReturn = thisJoinPoint.proceed(args);

    for (Observer obs : observable.getObservers()) {
        int value;

        if (args.length == 3) {
            value = (Integer) args[2] - (Integer) args[1];
        } else {
            if (args[0].getClass().isArray()) {
                value = ((byte[]) args[0]).length * 4;
            } else if (Integer.class.isAssignableFrom(args[0].getClass())) {
                value = (Integer) args[0];
            } else {
                throw new RuntimeException("Unknown FileOuputStream's write method!");
            }
        }

        obs.update(observable, value);
    }
    return methodReturn;
}

From source file:kieker.monitoring.probe.aspectj.jersey.OperationExecutionJerseyServerInterceptor.java

License:Apache License

/**
 * Method to intercept outgoing response.
 *
 * @return value of the intercepted method
 *///from  w  w  w  . j a v a2s  .c  o  m
@Around("execution(public void com.sun.jersey.spi.container.ContainerResponse.write())")
public Object operationWriteResponse(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS (Throwable)
    if (!CTRLINST.isMonitoringEnabled()) {
        return thisJoinPoint.proceed();
    }
    final String signature = this.signatureToLongString(thisJoinPoint.getSignature());
    if (!CTRLINST.isProbeActivated(signature)) {
        return thisJoinPoint.proceed();
    }

    final long traceId = CF_REGISTRY.recallThreadLocalTraceId();

    if (traceId == -1) {
        // Kieker trace Id not registered. Should not happen, since this is a response message!
        LOG.warn("Kieker traceId not registered. Will unset all threadLocal variables and return.");
        return thisJoinPoint.proceed();
    }

    final String sessionId = SESSION_REGISTRY.recallThreadLocalSessionId();
    final ContainerResponse containerResponse = (ContainerResponse) thisJoinPoint.getTarget();
    final MultivaluedMap<String, Object> responseHeader = containerResponse.getHttpHeaders();

    // Pass back trace id, session id, eoi but not ess (use old value before the request)
    final List<Object> responseHeaderList = new ArrayList<Object>();
    responseHeaderList.add(Long.toString(traceId) + "," + sessionId + ","
            + Integer.toString(CF_REGISTRY.recallThreadLocalEOI()));
    responseHeader.put(JerseyHeaderConstants.OPERATION_EXECUTION_JERSEY_HEADER, responseHeaderList);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Sending response with header = " + responseHeader.toString() + " to the request: "
                + containerResponse.getContainerRequest().getRequestUri());
    }

    final Object retval = thisJoinPoint.proceed();

    return retval;
}

From source file:me.xiaochutian.aspect.ExceptionAspect.java

@Around("anyMethod()")
public Object doBasicProfiling(ProceedingJoinPoint joinPoint) throws Throwable {
    //        System.out.println("");  
    //        System.out.println("??"+joinPoint.getTarget().getClass().getName());  
    //        System.out.println("??"+joinPoint.getSignature().getName());  
    //        System.out.println("?"+joinPoint.getArgs());  
    //        System.out.println("staticPart:"+ joinPoint.getStaticPart().toShortString());  
    //        System.out.println("kind:"+joinPoint.getKind());  
    //        System.out.println("sourceLocation:"+joinPoint.getSourceLocation());  
    //        Object object = joinPoint.proceed();//   
    //        System.out.println("");  
    Logger logger = LoggerFactory.getLogger(joinPoint.getTarget().getClass());
    logger.debug("??" + joinPoint.getSignature().getName());
    logger.debug("?");
    Arrays.stream(joinPoint.getArgs()).forEach(a -> logger.debug(a.toString() + " "));
    Object object = joinPoint.proceed();
    logger.debug("?");
    return object;
}

From source file:moe.yuna.palinuridae.log.LogAspect.java

@Around("execution(* moe.yuna.palinuridae.dialect..*.*(..))")
public Object logSql(ProceedingJoinPoint pjp) throws Throwable {
    Object result = pjp.proceed(pjp.getArgs());
    LoggerFactory.getLogger(pjp.getTarget().getClass()).debug("====Prepare Sql:" + result);
    return result;
}

From source file:moe.yuna.palinuridae.log.LogAspect.java

@Around("execution(* moe.yuna.palinuridae.core.*BaseDao.find*(..))")
public Object logFindById(ProceedingJoinPoint pjp) throws Throwable {
    Object result = pjp.proceed(pjp.getArgs());
    LoggerFactory.getLogger(pjp.getTarget().getClass()).debug("====result:" + result);
    return result;
}