org.aspectj.lang.annotation.After Java Examples

The following examples show how to use org.aspectj.lang.annotation.After. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ControllerAOP.java    From layui-admin with MIT License 6 votes vote down vote up
/**
 * 应用日志存储
 * */
@After("operLogCut() && @annotation(operLog)")
public void logAdvisor(BizOperLog operLog){
	log.info("进入操作日志切面");
	// 添加记录日志
	HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

	UserTest user = (UserTest)SecurityUtils.getSubject().getPrincipal();
	String userid = user.getId();// 操作员ID
	String loginName = user.getLoginName();
	String ipAddr = IPUtil.getIpAddr(request);// 访问段ip

	//从注解中获取操作类型和备注
	String opertype =  operLog.operType().getValue();
	String memo = operLog.memo();
	sysOperLogServiceImpl.insertOperLog(userid,loginName,ipAddr,opertype,memo);
	log.info("记录操作日志成功");
}
 
Example #2
Source File: AbstractAspect.java    From kieker with Apache License 2.0 6 votes vote down vote up
@After("monitoredOperation() && notWithinKieker()")
public void afterOperation(final StaticPart jpStaticPart) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}

	final String operationSignature = this.signatureToLongString(jpStaticPart.getSignature());
	if (!CTRLINST.isProbeActivated(operationSignature)) {
		return;
	}

	final int stackIndex = this.currentStackIndex.get().decrementValue();
	if (stackIndex == 1) {
		TRACEREGISTRY.unregisterTrace();
	}
}
 
Example #3
Source File: FreemarkerSharedVariableMonitorAspects.java    From OneBlog with GNU General Public License v3.0 6 votes vote down vote up
@After("pointcut()")
public void after(JoinPoint joinPoint) {
    Map config = configService.getConfigs();
    if (null == config) {
        log.error("config为空");
        return;
    }
    Long updateTime = ((Date) config.get(ConfigKeyEnum.UPDATE_TIME.getKey())).getTime();
    if (updateTime == configLastUpdateTime) {
        log.debug("config表未更新");
        return;
    }
    log.debug("config表已更新,重新加载config到shared variable");
    configLastUpdateTime = updateTime;
    try {
        configuration.setSharedVariable("config", config);
    } catch (TemplateModelException e) {
        e.printStackTrace();
    }
}
 
Example #4
Source File: ElasticSearchPlugin.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@After("co.yiiu.pybbs.hook.IndexedServiceHook.indexTopic()")
public void indexTopic(JoinPoint joinPoint) {
    if (elasticSearchService.instance() != null) {
        Object[] args = joinPoint.getArgs();
        Map<String, Object> source = new HashMap<>();
        source.put("title", args[1]);
        source.put("content", args[2]);
        elasticSearchService.createDocument("topic", (String) args[0], source);
    }
}
 
Example #5
Source File: LoggerAspect.java    From Goku.Framework.CoreUI with MIT License 5 votes vote down vote up
@After("execution(* com.goku.coreui.**.controller..*.*(..))")
public void After(JoinPoint point){
    Object target = point.getTarget();
    //this.logger.info(target.toString());
    String method = point.getSignature().getName();
    //this.logger.info(method);
    Class<?>[] classz = target.getClass().getInterfaces();
    Class<?>[] parameterTypes = ((MethodSignature) point.getSignature())
            .getMethod().getParameterTypes();
    try {
        Method m = classz[0].getMethod(method, parameterTypes);
        if (m != null && m.isAnnotationPresent(LoggerInfo.class)) {
            LoggerInfo loggerinfo = m.getAnnotation(LoggerInfo.class);
            Subject subject = SecurityUtils.getSubject();
            //this.logger.info("oper:"+loggerinfo.Name()+"|"+"method"+ loggerinfo.Method());
            SysLog syslog=new SysLog();
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            syslog.setId(uuid);
            syslog.setUsername((String) subject.getPrincipal());
            syslog.setIp(subject.getSession().getHost());
            syslog.setOperation(loggerinfo.Name());
            syslog.setMethod(loggerinfo.Method());
            syslog.setParams(JSON.toJSONString (point.getArgs()));
            syslog.setCreateDate(new Date());
            syslogmapper.insert(syslog);
        }

    } catch (Exception e) {
       // e.printStackTrace();
    }
}
 
Example #6
Source File: AfterAdvice.java    From Spring with Apache License 2.0 5 votes vote down vote up
@After("execution(* *(..))")
public void exiting(JoinPoint joinPoint) {
	afterCalled = true;
	log.info("exiting " + joinPoint.getSignature());
	for (Object arg : joinPoint.getArgs()) {
		log.info("Arg : " + arg);
	}
}
 
