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.netflix.genie.web.aspect.HealthCheckMetricsAspect.java

License:Apache License

private void recordHealthIndicatorTurnaround(final long turnaround, final ProceedingJoinPoint joinPoint,
        @Nullable final Throwable throwable) {
    log.debug("{} completed in {} ns (exception: {})", joinPoint.getTarget().getClass().getSimpleName(),
            turnaround, throwable != null ? throwable.getClass().getSimpleName() : "none");
    final Set<Tag> tags;
    if (throwable == null) {
        tags = MetricsUtils.newSuccessTagsSet();
    } else {//from  w  w  w  . j  a v a  2  s  .c  om
        tags = MetricsUtils.newFailureTagsSetForException(throwable);
    }
    tags.add(Tag.of(HEALTH_INDICATOR_CLASS_TAG_NAME, joinPoint.getTarget().getClass().getSimpleName()));
    this.registry.timer(HEALTH_INDICATOR_TIMER_METRIC_NAME, tags).record(turnaround, TimeUnit.NANOSECONDS);
}

From source file:com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCacheAspect.java

License:Apache License

@Around("cacheRemoveAnnotationPointcut()")
public Object methodsAnnotatedWithCacheRemove(final ProceedingJoinPoint joinPoint) throws Throwable {
    Method method = getMethodFromTarget(joinPoint);
    Object obj = joinPoint.getTarget();
    Object[] args = joinPoint.getArgs();
    Validate.notNull(method, "failed to get method from joinPoint: %s", joinPoint);
    MetaHolder metaHolder = MetaHolder.builder().args(args).method(method).obj(obj)
            .executionType(ExecutionType.SYNCHRONOUS).build();
    CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory
            .createCacheRemoveInvocationContext(metaHolder);
    HystrixRequestCacheManager.getInstance().clearCache(context);
    return joinPoint.proceed();
}

From source file:com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCollapserAspect.java

License:Apache License

@Around("hystrixCollapserAnnotationPointcut()")
public Object methodsAnnotatedWithHystrixCommand(final ProceedingJoinPoint joinPoint) throws Throwable {
    HystrixCollapser hystrixCollapser;//from  ww  w  . j ava 2 s.co m
    Method collapserMethod = getMethodFromTarget(joinPoint);
    Object obj = joinPoint.getTarget();
    Object[] args = joinPoint.getArgs();

    Validate.notNull(collapserMethod, "failed to get collapser method from joinPoint: %s", joinPoint);
    hystrixCollapser = collapserMethod.getAnnotation(HystrixCollapser.class);

    Method commandMethod = getMethodFromTarget(joinPoint, hystrixCollapser.commandMethod());
    ExecutionType collapserExecutionType = ExecutionType.getExecutionType(collapserMethod.getReturnType());
    ExecutionType commandExecutionType = ExecutionType.getExecutionType(commandMethod.getReturnType());
    Closure closure = ClosureFactoryRegistry.getFactory(commandExecutionType).createClosure(commandMethod, obj,
            args);

    HystrixCommand hystrixCommand = commandMethod.getAnnotation(HystrixCommand.class);
    Validate.notNull(hystrixCommand,
            "collapser cannot refer to the '' method which wasn't annotated with @HystrixCommand");

    MetaHolder metaHolder = MetaHolder.builder().args(args).method(commandMethod).obj(obj).closure(closure)
            .executionType(commandExecutionType).hystrixCollapser(hystrixCollapser)
            .hystrixCommand(hystrixCommand).defaultCommandKey(commandMethod.getName())
            .defaultCollapserKey(collapserMethod.getName()).defaultGroupKey(obj.getClass().getSimpleName())
            .build();
    CommandCollapser commandCollapser = new CommandCollapser(metaHolder);
    return CommandExecutor.execute(commandCollapser, collapserExecutionType);
}

From source file:com.netsteadfast.greenstep.aspect.HessianServiceProxyAspect.java

License:Apache License

