List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:$.BizAspect.java
License:Open Source License
/** * ./* w ww . j a va 2s.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()); //Object o = jionpoint.proceed();//??? return o; }
From source file:$.CommonAspect.java
License:Open Source License
/** * ./*from ww w . j ava 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()); //Object o = jionpoint.proceed();//??? return o; }
From source file:$.CoreAspect.java
License:Open Source License
/** * .// w w w. j a va2s. c o m * * @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()); //Object o = jionpoint.proceed();//??? return o; }
From source file:au.id.wolfe.stormcloud.core.interceptor.DAOInterceptor.java
License:Apache License
@Around("execution(* au.id.wolfe.stormcloud.core.dao..*.*(..))") public Object logHibernateQueryTimes(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { final String targetClass = ClassUtils .getShortClassName(proceedingJoinPoint.getTarget().getClass().getName()); final String methodName = proceedingJoinPoint.getSignature().getName(); StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from w w w . j a v a 2 s . co m*/ Object retVal = proceedingJoinPoint.proceed(); stopWatch.stop(); StringBuilder sb = new StringBuilder(); sb.append(targetClass).append(" - ").append(methodName).append(": ").append(stopWatch.getTime()) .append(" ms"); log.debug(sb.toString()); return retVal; }
From source file:br.com.itw.commons.aop.OnSuccessAdvice.java
License:Apache License
@Around("execution(public * br.com.itw.qopsearch.api.**.*.*(..)) && @annotation(requestMapping)") public HttpEntity onSuccess(ProceedingJoinPoint pjp, RequestMapping requestMapping) throws Throwable { int length = requestMapping.method().length; if (length == 0) { throw new IllegalArgumentException(ERRO_SEM_METODO_DEFINIDO); }/* www . java 2 s . co m*/ boolean containsGet = Arrays.asList(requestMapping.method()).contains(RequestMethod.GET); if (containsGet && length > 1) { throw new IllegalArgumentException(ERRO_GET); } Object object = null; Object objectBody = null; HttpStatus httpStatus = HttpStatus.OK; String methodName = pjp.getSignature().getName(); if (!containsGet && !methodName.startsWith("find") && !methodName.startsWith("search")) { object = pjp.proceed(); HttpEntity httpEntity; ResponseEntity responseEntity; MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); String prefixCode = ON_SUCCESS + pjp.getTarget().getClass().getSimpleName() + "." + methodName; String titleCode = prefixCode + "." + TITLE; String messageCode = prefixCode + "." + MESSAGE; if (!pjp.getSignature().toString().startsWith("void")) { if (object instanceof ResponseEntity) { responseEntity = (ResponseEntity) object; httpStatus = responseEntity.getStatusCode(); objectBody = responseEntity.getBody(); } else if (object instanceof HttpEntity) { httpEntity = (HttpEntity) object; httpStatus = httpEntity == null ? HttpStatus.NO_CONTENT : HttpStatus.CREATED; if (HttpStatus.CREATED.equals(httpStatus)) objectBody = httpEntity.getBody(); } String title = messageSource.getMessage(titleCode, null, SUCESSO_TITLE, Locale.getDefault()); headers.add(TITLE, title); String sucessoDefault = messageSource.getMessage(SUCESSO_MSG, null, Locale.getDefault()); String message = messageSource.getMessage(messageCode, null, sucessoDefault, Locale.getDefault()); headers.add(MESSAGE, message); return new ResponseEntity(objectBody, headers, httpStatus); } else { //Mtodos do tipo void, no tem como fazer nada, o desenvolvedor decidiu retornar 200 return null; } } return httpGetEntity(pjp, objectBody, httpStatus); }
From source file:cn.com.esrichina.gcloud.commons.LicenseLevelCheckAspect.java
@Around("execution(* cn.com.esrichina.gcloud.*.web.resources.*.*(..))") public Object doCheck(ProceedingJoinPoint pjp) throws Throwable { Object target = pjp.getTarget(); String methodName = pjp.getSignature().getName(); Class[] parameterTypes = ((MethodSignature) pjp.getSignature()).getMethod().getParameterTypes(); Method method = target.getClass().getMethod(methodName, parameterTypes); LicenseLevelCheck licenseLevelCheck = null; if (method != null) { licenseLevelCheck = method.getAnnotation(LicenseLevelCheck.class); }/*w ww . ja v a 2s. co m*/ if (licenseLevelCheck == null) { try { return pjp.proceed(); } catch (Exception e) { throw e; } } else { String needLevel = licenseLevelCheck.level(); GCloudLicense license = LicenseContext.getInstance().getLicense(); // if (license == null || license.getLicenseLevel() == null) { // throw new // RuntimeException(Messages.getMessage("license_not_load")); // } if (needLevel.equals(GCloudLicense.LEVEL_ADVANCED) && !license.isAdvanced()) { throw new RuntimeException(Messages.getMessage("license_level_adv_limit")); } else if (needLevel.equals(GCloudLicense.LEVEL_STANDARD) && license.isBasic()) { throw new RuntimeException(Messages.getMessage("license_level_adv_limit")); } try { return pjp.proceed(); } catch (Exception e) { throw e; } } }
From source file:cn.com.xl.core.aop.BeforeAop.java
License:Apache License
@Around("cutBefore()") public Object doBefore(ProceedingJoinPoint point) throws Throwable { HttpServletRequest request = HttpKit.getRequest(); MethodSignature ms = (MethodSignature) point.getSignature(); Method method = ms.getMethod(); Object[] args = point.getArgs(); Class<?> clazz = point.getTarget().getClass(); Before before = method.getAnnotation(Before.class); Interceptor ic = before.value().newInstance(); Object result = ic.intercept(new Invocation(clazz, method, args, request)); if (null == result) { return point.proceed(); } else {/*from w ww . j a v a2 s . c om*/ return result; } }
From source file:com.alibaba.china.plugin.cache.spring.aop.CacheAopSupport.java
License:Open Source License
private Configuration retriveConfiguration(ProceedingJoinPoint joinPoint, Cached cached) { Configuration configuration = new Configuration(); configuration.setExpireTime(cached.expireTime()); configuration.setZip(cached.isZip()); configuration.setStrategy(cached.strategy()); configuration.setNamespace(cached.namespace()); configuration.setDefaultKey(cached.defaultKey()); configuration.setDefaultValue(cached.defaultValue()); Method method = (Method) joinPoint.getTarget(); try {//from ww w . j a v a2s . c o m Versioner versioner = getVersioner(method); configuration.setVersioner(versioner); KeyCoder keyCoder = getKeyCoder(method); configuration.setKeyCoder(keyCoder); ValueCoder valueCoder = getValueCoder(method); configuration.setValueCoder(valueCoder); } catch (Exception e) { throw new CacheException("", e); } return configuration; }
From source file:com.alibaba.china.plugin.cache.spring.aop.CacheAopSupport.java
License:Open Source License
private Object retriveKey(ProceedingJoinPoint joinPoint) { Method method = (Method) joinPoint.getTarget(); method.getAnnotation(VersionedBy.class); Object[] args = joinPoint.getArgs(); if (args == null || args.length == 0) { return null; }/* w w w. j ava2 s.co m*/ Annotation[][] paramAnnotations = method.getParameterAnnotations(); List<Object> keyList = new ArrayList<Object>(); for (Annotation[] annos : paramAnnotations) { for (Annotation a : annos) { if (a instanceof Key) { Key keyAnno = (Key) a; int index = keyAnno.value(); if (index >= 0 && index < args.length) { keyList.add(args[index]); } } } } if (keyList.size() == 0) { return null; } else if (keyList.size() == 1) { return keyList.get(0); } return keyList.toArray(); }
From source file:com.alibaba.china.plugin.cache.spring.aop.CacheAopSupport.java
License:Open Source License
private Object retriveValue(ProceedingJoinPoint joinPoint) { Method method = (Method) joinPoint.getTarget(); method.getAnnotation(VersionedBy.class); Object[] args = joinPoint.getArgs(); if (args == null || args.length == 0) { return null; }/*from w ww .j a v a 2 s.c o m*/ Annotation[][] paramAnnotations = method.getParameterAnnotations(); List<Object> valueList = new ArrayList<Object>(); for (Annotation[] annos : paramAnnotations) { for (Annotation a : annos) { if (a instanceof Value) { Value valueAnno = (Value) a; int index = valueAnno.value(); if (index >= 0 && index < args.length) { valueList.add(args[index]); } } } } if (valueList.size() == 0) { return null; } else if (valueList.size() == 1) { return valueList.get(0); } return valueList.toArray(); }