Example #7
Source File: RepositoryAspect.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
@After("execution(* org.bonitasoft.web.designer.repository.Repository+.updateLastUpdateAndSave(..)) ")
public void postSaveAndUpdateDate(JoinPoint joinPoint) {
    try {
        handler.postSave(filePath(joinPoint));
    } catch (ResourceNotFoundException e) {
        throw new RepositoryException("An error occured while proceeding post save action.", e);
    }
}
 
Example #8
Source File: SynchronizedAspect.java    From kieker with Apache License 2.0 5 votes vote down vote up
@After("lock() && args(lock) && notWithinKieker()")
public final void afterMonitorEntry(final Object lock) {
	if (!CTRLINST.isMonitoringEnabled()) {
		return;
	}
	final TraceMetadata trace = TRACEREGISTRY.getTrace();
	if (trace != null) { // ignore monitorEntry if not inside of a trace!
		final long traceId = trace.getTraceId();
		final int orderId = trace.getNextOrderId();
		CTRLINST.newMonitoringRecord(new MonitorEntryEvent(TIME.getTime(), traceId, orderId, System.identityHashCode(lock)));
	}
}
 
Example #9
Source File: Interceptor.java    From Mykit with Apache License 2.0 5 votes vote down vote up
@After("aspect()")
public void doAfter(JoinPoint joinPoint) {
    System.out.println("===========执行后置通知==============");
    if(log.isInfoEnabled()){
        log.info("after " + joinPoint);
    }
}
 
Example #10
Source File: LoginLogAspect.java    From Shiro-Action with MIT License 5 votes vote down vote up
@After("loginLogPointCut()")
public void recordLoginLog(JoinPoint joinPoint) {
    // 获取登陆参数
    Object[] args = joinPoint.getArgs();
    User user = (User) args[0];

    Subject subject = SecurityUtils.getSubject();

    String ip = IPUtils.getIpAddr();
    loginLogService.addLog(user.getUsername(), subject.isAuthenticated(), ip);
}
 
Example #11
Source File: AbstractAspectJAdvisorFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Find and return the first AspectJ annotation on the given method
 * (there <i>should</i> only be one anyway...)
 */
@SuppressWarnings("unchecked")
protected static AspectJAnnotation<?> findAspectJAnnotationOnMethod(Method method) {
	Class<?>[] classesToLookFor = new Class<?>[] {
			Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class};
	for (Class<?> c : classesToLookFor) {
		AspectJAnnotation<?> foundAnnotation = findAnnotation(method, (Class<Annotation>) c);
		if (foundAnnotation != null) {
			return foundAnnotation;
		}
	}
	return null;
}
 
Example #12
Source File: RedisCachePlugin.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@After("co.yiiu.pybbs.hook.UserServiceHook.delRedisUser()")
public void userDelRedisUser(JoinPoint joinPoint) {
  User user = (User) joinPoint.getArgs()[0];
  redisService.delString(String.format(RedisKeys.REDIS_USER_ID_KEY, user.getId()));
  redisService.delString(String.format(RedisKeys.REDIS_USER_USERNAME_KEY, user.getUsername()));
  redisService.delString(String.format(RedisKeys.REDIS_USER_TOKEN_KEY, user.getToken()));
  redisService.delString(String.format(RedisKeys.REDIS_USER_MOBILE_KEY, user.getMobile()));
  redisService.delString(String.format(RedisKeys.REDIS_USER_EMAIL_KEY, user.getEmail()));
}
 
Example #13
Source File: WebLogAspect.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 授权修改之后调用
 * 
 * @author 梦境迷离.
 * @time 上午9:32:02
 * @version V1.0
 *
 */
@After(value = "shiroAop()")
public void afterGrant(JoinPoint point) {
	int id = (int) point.getArgs()[0];
	log.info("第一个参数是用户id:{}", id);
	RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
	MyRealm realm = (MyRealm) rsm.getRealms().iterator().next();
	realm.clearCachedAuthorization(id);
}
 
Example #14
Source File: WebLogAspect.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 使用@After在切入点结尾处切入内容
 * 
 * @author 梦境迷离
 * @time 下午4:37:17.
 */
@After(value = "webLog()")
public void doAfter(JoinPoint joinPoint) {
	// 处理完请求,返回内容
	log.info("FINISH : " + joinPoint.getClass());

}
 
