List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed() throws Throwable;
From source file:com.job.lr.aop.LogAspect.java
License:Apache License
/** * ?? ProceedingJoinPoint ?. /*from w ww.j a v a2 s.com*/ * ??: ProceedingJoinPoint ???. * , ? */ @Around("pointcutExpression()") public Object aroundMethod(ProceedingJoinPoint pjd) { Object result = null; String methodName = pjd.getSignature().getName(); try { //? System.out.println("The method " + methodName + " begins with " + Arrays.asList(pjd.getArgs())); // result = pjd.proceed(); // System.out.println("The method " + methodName + " ends with " + result); } catch (Throwable e) { // System.out.println("The method " + methodName + " occurs exception:" + e); throw new RuntimeException(e); } //? System.out.println("The method " + methodName + " ends"); return result; }
From source file:com.joken.base.spring.aop.CacheableAop.java
License:Open Source License
/** * AOP?//from w ww . j a v a 2 s . c om * * @param pjp * ? * @param cache * * @return ? * @throws Throwable * @date 2015-10-10 ?8:29:11 */ @Around("@annotation(cache)") public Object cached(final ProceedingJoinPoint pjp, Cacheable cache) throws Throwable { THREAD_CACHE_EXPIRE.remove(); if (redisTemplate == null) { return pjp.proceed(); } // ??? String key = getCacheKey(pjp, cache); // ???? if (StringUtils.isEmpty(key)) { return pjp.proceed(); } logger.info("????" + key); // ? if (cache.handleMode() == CacheHandleMode.delete) { this.deleteCaceh(key, cache); return pjp.proceed(); } MethodSignature method = (MethodSignature) pjp.getSignature(); Class<?> clazz = method.getReturnType(); Object value; if (!(cache.handleMode() == CacheHandleMode.append)) { // ?? value = this.getCache(key, cache); if (value != null) { return this.castValue(clazz, value); } } // ,?? value = pjp.proceed(); // ?? if (value != null && cache.handleMode() != CacheHandleMode.nil) { // Object cacheValue = value; if (value instanceof ResponseModel) { cacheValue = ((ResponseModel) value).getData(); } // ?? if (cacheValue != null) { logger.info("??" + key); this.setCache(key, cacheValue, cache); } } return value; }
From source file:com.klistret.cmdb.aspect.crud.ElementIntegration.java
License:Open Source License
public Object transmit(ProceedingJoinPoint pjp) throws Throwable { try {//from www .ja va 2s . com Element element = (Element) pjp.proceed(); Signature signature = pjp.getSignature(); String name = signature.getName().toUpperCase(); Object[] args = pjp.getArgs(); if (name.equals("GET")) name = "READ"; try { SignatureMethod method = SignatureMethod.valueOf(name); switch (method) { case CREATE: case DELETE: case UPDATE: case READ: Element precedent = null; for (Object arg : args) if (arg instanceof Element) precedent = (Element) arg; logger.debug("Generating a message with CRUD function {} on element [id: {}, version: {}]", new Object[] { name, element.getId(), element.getVersion() }); Message<Element> message = MessageBuilder.withPayload(element).setHeader("function", name) .setHeader("precedent", precedent == null ? null : precedent.getVersion()).build(); channel.send(message); break; } } catch (IllegalArgumentException e) { logger.debug("Method {} is not trasmitted", name); } return element; } catch (HibernateOptimisticLockingFailureException e) { throw new ApplicationException("Stale element.", new StaleStateException(e.getMessage())); } catch (Exception e) { logger.error("Unknown exception: {}", e.getMessage()); throw e; } }
From source file:com.klistret.cmdb.aspect.crud.RelationIntegration.java
License:Open Source License
public Object transmit(ProceedingJoinPoint pjp) throws Throwable { try {//www .ja v a 2 s. c om Relation relation = (Relation) pjp.proceed(); Signature signature = pjp.getSignature(); String name = signature.getName().toUpperCase(); Object[] args = pjp.getArgs(); if (name.equals("GET")) name = "READ"; try { SignatureMethod method = SignatureMethod.valueOf(name); switch (method) { case CREATE: case DELETE: case UPDATE: case READ: Relation precedent = null; for (Object arg : args) if (arg instanceof Relation) precedent = (Relation) arg; logger.debug("Generating a message with CRUD function {} on relation [id: {}, version: {}]", new Object[] { name, relation.getId(), relation.getVersion() }); Message<Relation> message = MessageBuilder.withPayload(relation).setHeader("function", name) .setHeader("precedent", precedent == null ? null : precedent.getVersion()).build(); channel.send(message); break; } } catch (IllegalArgumentException e) { logger.debug("Method {} is not trasmitted", name); } return relation; } catch (HibernateOptimisticLockingFailureException e) { throw new ApplicationException("Stale relation.", new StaleStateException(e.getMessage())); } catch (Exception e) { logger.error("Unknown exception: {}", e.getMessage()); throw e; } }
From source file:com.klistret.cmdb.utility.spring.OptimisticLocking.java
License:Open Source License
public Object commitTransaction(ProceedingJoinPoint pjp) throws Throwable { try {//from w ww .j a v a2 s. c om return pjp.proceed(); } catch (HibernateOptimisticLockingFailureException e) { Signature signature = pjp.getSignature(); logger.error("Stale in declaration:{}, name: {}, long: {} message: {}", new Object[] { signature.getDeclaringTypeName(), signature.getName(), pjp.toLongString(), e.getMessage() }); throw new ApplicationException("Stale entity captured."); } }
From source file:com.liferay.portal.workflow.WorkflowLinkAdvice.java
License:Open Source License
public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Signature signature = proceedingJoinPoint.getSignature(); String methodName = signature.getName(); Object[] arguments = proceedingJoinPoint.getArgs(); if (methodName.equals(_UPDATE_ACTIVE)) { long companyId = (Long) arguments[0]; String name = (String) arguments[2]; int version = (Integer) arguments[3]; boolean active = (Boolean) arguments[4]; if (!active) { int workflowDefinitionLinksCount = WorkflowDefinitionLinkLocalServiceUtil .getWorkflowDefinitionLinksCount(companyId, name, version); if (workflowDefinitionLinksCount >= 1) { throw new RequiredWorkflowDefinitionException(); }//from ww w .j ava 2s . co m } } return proceedingJoinPoint.proceed(); }
From source file:com.liferay.portal.workflow.WorkflowLockingAdvice.java
License:Open Source License
public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Signature signature = proceedingJoinPoint.getSignature(); String methodName = signature.getName(); Object[] arguments = proceedingJoinPoint.getArgs(); if (methodName.equals(_START_WORKFLOW_INSTANCE_METHOD_NAME)) { String workflowDefinitionName = (String) arguments[3]; Integer workflowDefinitionVersion = (Integer) arguments[4]; String className = WorkflowDefinition.class.getName(); String key = _encodeKey(workflowDefinitionName, workflowDefinitionVersion); if (LockLocalServiceUtil.isLocked(className, key)) { throw new WorkflowException("Workflow definition name " + workflowDefinitionName + " and version " + workflowDefinitionVersion + " is being undeployed"); }/*from ww w . ja va 2 s . co m*/ return proceedingJoinPoint.proceed(); } else if (!methodName.equals(_UNDEPLOY_WORKFLOW_DEFINITION_METHOD_NAME)) { return proceedingJoinPoint.proceed(); } long userId = (Long) arguments[1]; String name = (String) arguments[2]; Integer version = (Integer) arguments[3]; String className = WorkflowDefinition.class.getName(); String key = _encodeKey(name, version); if (LockLocalServiceUtil.isLocked(className, key)) { throw new WorkflowException( "Workflow definition name " + name + " and version " + version + " is being undeployed"); } try { LockLocalServiceUtil.lock(userId, className, key, String.valueOf(userId), false, Time.HOUR); return proceedingJoinPoint.proceed(); } finally { LockLocalServiceUtil.unlock(className, key); } }
From source file:com.liferay.portal.workflow.WorkflowPermissionAdvice.java
License:Open Source License
public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Signature signature = proceedingJoinPoint.getSignature(); String methodName = signature.getName(); Object[] arguments = proceedingJoinPoint.getArgs(); if (methodName.equals(_ASSIGN_WORKFLOW_TASK_TO_USER_METHOD_NAME)) { long userId = (Long) arguments[1]; PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); if (permissionChecker.getUserId() != userId) { throw new PrincipalException(); }//w w w . j a v a2s . co m } return proceedingJoinPoint.proceed(); }
From source file:com.loadtesting.showcase.springmvc.aop.CapturingAspect.java
License:Apache License
@Around("execution(* *(..)) && @annotation(measuredHere)") public Object around(ProceedingJoinPoint point, MeasuredHere measuredHere) throws Throwable { String capturerName = measuredHere.name(); StatisticsCapturer capturer = ConcurrentHandler.getSingletonInstance().getStatisticsCapturer(capturerName); synchronized (obj) { capturer.startCapture();//from w w w. ja v a 2 s . c o m } boolean hasError = true; try { Object result = point.proceed(); hasError = false; return result; } catch (Throwable th) { throw th; } finally { if (hasError) { synchronized (obj) { capturer.endCaptureWithError(); } } else { synchronized (obj) { capturer.endCapture(); } } } }
From source file:com.lushapp.core.aop.LogAspect.java
License:Apache License
/** * @param point //from ww w . ja va 2s . co m */ @Around("execution(* com.lushapp.modules.*.service..*Manager.*(..))") public Object logAll(ProceedingJoinPoint point) throws Throwable { Object result = null; // ?? String methodName = point.getSignature().getName(); String className = point.getTarget().getClass().getSimpleName(); String userName = null; Long start = 0L; Long end = 0L; String ip = null; // ? try { // start = System.currentTimeMillis(); result = point.proceed(); end = System.currentTimeMillis(); // ?? SessionInfo sessionInfo = null; try { sessionInfo = SecurityUtils.getCurrentSessionInfo(); } catch (Exception e) { logger.error(e.getMessage()); } if (sessionInfo != null) { userName = sessionInfo.getLoginName(); ip = sessionInfo.getIp(); } else { userName = ""; ip = "127.0.0.1"; logger.warn("sessionInfo."); } } catch (Throwable e) { logger.error(e.getMessage(), e); throw e; } String name = null; // ? if (className.indexOf("Resource") > -1) { name = "??"; } else if (className.indexOf("Role") > -1) { name = "?"; } else if (className.indexOf("User") > -1) { name = "?"; } else if (className.indexOf("Organ") > -1) { name = "?"; } else { name = className; } // ? String opertype = methodName; if (StringUtils.isNotBlank(opertype) && (opertype.indexOf("save") > -1 || opertype.indexOf("update") > -1 || opertype.indexOf("delete") > -1 || opertype.indexOf("merge") > -1)) { Long time = end - start; Log log = new Log(); log.setType(LogType.operate.getValue()); log.setLoginName(userName); log.setModule(name); log.setAction(opertype); log.setOperTime(new Date(start)); log.setActionTime(time.toString()); log.setIp(ip); BrowserType browserType = BrowserUtils.getBrowserType(SpringMVCHolder.getRequest()); log.setBrowserType(browserType == null ? null : browserType.toString()); defaultEntityManager.save(log); } if (logger.isDebugEnabled()) { logger.debug(":{},?{},?{},{}ms.", new Object[] { userName, className, methodName, end - start }); } return result; }