private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    String serviceId = AspectConstants.getServiceId(annotations);

    /**/*from ww  w .  j a  va 2  s  . co  m*/
     * ???? service-bean
     */
    if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) {
        //logger.info( "reject proxy service: " + serviceId );
        return pjp.proceed();
    }

    String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal());

    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
        /**
         * ???? service-bean
         */
        if (StringUtils.isBlank(userId)) {
            logger.warn("no userId");
            pjp.proceed();
        }

        /**
         * ???? service-bean
         */
        if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
            logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId);
            return pjp.proceed();
        }
    }

    String serviceInterfacesName = "";
    Class<?> serviceInterfaces[] = pjp.getTarget().getClass().getInterfaces();
    for (Class<?> clazz : serviceInterfaces) {
        if (clazz.getName().indexOf(".service.") > -1) {
            serviceInterfacesName = clazz.getName();
        }
    }
    if (StringUtils.isBlank(serviceInterfacesName)) {
        logger.error("error no service interface: " + serviceId);
        throw new Exception("error no service interface: " + serviceId);
    }

    String url = GreenStepHessianUtils.getServiceUrl(serviceId);
    String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/"
            + ApplicationSiteUtils.getContextPath(Constants.getSystem());

    /**
     * ?????, ? HessianServiceProxyAspect ? (server-remote???)
     *  http://127.0.0.1:8080/
     *  hessian.enable=Y ???, ?url hessian.serverUrl=http://127.0.0.1:8080/
     * 
     */
    if (url.indexOf(theSystemPath) > -1) {
        logger.error("cannot open same-server. now system contextPath = " + theSystemPath
                + " , but proxy url = " + url);
        throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath
                + " , but proxy url = " + url);
    }

    logger.info("proxy url = " + url);
    HessianProxyFactory factory = null;
    Object proxyServiceObject = null;
    if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) { // ?checkValue?
        factory = new GreenStepHessianProxyFactory();
        ((GreenStepHessianProxyFactory) factory)
                .setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId));
        proxyServiceObject = ((GreenStepHessianProxyFactory) factory)
                .createForHeaderMode(Class.forName(serviceInterfacesName), url);
    } else { // ?checkValue?
        factory = new HessianProxyFactory();
        proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url);
    }
    Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods();
    Method proxyObjectMethod = null;
    if (null == proxyObjectMethods) {
        logger.error("error no find proxy method: " + serviceId);
        throw new Exception("error no find proxy method: " + serviceId);
    }
    for (Method m : proxyObjectMethods) {
        if (m.getName().equals(signature.getMethod().getName())
                && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) {
            proxyObjectMethod = m;
        }
    }

    if (null == proxyObjectMethod) {
        logger.error("error no execute proxy method: " + serviceId);
        throw new Exception("error no execute proxy method: " + serviceId);
    }

    Object resultObj = null;
    try {
        resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs());
        this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs());
    } catch (InvocationTargetException e) {
        if (e.getMessage() != null) {
            throw new ServiceException(e.getMessage().toString());
        }
        if (e.getTargetException().getMessage() != null) {
            throw new ServiceException(e.getTargetException().getMessage().toString());
        }
        throw e;
    } catch (Exception e) {
        logger.error(e.getMessage().toString());
        throw e;
    }
    logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName());
    return resultObj;
}

From source file:com.netsteadfast.greenstep.aspect.ServiceAuthorityCheckAspect.java

License:Apache License