Example #15
Source File: NamespaceUnlockAspect.java    From apollo with Apache License 2.0 5 votes vote down vote up
@After("@annotation(PreAcquireNamespaceLock) && args(itemId, operator, ..)")
public void requireLockAdvice(long itemId, String operator) {
  Item item = itemService.findOne(itemId);
  if (item == null) {
    throw new BadRequestException("item not exist.");
  }
  tryUnlock(namespaceService.findOne(item.getNamespaceId()));
}
 
Example #16
Source File: ViewClickedEventAspect.java    From Tracker with MIT License 5 votes vote down vote up
@After("execution(* android.view.View.OnClickListener.onClick(android.view.View))")
public void viewClicked(final ProceedingJoinPoint joinPoint) {
	/**
	 * 保存点击事件
	 */
	Context context = getContext(joinPoint.getThis());
	try {
		joinPoint.proceed();
	} catch (Throwable e) {
		e.printStackTrace(System.err);
	}
}
 
Example #17
Source File: CheckExecutingAspect.java    From biliob_backend with MIT License 5 votes vote down vote up
@After("checkExecuting()")
public void doAfter(JoinPoint jp) {
    String methodName = jp.getSignature().getName();
    if (executing.remove(methodName)) {
        logger.debug("[END] {} {}", methodName, Thread.currentThread());
    }
}
 
Example #18
Source File: ElasticSearchPlugin.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@After("co.yiiu.pybbs.hook.IndexedServiceHook.batchDeleteIndex()")
public void batchDeleteIndex(JoinPoint joinPoint) {
    if (elasticSearchService.instance() != null) {
        List<Topic> topics = topicMapper.selectList(null);
        List<Integer> ids = topics.stream().map(Topic::getId).collect(Collectors.toList());
        elasticSearchService.bulkDeleteDocument("topic", ids);
    }
}
 
Example #19
Source File: ReplaceAbleAspect.java    From Surgeon with Apache License 2.0 5 votes vote down vote up
@After("method()")
public void afterIfNeeded(JoinPoint jPoint) throws Throwable {
    String[] pair = parseNamespaceAndMethodName(jPoint);
    String namespace = pair[0];
    String function = pair[1];

    //invoke after function
    MasterFinder.getInstance().findAndInvoke(namespace, AFTER, function, jPoint.getThis(), jPoint.getArgs());
}
 
Example #20
Source File: ElasticSearchPlugin.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@After("co.yiiu.pybbs.hook.IndexedServiceHook.indexAllTopic()")
public void indexAllTopic() {
    if (elasticSearchService.instance() != null) {
        List<Topic> topics = topicMapper.selectList(null);
        Map<String, Map<String, Object>> sources = topics.stream().collect(Collectors.toMap(key -> String.valueOf(key
                .getId()), value -> {
            Map<String, Object> map = new HashMap<>();
            map.put("title", value.getTitle());
            map.put("content", value.getContent());
            return map;
        }));
        elasticSearchService.bulkDocument("topic", sources);
    }
}
 
Example #21
Source File: AllureAspectJ.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@After("anyAssertCreation()")
public void logAssertCreation(final JoinPoint joinPoint) {
    final String actual = joinPoint.getArgs().length > 0
            ? ObjectUtils.toString(joinPoint.getArgs()[0])
            : "<?>";
    final String uuid = UUID.randomUUID().toString();
    final String name = String.format("assertThat \'%s\'", actual);

    final StepResult result = new StepResult()
            .setName(name)
            .setStatus(Status.PASSED);

    getLifecycle().startStep(uuid, result);
    getLifecycle().stopStep(uuid);
}
 
Example #22
Source File: AbstractAspectJAdvisorFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find and return the first AspectJ annotation on the given method
 * (there <i>should</i> only be one anyway...)
 */
@SuppressWarnings("unchecked")
protected static AspectJAnnotation<?> findAspectJAnnotationOnMethod(Method method) {
	Class<?>[] classesToLookFor = new Class<?>[] {
			Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class};
	for (Class<?> c : classesToLookFor) {
		AspectJAnnotation<?> foundAnnotation = findAnnotation(method, (Class<Annotation>) c);
		if (foundAnnotation != null) {
			return foundAnnotation;
		}
	}
	return null;
}
 
