List of usage examples for org.aspectj.lang.reflect MethodSignature getMethod
Method getMethod();
From source file:com.netsteadfast.greenstep.aspect.ServiceScriptExpressionProcessAspect.java
License:Apache License
@Around(AspectConstants.LOGIC_SERVICE_PACKAGE) public Object logicServiceProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable { Annotation[] annotations = pjp.getTarget().getClass().getAnnotations(); MethodSignature signature = (MethodSignature) pjp.getSignature(); if (annotations == null || annotations.length < 1) { return pjp.proceed(); }// w ww .ja v a 2s.co m String beanId = AspectConstants.getServiceId(annotations); /** * Hession proxy ?, remote-server ?, client??, ???, remote-server, client */ if (GreenStepHessianUtils.isEnableCallRemote() && GreenStepHessianUtils.isProxyServiceId(beanId)) { return pjp.proceed(); } if (StringUtils.isBlank(beanId)) { return pjp.proceed(); } if (!ServiceScriptExpressionUtils.needProcess(beanId, signature.getMethod().getName(), Constants.getSystem())) { return pjp.proceed(); } Method method = signature.getMethod(); ServiceScriptExpressionUtils.processBefore(beanId, signature.getMethod(), Constants.getSystem(), pjp); Object obj = pjp.proceed(); ServiceScriptExpressionUtils.processAfter(beanId, method, Constants.getSystem(), obj, pjp); return obj; }
From source file:com.netsteadfast.greenstep.service.aspect.ServiceAuthorityCheckAspect.java
License:Apache License
@Around(ServiceAspectConstants.AROUND_VALUE) public Object aroundMethod(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable { MethodSignature signature = (MethodSignature) pjp.getSignature(); Annotation[] annotations = pjp.getTarget().getClass().getAnnotations(); String serviceId = this.getServiceId(annotations); Subject subject = SecurityUtils.getSubject(); Method method = signature.getMethod(); if (subject.hasRole(Constants.SUPER_ROLE_ALL) || subject.hasRole(Constants.SUPER_ROLE_ADMIN)) { SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(), this.getEventId(serviceId, method.getName()), true); return pjp.proceed(); }/*from w w w. jav a 2s . co m*/ if (StringUtils.isBlank(serviceId)) { // service id SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(), this.getEventId(serviceId, method.getName()), true); return pjp.proceed(); } if (!this.isServiceAuthorityCheck(annotations)) { // ServiceAuthority check=false ? SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(), this.getEventId(serviceId, method.getName()), true); return pjp.proceed(); } Annotation[] methodAnnotations = method.getAnnotations(); if (this.isServiceMethodAuthority(serviceId, methodAnnotations, subject)) { SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(), this.getEventId(serviceId, method.getName()), true); return pjp.proceed(); } logger.warn("[decline] user[" + subject.getPrincipal() + "] " + pjp.getTarget().getClass().getName() + " - " + signature.getMethod().getName()); SysEventLogSupport.log((String) subject.getPrincipal(), Constants.getSystem(), this.getEventId(serviceId, method.getName()), false); throw new AuthorityException(SysMessageUtil.get(GreenStepSysMsgConstants.NO_PERMISSION)); }
From source file:com.netsteadfast.greenstep.service.aspect.ServiceScriptExpressionProcessAspect.java
License:Apache License
@Around(ServiceAspectConstants.AROUND_VALUE) public Object aroundMethod(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable { Annotation[] annotations = pjp.getTarget().getClass().getAnnotations(); MethodSignature signature = (MethodSignature) pjp.getSignature(); if (annotations == null || annotations.length < 1) { return pjp.proceed(); }//from www . j av a 2 s . c o m String beanId = ""; for (int i = 0; i < annotations.length; i++) { if (annotations[i] instanceof Service) { beanId = ((Service) annotations[i]).value(); } } if (StringUtils.isBlank(beanId)) { return pjp.proceed(); } if (!ServiceScriptExpressionUtils.needProcess(beanId, signature.getMethod().getName(), Constants.getSystem())) { return pjp.proceed(); } Method method = signature.getMethod(); ServiceScriptExpressionUtils.processBefore(beanId, signature.getMethod(), Constants.getSystem(), pjp); Object obj = pjp.proceed(); ServiceScriptExpressionUtils.processAfter(beanId, method, Constants.getSystem(), obj, pjp); return obj; }
From source file:com.newmainsoftech.spray.slingong.datastore.AnnotationTransactionOnStaticMethodAspect.java
License:Apache License
/** * AspectJ's {@link Before} advise to create new transaction before execution of either static * method annotated with @{@link Transactional} annotation or public static method in class * annotated with <code>@Transactional</code> annotation. <br /> * The body of advise is copy from before-advise of Spring's {@link AbstractTransactionAspect} aspect. * @param joinPoint/*from ww w. java2s .c o m*/ */ @SuppressAjWarnings("adviceDidNotMatch") @Before("pointcutAtExecutionOfStaticTransactionalMethod()") public void beforeAdvisedExecutionOfStaticTransactionalMethod(JoinPoint joinPoint) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Method method = methodSignature.getMethod(); TransactionInfo txInfo = createTransactionIfNecessary(method, joinPoint.getStaticPart().getClass()); }
From source file:com.newmainsoftech.spray.slingong.datastore.Slim3AnnotationTransactionAspectTest.java
License:Apache License
@org.aspectj.lang.annotation.After("Slim3AnnotationTransactionAspect.pointcutAtCallToNotReadOnlyMethodsOfGlobalTransaction()") public void afterCallToNotReadOnlyMethodsOfGlobalTransaction(JoinPoint joinPoint) { ++globalTransactionNotReadOnlyMethodCallCount; if (logger.isDebugEnabled()) { MethodSignature methodSignature = (MethodSignature) (joinPoint.getSignature()); logger.debug(String.format( "%1$s as not-read-only method is called. Advanced value of " + "globalTransactionNotReadOnlyMethodCallCount counter to %2$d.", methodSignature.getMethod().toString(), globalTransactionNotReadOnlyMethodCallCount)); }// w w w . ja v a2s .c o m }
From source file:com.newtranx.util.aop.AspectJUtils.java
License:Apache License
public static Method getMethod(JoinPoint joinPoint) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); if (method.getDeclaringClass().isInterface()) { try {/*from ww w.j a v a 2 s. c om*/ method = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(), method.getParameterTypes()); } catch (final SecurityException exception) { throw new RuntimeException(exception); } catch (final NoSuchMethodException exception) { throw new RuntimeException(exception); } } return method; }
From source file:com.newtranx.util.monitoring.MonitorAspect.java
License:Apache License
private static Method getMethod(MethodSignature signature, ProceedingJoinPoint pjp) { Method method = signature.getMethod(); if (method.getDeclaringClass().isInterface()) { try {//w w w . j av a2 s.c om method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(), method.getParameterTypes()); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException(e); } } return method; }
From source file:com.rockagen.gnext.service.spring.aspect.OpLogAspect.java
License:Apache License
/** * [Main] {@link Around}//w w w . j av a 2 s. c o m * @param pjp {@link ProceedingJoinPoint} * @return Object * @throws Throwable */ public Object around(ProceedingJoinPoint pjp) throws Throwable { Object obj = null; MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getMethod(); int result = 1; String message = ""; String action = getPlogValue(method); Date startAt = new Date(); try { // call target object method obj = pjp.proceed(); } catch (Exception e) { result = 0; message = e.getMessage(); throw e; } finally { register(action, startAt, result, message); } return obj; }
From source file:com.sccl.attech.common.advice.CustomJsonFilterAdvice.java
License:Open Source License
/** * Do around.//from www .j ava 2s .com * * @param pjp the pjp * @return the object * @throws Throwable the throwable */ @Around("execution(* com.sccl.attech.modules.template.web.*.*(..))") public Object doAround(ProceedingJoinPoint pjp) throws Throwable { MethodSignature msig = (MethodSignature) pjp.getSignature(); HttpServletResponse response = getResponse(pjp.getArgs()); CustomJsonFilter annotation = msig.getMethod().getAnnotation(CustomJsonFilter.class); CustomJsonFilters annotations = msig.getMethod().getAnnotation(CustomJsonFilters.class); if ((annotation == null && annotations == null) || null == response) { return pjp.proceed(); } JsonMapper mapper = new JsonMapper(); if (annotation != null) { Class<?> mixin = annotation.mixin(); Class<?> target = annotation.target(); if (target != null) { mapper.addMixInAnnotations(target, mixin); } else { mapper.addMixInAnnotations(msig.getMethod().getReturnType(), mixin); } } if (annotations != null) { CustomJsonFilter[] filters = annotations.filters(); for (CustomJsonFilter filter : filters) { Class<?> mixin = filter.mixin(); Class<?> target = filter.target(); if (target != null) { mapper.addMixInAnnotations(target, mixin); } else { mapper.addMixInAnnotations(msig.getMethod().getReturnType(), mixin); } } } try { // response.setCharacterEncoding("UTF-8"); mapper.writeValue(response.getOutputStream(), pjp.proceed()); return null; } catch (Exception ex) { throw new RuntimeException(ex); } // return null; }
From source file:com.smallchill.core.aop.BeforeAop.java
License:Apache License
@Around("cutBefore()") public Object doBefore(ProceedingJoinPoint point) throws Throwable { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest();// w w w . j a va 2 s. c om 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 { return result; } }