@Around(AspectConstants.LOGIC_SERVICE_PACKAGE)
public Object logicServiceProcess(ProceedingJoinPoint pjp)
        throws AuthorityException, ServiceException, Throwable {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    String serviceId = AspectConstants.getServiceId(annotations);
    Subject subject = SecurityUtils.getSubject();
    Method method = signature.getMethod();
    if (subject.hasRole(Constants.SUPER_ROLE_ALL) || subject.hasRole(Constants.SUPER_ROLE_ADMIN)) {
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }/*w ww  .  j  a  v a 2 s.  c o  m*/
    if (StringUtils.isBlank(serviceId)) { //  service id  
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    if (!this.isServiceAuthorityCheck(annotations)) { //  ServiceAuthority  check=false ? 
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    Annotation[] methodAnnotations = method.getAnnotations();
    if (this.isServiceMethodAuthority(serviceId, methodAnnotations, subject)) {
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    logger.warn("[decline] user[" + subject.getPrincipal() + "] " + pjp.getTarget().getClass().getName() + " - "
            + signature.getMethod().getName());
    SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
            this.getEventId(serviceId, method.getName()), false);
    throw new AuthorityException(SysMessageUtil.get(GreenStepSysMsgConstants.NO_PERMISSION));
}

From source file:com.netsteadfast.greenstep.aspect.ServiceScriptExpressionProcessAspect.java

License:Apache License

@Around(AspectConstants.LOGIC_SERVICE_PACKAGE)
public Object logicServiceProcess(ProceedingJoinPoint pjp)
        throws AuthorityException, ServiceException, Throwable {
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    if (annotations == null || annotations.length < 1) {
        return pjp.proceed();
    }/*ww  w. ja v  a2s . com*/
    String beanId = AspectConstants.getServiceId(annotations);

    /**
     * Hession proxy ?,  remote-server ?, client??, ???, remote-server, client
     */
    if (GreenStepHessianUtils.isEnableCallRemote() && GreenStepHessianUtils.isProxyServiceId(beanId)) {
        return pjp.proceed();
    }

    if (StringUtils.isBlank(beanId)) {
        return pjp.proceed();
    }
    if (!ServiceScriptExpressionUtils.needProcess(beanId, signature.getMethod().getName(),
            Constants.getSystem())) {
        return pjp.proceed();
    }
    Method method = signature.getMethod();
    ServiceScriptExpressionUtils.processBefore(beanId, signature.getMethod(), Constants.getSystem(), pjp);
    Object obj = pjp.proceed();
    ServiceScriptExpressionUtils.processAfter(beanId, method, Constants.getSystem(), obj, pjp);
    return obj;
}

From source file:com.netsteadfast.greenstep.service.aspect.ServiceAuthorityCheckAspect.java

License:Apache License

@Around(ServiceAspectConstants.AROUND_VALUE)
public Object aroundMethod(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {

    MethodSignature signature = (MethodSignature) pjp.getSignature();
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    String serviceId = this.getServiceId(annotations);
    Subject subject = SecurityUtils.getSubject();
    Method method = signature.getMethod();
    if (subject.hasRole(Constants.SUPER_ROLE_ALL) || subject.hasRole(Constants.SUPER_ROLE_ADMIN)) {
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }/*from w ww  .  j  a va 2 s .c  o  m*/
    if (StringUtils.isBlank(serviceId)) { //  service id  
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    if (!this.isServiceAuthorityCheck(annotations)) { //  ServiceAuthority  check=false ? 
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    Annotation[] methodAnnotations = method.getAnnotations();
    if (this.isServiceMethodAuthority(serviceId, methodAnnotations, subject)) {
        SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
                this.getEventId(serviceId, method.getName()), true);
        return pjp.proceed();
    }
    logger.warn("[decline] user[" + subject.getPrincipal() + "] " + pjp.getTarget().getClass().getName() + " - "
            + signature.getMethod().getName());
    SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(),
            this.getEventId(serviceId, method.getName()), false);
    throw new AuthorityException(SysMessageUtil.get(GreenStepSysMsgConstants.NO_PERMISSION));
}

From source file:com.netsteadfast.greenstep.service.aspect.ServiceScriptExpressionProcessAspect.java

License:Apache License

@Around(ServiceAspectConstants.AROUND_VALUE)
public Object aroundMethod(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
    Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    if (annotations == null || annotations.length < 1) {
        return pjp.proceed();
    }//from  www.j  av a  2  s  . co m
    String beanId = "";
    for (int i = 0; i < annotations.length; i++) {
        if (annotations[i] instanceof Service) {
            beanId = ((Service) annotations[i]).value();
        }
    }
    if (StringUtils.isBlank(beanId)) {
        return pjp.proceed();
    }
    if (!ServiceScriptExpressionUtils.needProcess(beanId, signature.getMethod().getName(),
            Constants.getSystem())) {
        return pjp.proceed();
    }
    Method method = signature.getMethod();
    ServiceScriptExpressionUtils.processBefore(beanId, signature.getMethod(), Constants.getSystem(), pjp);
    Object obj = pjp.proceed();
    ServiceScriptExpressionUtils.processAfter(beanId, method, Constants.getSystem(), obj, pjp);
    return obj;
}

From source file:com.newtranx.util.monitoring.MonitorAspect.java

License:Apache License

private static Method getMethod(MethodSignature signature, ProceedingJoinPoint pjp) {
    Method method = signature.getMethod();
    if (method.getDeclaringClass().isInterface()) {
        try {/*from ww w  .  ja  v a2 s.  c o m*/
            method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(),
                    method.getParameterTypes());
        } catch (NoSuchMethodException | SecurityException e) {
            throw new RuntimeException(e);
        }
    }
    return method;
}

From source file:com.onboard.service.activity.impl.ActivityRecorderImpl.java

License:Apache License

@Override
public Object deleteActivity(ProceedingJoinPoint joinpoint) {
    Object returnVal = null;//from   w  w  w .  ja va 2s  .co m
    String modelType = null;

    Class<?>[] serviceTypes = joinpoint.getTarget().getClass().getInterfaces();
    for (Class<?> clazz : serviceTypes) {
        if (service2ModelMap.get(clazz.getName()) != null) {
            modelType = service2ModelMap.get(clazz.getName());
            break;
        }
    }

    if (modelType != null) {
        Activity activity = new Activity();
        activity.setAttachType(modelType);
        activity.setAttachId((Integer) joinpoint.getArgs()[0]);
        activityMapper.deleteByExample(new ActivityExample(activity));
        /**
         * TODO delete notifications which reference the activity
         */
    }

    try {
        returnVal = joinpoint.proceed();
    } catch (Throwable e) {
        logger.error("fail to delete item: ", e);
    }

    return returnVal;
}