Example #23
Source File: DeepLinkServiceProcessor.java    From OkDeepLink with Apache License 2.0 5 votes vote down vote up
private MethodSpec generateInitMethod(List<AddressElement> addressElements) {

        CodeBlock.Builder initializer = CodeBlock.builder();
        for (AddressElement element : addressElements) {
            List<String> deepLinkPaths = element.getDeepLinkPaths();
            if (!element.isPathsEmpty()) {
                for (String deepLinkPath : deepLinkPaths) {
                    TypeMirror activityTypeMirror = element.getActivityTypeMirror();
                    TypeMirror supportTypeMirror = elements.getTypeElement(ACTIVITY).asType();
                    if (activityTypeMirror != null) {
                        if (!types.isSubtype(activityTypeMirror, supportTypeMirror)) {
                            logger.error(Activity.class.getName() + " only support class which extends " + ACTIVITY, element.getElement());
                        }
                    }
                    ClassName activityClassName = element.getActivityClassName();
                    if (activityClassName != null) {
                        initializer.add("$T.addAddress(new $T($S, $T.class));\n",
                                DEEP_LINK_CLIENT, DEEP_LINK_ENTRY, deepLinkPath, activityClassName);
                    }
                }
            }

        }
        MethodSpec.Builder initMethod = MethodSpec.methodBuilder("init")
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(AnnotationSpec.builder(After.class).addMember("value", "$S", "execution(* " + INIT_METHOD_NAME + ")").build())
                .addCode(initializer.build());

        return initMethod.build();
    }
 
Example #24
Source File: RedisCachePlugin.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@After("co.yiiu.pybbs.hook.UserServiceHook.delRedisUser()")
public void userDelRedisUser(JoinPoint joinPoint) {
    User user = (User) joinPoint.getArgs()[0];
    redisService.delString(String.format(RedisKeys.REDIS_USER_ID_KEY, user.getId()));
    redisService.delString(String.format(RedisKeys.REDIS_USER_USERNAME_KEY, user.getUsername()));
    redisService.delString(String.format(RedisKeys.REDIS_USER_TOKEN_KEY, user.getToken()));
    redisService.delString(String.format(RedisKeys.REDIS_USER_MOBILE_KEY, user.getMobile()));
    redisService.delString(String.format(RedisKeys.REDIS_USER_EMAIL_KEY, user.getEmail()));
}
 
Example #25
Source File: ActivityAspect.java    From AspectJX-Demo with Apache License 2.0 4 votes vote down vote up
@After("call(* com.hujiang.library.demo.AspectJavaDemo.work())")
public void aspectJavaDemoAdvice(JoinPoint joinPoint) throws Throwable {
    Log.i("helloAOP", "aspect:::" + joinPoint.getSignature());
}
 
Example #26
Source File: ElasticSearchPlugin.java    From pybbs with GNU Affero General Public License v3.0 4 votes vote down vote up
@After("co.yiiu.pybbs.hook.IndexedServiceHook.deleteTopicIndex()")
public void deleteTopicIndex(JoinPoint joinPoint) {
    if (elasticSearchService.instance() != null) {
        elasticSearchService.deleteDocument("topic", (String) joinPoint.getArgs()[0]);
    }
}
 
Example #27
Source File: DataSupplierAspect.java    From test-data-supplier with Apache License 2.0 4 votes vote down vote up
@After("execution(@org.testng.annotations.DataProvider * io.github.sskorol.core.DataProviderTransformer.*(..))")
public void afterDataProviderCall(final JoinPoint joinPoint) {
    DATA_SUPPLIERS.forEach(ds -> ds.afterDataPreparation((ITestContext) joinPoint.getArgs()[0],
            (ITestNGMethod) joinPoint.getArgs()[1]));
}
 
Example #28
Source File: NamespaceUnlockAspect.java    From apollo with Apache License 2.0 4 votes vote down vote up
@After("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, itemId, item, ..)")
public void requireLockAdvice(String appId, String clusterName, String namespaceName, long itemId,
                              ItemDTO item) {
  tryUnlock(namespaceService.findOne(appId, clusterName, namespaceName));
}
 
Example #29
Source File: ActivityAspect.java    From AspectJX-Demo with Apache License 2.0 4 votes vote down vote up
@After("execution(* android.support.v4.app.Fragment.on**(..))")
public void fragmentMethod(JoinPoint joinPoint) throws Throwable {
    Log.i("helloAOP", "aspect:::" + joinPoint.getSignature());
}
 
Example #30
Source File: ActivityAspect.java    From AspectJX-Demo with Apache License 2.0 4 votes vote down vote up
@After("execution(* com.hujiang.library.demo.Greeter.**())")
public void greeterAdvice(JoinPoint joinPoint) throws Throwable {
    Log.i("helloAOP", "aspect:::" + joinPoint.getSignature());
}