List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:com.jeanchampemont.wtfdyum.security.SecurityAspect.java
License:Apache License
/** * Around method annotated with @Secured. * *//*from ww w . ja v a2 s . co m*/ @Around("execution(public * *(..)) && @annotation(secured)") public Object aroundSecuredMethod(final ProceedingJoinPoint pjp, final Secured secured) throws Throwable { log.trace("Secured method called: {}", pjp.getSignature()); if (!authenticationService.isAuthenticated()) { log.trace("Secured call not authorized, throwing SecurityException"); throw new SecurityException(); } log.trace("Secured call authorized"); return pjp.proceed(); }
From source file:com.jiwhiz.aop.logging.LoggingAspect.java
License:Apache License
@Around("loggingPoincut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { if (log.isDebugEnabled()) { log.debug("==> Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs())); }// w ww. j av a 2 s .co m try { Object result = joinPoint.proceed(); if (log.isDebugEnabled()) { log.debug("<== Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), result); } return result; } catch (IllegalArgumentException e) { log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); throw e; } }
From source file:com.jmhz.device.sys.aop.UserCacheAspect.java
License:Apache License
@Around(value = "userServicePointcut() && cacheablePointcut()") public Object cacheableAdvice(ProceedingJoinPoint pjp) throws Throwable { String methodName = pjp.getSignature().getName(); Object arg = pjp.getArgs().length >= 1 ? pjp.getArgs()[0] : null; String key = ""; boolean isIdKey = false; if ("findOne".equals(methodName)) { key = idKey(String.valueOf(arg)); isIdKey = true;/* w w w . j a va2 s . c o m*/ } else if ("findByUsername".equals(methodName)) { key = usernameKey((String) arg); } else if ("findByEmail".equals(methodName)) { key = telKey((String) arg); } User user = null; if (isIdKey == true) { user = get(key); } else { Long id = get(key); if (id != null) { key = idKey(String.valueOf(id)); user = get(key); } } //cache hit if (user != null) { log.debug("cacheName:{}, hit key:{}", cacheName, key); return user; } log.debug("cacheName:{}, miss key:{}", cacheName, key); //cache miss user = (User) pjp.proceed(); //put cache put(user); return user; }
From source file:com.jmmd.biz.shared.aspect.BizAspect.java
License:Open Source License
/** * ./*from w w w .j a va 2 s . co m*/ * * @param jionpoint * @return * @throws Throwable */ @Around("bizPointcut() && @annotation(aspectLogger)") public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable { /* * . */ long l1 = System.currentTimeMillis(); /* * ??. */ String desc = aspectLogger.value(); /* * ??. */ //boolean discover = aspectLogger.discover(); /* * ???. */ String targetMethodName = jionpoint.getSignature().getName(); /* * ???. */ String targetClassName = jionpoint.getTarget().getClass().getName(); /* * ?. */ Object o = jionpoint.proceed(); /* * ?. */ long l2 = System.currentTimeMillis(); /* * ?. */ StringBuilder aspectMessage = new StringBuilder(); aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName) .append(".").append(targetMethodName).append("),(").append((l2 - l1)).append("ms)") .append(",?()"); /* * . */ logger.info(aspectMessage.toString()); return o; }
From source file:com.jmmd.common.shared.aspect.CommonLogger.java
License:Open Source License
/** * ./*from ww w . j av a 2 s . c o m*/ * * @param jionpoint * @return * @throws Throwable */ @Around("commonPointcut() && @annotation(aspectLogger)") public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable { /* * . */ long l1 = System.currentTimeMillis(); /* * ??. */ String desc = aspectLogger.value(); /* * ???. */ String targetMethodName = jionpoint.getSignature().getName(); /* * ???. */ String targetClassName = jionpoint.getTarget().getClass().getName(); /* * ?. */ Object o = jionpoint.proceed(); /* * ?. */ long l2 = System.currentTimeMillis(); /* * ?. */ StringBuilder aspectMessage = new StringBuilder(); aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName) .append(".").append(targetMethodName).append("),(").append((l2 - l1)).append("ms)") .append(",?()"); /* * . */ logger.info(aspectMessage.toString()); return o; }
From source file:com.jmmd.core.shared.aspect.CoreAspect.java
License:Open Source License
/** * ./*from www. jav a 2s .c om*/ * * @param jionpoint * @return * @throws Throwable */ @Around("corePointcut() && @annotation(aspectLogger)") public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable { /* * . */ long l1 = System.currentTimeMillis(); /* * ??. */ String desc = aspectLogger.value(); /* * ???. */ String targetMethodName = jionpoint.getSignature().getName(); /* * ???. */ String targetClassName = jionpoint.getTarget().getClass().getName(); /* * ?. */ Object o = jionpoint.proceed(); /* * ?. */ long l2 = System.currentTimeMillis(); /* * ?. */ StringBuilder aspectMessage = new StringBuilder(); aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName) .append(".").append(targetMethodName).append("),(").append(l2 - l1).append("ms)") .append(",?()"); /* * . */ logger.info(aspectMessage.toString()); return o; }
From source file:com.job.lr.aop.LogAspect.java
License:Apache License
/** * ?? ProceedingJoinPoint ?. // www.j a v a 2 s.c o m * ??: 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 w w. ja 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.joken.base.spring.aop.CacheableAop.java
License:Open Source License
/** * ?key//from w w w . j a v a 2 s . c om * * @param pjp * * @param cache * * @return */ private String getCacheKey(ProceedingJoinPoint pjp, Cacheable cache) { Annotation[][] pas = ((MethodSignature) pjp.getSignature()).getMethod().getParameterAnnotations(); StringBuilder buf = new StringBuilder(); Object[] args = pjp.getArgs(); Object objVal; String val; BigDecimal expire; List<Object> params = new ArrayList<Object>(); for (int i = 0; i < pas.length; i++) { objVal = args[i]; if (objVal == null) { continue; } val = objVal.toString(); val = val.replaceAll(",", "-"); for (Annotation an : pas[i]) { if (an instanceof CacheKey) { if (buf.length() > 0) { buf.append(":"); } buf.append(val); params.add(val); break; } else if (an instanceof ExpireKey) {// ? try { expire = new BigDecimal(val); THREAD_CACHE_EXPIRE.set(expire.intValue()); } catch (Exception e) { } } } } if (StringUtils.isEmpty(cache.keyName())) { return buf.toString(); } if (cache.keyArray()) { return StringUtils.format(SystemGlobal.get(cache.keyName()), params.toArray(new Object[0])); } return StringUtils.format(SystemGlobal.get(cache.keyName()), buf.toString()); }
From source file:com.klistret.cmdb.aspect.crud.ElementIntegration.java
License:Open Source License
public Object transmit(ProceedingJoinPoint pjp) throws Throwable { try {// w w w . j a va 2s .c o m 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; } }