本文整理汇总了Java中org.aspectj.lang.annotation.AfterReturning类的典型用法代码示例。如果您正苦于以下问题:Java AfterReturning类的具体用法?Java AfterReturning怎么用?Java AfterReturning使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AfterReturning类属于org.aspectj.lang.annotation包,在下文中一共展示了AfterReturning类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterReturn
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
/**
* @param joinPoint
*/
@AfterReturning("logAnnoAspect()")
public void afterReturn(JoinPoint joinPoint) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
LogModify logModifyAnno = method.getAnnotation(LogModify.class);
if (null != logModifyAnno) {
BaseEntity entity = (BaseEntity) joinPoint.getArgs()[0];
Log log = new Log();
log.setUserId(((User) SecurityUtils.getSubject().getSession().getAttribute("curUser")).getId());
log.setAction(ACTION + logModifyAnno.resource());
log.setResource(entity.getLogResource());
log.setResourceId(entity.getId());
logService.insert(log);
}
}
示例2: afterReturn
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
/**
* @param joinPoint
*/
@AfterReturning("logAnnoAspect()")
public void afterReturn(JoinPoint joinPoint) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
LogDelete logDelete = method.getAnnotation(LogDelete.class);
if (null != logDelete) {
BaseEntity entity = (BaseEntity) joinPoint.getArgs()[0];
Log log = new Log();
log.setUserId(((User) SecurityUtils.getSubject().getSession().getAttribute("curUser")).getId());
log.setAction(Constants.LOG_ACTION_DELETE + logDelete.resource());
log.setResource(entity.getLogResource());
log.setResourceId(entity.getId());
logService.insert(log);
}
}
示例3: afterReturningServer
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning(pointcut = "execution(* cn.org.once.cstack.ServerService.create(..)) "
+ "|| execution(* cn.org.once.cstack.ServerService.updateType(..))", returning = "result")
public void afterReturningServer(StaticPart staticPart, Object result) throws MonitorException {
try {
if (result == null)
return;
Server server = (Server) result;
User user = server.getApplication().getUser();
Message message = null;
switch (staticPart.getSignature().getName().toUpperCase()) {
case createType:
message = MessageUtils.writeServerMessage(user, server, createType);
break;
case updateType:
message = MessageUtils.writeServerMessage(user, server, updateType);
break;
}
logger.info(message.toString());
messageService.create(message);
} catch (ServiceException e) {
throw new MonitorException("Error afterReturningApplication", e);
}
}
示例4: afterReturningFileExplorer
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning("execution(* cn.org.once.cstack.service.FileService.deleteFilesFromContainer(..))"
+ " || execution(* cn.org.once.cstack.service.FileService.sendFileToContainer(..))")
public void afterReturningFileExplorer(JoinPoint joinPoint) throws ServiceException {
Message message = new Message();
User user = getAuthentificatedUser();
message.setDate(new Date());
message.setType(Message.INFO);
message.setAuthor(user);
message.setApplicationName((String) joinPoint.getArgs()[0]);
switch (joinPoint.getSignature().getName().toUpperCase()) {
case "DELETEFILESFROMCONTAINER":
message.setEvent(user.getLogin() + " has removed this file : " + joinPoint.getArgs()[2]);
break;
}
this.messageService.create(message);
}
示例5: afterReturningDeployment
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning(pointcut = "execution(* cn.org.once.cstack.service.DeploymentService.create(..))", returning = "result")
public void afterReturningDeployment(StaticPart staticPart, Object result)
throws MonitorException {
try {
if (result == null)
return;
Deployment deployment = (Deployment) result;
User user = deployment.getApplication().getUser();
Message message = null;
switch (staticPart.getSignature().getName().toUpperCase()) {
case createType:
message = MessageUtils.writeDeploymentMessage(user, deployment,
createType);
break;
}
if (message != null) {
logger.info(message.toString());
messageService.create(message);
}
} catch (ServiceException e) {
throw new MonitorException("Error afterReturningApplication", e);
}
}
示例6: updateCache
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning ("@annotation(fr.gael.dhus.spring.cache.IncrementCache)")
public void updateCache (JoinPoint joinPoint)
{
IncrementCache annotation = ((MethodSignature) joinPoint.getSignature ())
.getMethod ().getAnnotation (IncrementCache.class);
Cache cache = getCacheManager().getCache(annotation.name());
if (cache != null)
{
synchronized (cache)
{
Integer old_value = cache.get (annotation.key (), Integer.class);
cache.clear ();
if (old_value == null)
{
return;
}
cache.put (annotation.key (), (old_value + annotation.value ()));
}
}
}
示例7: deleteServiceCallCalls
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
/**
* 管理员删除操作日志(后置通知)
*
*/
@AfterReturning(value = "deleteServiceCall()", argNames = "rtv", returning = "rtv")
public void deleteServiceCallCalls(JoinPoint joinPoint, Object rtv)
throws Throwable {
// 获取方法名
String methodName = joinPoint.getSignature().getName();
StringBuffer rs = new StringBuffer();
rs.append(methodName);
String className = null;
for (Object info : joinPoint.getArgs()) {
// 获取对象类型
className = info.getClass().getName();
className = className.substring(className.lastIndexOf(".") + 1);
rs.append("[参数1,类型:" + className + ",值:(id:"
+ joinPoint.getArgs()[0] + ")");
}
// 创建日志对象
LogInfoEntity log = new LogInfoEntity();
log.setUserId(ShiroAuthenticationManager.getUserId());// 用户编号
log.setAccountName(ShiroAuthenticationManager.getUserAccountName());
log.setCreateTime(new Date(System.currentTimeMillis()));// 操作时间
log.setContent(rs.toString());// 操作内容
log.setOperation("delete");// 操作
logService.log(log);// 添加日志
}
示例8: after
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
/**
* @param data
* @throws ClassNotFoundException
* @throws HttpMessageNotWritableException
* @throws IOException
*/
@AfterReturning(pointcut = "point()", returning = "data")
public void after(JoinPoint jp, Object data) throws Exception {
MethodInvocationProceedingJoinPoint joinPoint = (MethodInvocationProceedingJoinPoint) jp;
Class<?> clazz = joinPoint.getSignature().getDeclaringType();
if (AnnotationUtils.findAnnotation(clazz, FeignClient.class) == null) {
log.debug("未找到feign 客户端");
return;
}
CustomSecurityContext securityContext = SecurityContextHystrixRequestVariable.getInstance().get();
ErrorResult errorResult = null;
if (securityContext != null && (errorResult = securityContext.getErrorResult()) != null) {
if (errorResult.getHttpStatus() != HttpStatus.OK.value()) {
Class<?> exceptionClass = Class.forName(errorResult.getException());
Constructor<?> constructor = exceptionClass.getConstructor(new Class[]{String.class, String.class});
throw (CustomException) constructor
.newInstance(new Object[]{errorResult.getMessage(), errorResult.getCode()});
}
}
SecurityContextHystrixRequestVariable.getInstance().remove();
}
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:27,代码来源:DefaultFeignExceptionHandlerInterceptor.java
示例9: doAfterReturning
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning(returning = "ret", pointcut = "webLog()")
public void doAfterReturning(Object ret) {
// 处理完请求,返回内容
WebOosLog commLogger = commLoggerThreadLocal.get();
commLogger.setActionResCode(ResponseStatus.SUCCESS);
commLogger.setReqEndTime(new Date());
commLogger.setReqDealTime((int) (commLogger.getReqEndTime().getTime() - commLogger.getReqStartTime().getTime()));
commLogger.setResponseData(JSON.toJSONString(ret));
commLogger.setIsUndefinedException(false);
loggerRecordService.doRecord(commLogger);
logger.debug("RESPONSE : " + JSON.toJSONString(ret));
logger.debug("SPEND TIME : " + commLogger.getReqDealTime() + "ms");
logger.debug("***************请求" + commLogger.getActionDesc() + "结束***************");
}
示例10: afterCreate
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning(pointcut = "execution(* com.digirati.elucidate.repository.AnnotationStoreRepository.createAnnotation(..))", returning = "w3cAnnotation")
public void afterCreate(W3CAnnotation w3cAnnotation) {
for (RegisteredListener synchronousRegisteredListener : synchronousRegisteredListeners) {
LOGGER.info(String.format("Notifying synchronous listener [%s] of CREATE on W3CAnnotation [%s]", synchronousRegisteredListener, w3cAnnotation));
synchronousRegisteredListener.notifyCreate(w3cAnnotation);
LOGGER.info(String.format("Synchronous listener [%s] has finished processing CREATE on W3CAnnotation [%s]", synchronousRegisteredListener, w3cAnnotation));
}
for (RegisteredListener asynchronousRegisteredListener : asynchronousRegisteredListeners) {
taskExecutor.execute(() -> {
LOGGER.info(String.format("Notifying asynchronous listener [%s] of CREATE on W3CAnnotation [%s]", asynchronousRegisteredListener, w3cAnnotation));
asynchronousRegisteredListener.notifyCreate(w3cAnnotation);
LOGGER.info(String.format("Asynchronous listener [%s] has finished processing CREATE on W3CAnnotation [%s]", asynchronousRegisteredListener, w3cAnnotation));
});
}
}
示例11: afterUpdate
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning(pointcut = "execution(* com.digirati.elucidate.repository.AnnotationStoreRepository.updateAnnotation(..))", returning = "w3cAnnotation")
public void afterUpdate(W3CAnnotation w3cAnnotation) {
for (RegisteredListener synchronousRegisteredListener : synchronousRegisteredListeners) {
LOGGER.info(String.format("Notifying synchronous listener [%s] of UPDATE on W3CAnnotation [%s]", synchronousRegisteredListener, w3cAnnotation));
synchronousRegisteredListener.notifyUpdate(w3cAnnotation);
LOGGER.info(String.format("Synchronous listener [%s] has finished processing UPDATE on W3CAnnotation [%s]", synchronousRegisteredListener, w3cAnnotation));
}
for (RegisteredListener asynchronousRegisteredListener : asynchronousRegisteredListeners) {
taskExecutor.execute(() -> {
LOGGER.info(String.format("Notifying asynchronous listener [%s] of UPDATE on W3CAnnotation [%s]", asynchronousRegisteredListener, w3cAnnotation));
asynchronousRegisteredListener.notifyUpdate(w3cAnnotation);
LOGGER.info(String.format("Asynchronous listener [%s] has finished processing UPDATE on W3CAnnotation [%s]", asynchronousRegisteredListener, w3cAnnotation));
});
}
}
示例12: afterDelete
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning(pointcut = "execution(* com.digirati.elucidate.repository.AnnotationStoreRepository.deleteAnnotation(..))", returning = "w3cAnnotation")
public void afterDelete(W3CAnnotation w3cAnnotation) {
for (RegisteredListener synchronousRegisteredListener : synchronousRegisteredListeners) {
LOGGER.info(String.format("Notifying synchronous listener [%s] of DELETE on W3CAnnotation [%s]", synchronousRegisteredListener, w3cAnnotation));
synchronousRegisteredListener.notifyDelete(w3cAnnotation);
LOGGER.info(String.format("Synchronous listener [%s] has finished processing DELETE on W3CAnnotation [%s]", synchronousRegisteredListener, w3cAnnotation));
}
for (RegisteredListener asynchronousRegisteredListener : asynchronousRegisteredListeners) {
taskExecutor.execute(() -> {
LOGGER.info(String.format("Notifying asynchronous listener [%s] of DELETE on W3CAnnotation [%s]", asynchronousRegisteredListener, w3cAnnotation));
asynchronousRegisteredListener.notifyDelete(w3cAnnotation);
LOGGER.info(String.format("Asynchronous listener [%s] has finished processing DELETE on W3CAnnotation [%s]", asynchronousRegisteredListener, w3cAnnotation));
});
}
}
示例13: updateCache
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning ("@annotation(fr.gael.dhus.spring.cache.IncrementCache)")
public void updateCache (JoinPoint joinPoint)
{
IncrementCache annotation = ((MethodSignature) joinPoint.getSignature ())
.getMethod ().getAnnotation (IncrementCache.class);
Cache cache = cacheManager.getCache (annotation.name ());
if (cache != null)
{
synchronized (cache)
{
Integer old_value = cache.get (annotation.key (), Integer.class);
cache.clear ();
if (old_value == null)
{
return;
}
cache.put (annotation.key (), (old_value + annotation.value ()));
}
}
}
示例14: processViewName
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning(pointcut = "execution(* com.poseidon.*.*Controller..*(..)))", returning = "result")
public void processViewName(JoinPoint joinPoint, Object result) {
final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
ViewName annotation = method.getAnnotation(ViewName.class);
if(annotation == null){
return;
}
String errorView = annotation.errorView();
if(errorView!= null && !errorView.isEmpty()){
buildModelAndView(result, errorView);
return;
}
String name = annotation.name();
Class<?> returnType = method.getReturnType();
if(!returnType.isAssignableFrom(ModelAndView.class)){
throw new ViewNameException("Para usar a annotation @ViewName é preciso que o metodo retorne ModelAndView.");
}
buildModelAndView(result, name);
}
示例15: args
import org.aspectj.lang.annotation.AfterReturning; //导入依赖的package包/类
@AfterReturning("execution (* net.jforum.services.ModerationService.moveTopics(..)) && args(toForumId, log, topicIds)")
public void moveTopics(int toForumId, ModerationLog log, int... topicIds) {
if (!ArrayUtils.isEmpty(topicIds)) {
this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalPosts#" + toForumId));
this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalTopics#" + toForumId));
Cache cache = this.factoryImplementor.getSecondLevelCacheRegion("net.jforum.entities.Forum");
if (cache != null) {
cache.remove("net.jforum.entities.Forum#" + toForumId);
}
Topic topic = (Topic)this.sessionFactory.getCurrentSession().get(Topic.class, topicIds[0]);
Forum forum = topic.getForum();
this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalPosts#" + forum.getId()));
this.clearCacheRegion(this.factoryImplementor.getQueryCache("forumDAO.getTotalTopics#" + forum.getId()));
Cache cache2 = this.factoryImplementor.getSecondLevelCacheRegion("net.jforum.entities.Forum");
if (cache2 != null) {
cache2.remove("net.jforum.entities.Forum#" + forum.getId());
}
}
}