List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:com.netflix.genie.web.aspect.HealthCheckMetricsAspect.java
License:Apache License
/** * Intercept call to AbstractHealthIndicator beans loaded and publish a timer tagged with error, if any. * This interception is required because these beans are not captured by HealthIndicator.doHealthCheck(), * even tho they implement that interface. * * @param joinPoint joinPoint for the actual call to doHealthCheck() * @throws Throwable as thrown by joinPoint.proceed() *///from ww w . j a va 2 s . c om @Around("execution(" + " void org.springframework.boot.actuate.health.AbstractHealthIndicator.doHealthCheck(" + " org.springframework.boot.actuate.health.Health.Builder" + " )" + ")") @SuppressWarnings("checkstyle:IllegalThrows") // For propagating Throwable from joinPoint.proceed() public void abstractHealthIndicatorDoHealthCheckMonitor(final ProceedingJoinPoint joinPoint) throws Throwable { final long start = System.nanoTime(); Throwable throwable = null; try { joinPoint.proceed(joinPoint.getArgs()); } catch (final Throwable t) { throwable = t; throw t; } finally { final long turnaround = System.nanoTime() - start; recordHealthIndicatorTurnaround(turnaround, joinPoint, throwable); } }
From source file:com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCacheAspect.java
License:Apache License
@Around("cacheRemoveAnnotationPointcut()") public Object methodsAnnotatedWithCacheRemove(final ProceedingJoinPoint joinPoint) throws Throwable { Method method = getMethodFromTarget(joinPoint); Object obj = joinPoint.getTarget(); Object[] args = joinPoint.getArgs(); Validate.notNull(method, "failed to get method from joinPoint: %s", joinPoint); MetaHolder metaHolder = MetaHolder.builder().args(args).method(method).obj(obj) .executionType(ExecutionType.SYNCHRONOUS).build(); CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory .createCacheRemoveInvocationContext(metaHolder); HystrixRequestCacheManager.getInstance().clearCache(context); return joinPoint.proceed(); }
From source file:com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCollapserAspect.java
License:Apache License
@Around("hystrixCollapserAnnotationPointcut()") public Object methodsAnnotatedWithHystrixCommand(final ProceedingJoinPoint joinPoint) throws Throwable { HystrixCollapser hystrixCollapser;/*from www . j a v a 2 s . c o m*/ Method collapserMethod = getMethodFromTarget(joinPoint); Object obj = joinPoint.getTarget(); Object[] args = joinPoint.getArgs(); Validate.notNull(collapserMethod, "failed to get collapser method from joinPoint: %s", joinPoint); hystrixCollapser = collapserMethod.getAnnotation(HystrixCollapser.class); Method commandMethod = getMethodFromTarget(joinPoint, hystrixCollapser.commandMethod()); ExecutionType collapserExecutionType = ExecutionType.getExecutionType(collapserMethod.getReturnType()); ExecutionType commandExecutionType = ExecutionType.getExecutionType(commandMethod.getReturnType()); Closure closure = ClosureFactoryRegistry.getFactory(commandExecutionType).createClosure(commandMethod, obj, args); HystrixCommand hystrixCommand = commandMethod.getAnnotation(HystrixCommand.class); Validate.notNull(hystrixCommand, "collapser cannot refer to the '' method which wasn't annotated with @HystrixCommand"); MetaHolder metaHolder = MetaHolder.builder().args(args).method(commandMethod).obj(obj).closure(closure) .executionType(commandExecutionType).hystrixCollapser(hystrixCollapser) .hystrixCommand(hystrixCommand).defaultCommandKey(commandMethod.getName()) .defaultCollapserKey(collapserMethod.getName()).defaultGroupKey(obj.getClass().getSimpleName()) .build(); CommandCollapser commandCollapser = new CommandCollapser(metaHolder); return CommandExecutor.execute(commandCollapser, collapserExecutionType); }
From source file:com.netsteadfast.greenstep.aspect.HessianServiceProxyAspect.java
License:Apache License
private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable { MethodSignature signature = (MethodSignature) pjp.getSignature(); Annotation[] annotations = pjp.getTarget().getClass().getAnnotations(); String serviceId = AspectConstants.getServiceId(annotations); /**/* www . ja v a 2 s . c o m*/ * ???? service-bean */ if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) { //logger.info( "reject proxy service: " + serviceId ); return pjp.proceed(); } String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal()); if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) { /** * ???? service-bean */ if (StringUtils.isBlank(userId)) { logger.warn("no userId"); pjp.proceed(); } /** * ???? service-bean */ if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) { logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId); return pjp.proceed(); } } String serviceInterfacesName = ""; Class<?> serviceInterfaces[] = pjp.getTarget().getClass().getInterfaces(); for (Class<?> clazz : serviceInterfaces) { if (clazz.getName().indexOf(".service.") > -1) { serviceInterfacesName = clazz.getName(); } } if (StringUtils.isBlank(serviceInterfacesName)) { logger.error("error no service interface: " + serviceId); throw new Exception("error no service interface: " + serviceId); } String url = GreenStepHessianUtils.getServiceUrl(serviceId); String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/" + ApplicationSiteUtils.getContextPath(Constants.getSystem()); /** * ?????, ? HessianServiceProxyAspect ? (server-remote???) * http://127.0.0.1:8080/ * hessian.enable=Y ???, ?url hessian.serverUrl=http://127.0.0.1:8080/ * */ if (url.indexOf(theSystemPath) > -1) { logger.error("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url); throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url); } logger.info("proxy url = " + url); HessianProxyFactory factory = null; Object proxyServiceObject = null; if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) { // ?checkValue? factory = new GreenStepHessianProxyFactory(); ((GreenStepHessianProxyFactory) factory) .setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId)); proxyServiceObject = ((GreenStepHessianProxyFactory) factory) .createForHeaderMode(Class.forName(serviceInterfacesName), url); } else { // ?checkValue? factory = new HessianProxyFactory(); proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url); } Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods(); Method proxyObjectMethod = null; if (null == proxyObjectMethods) { logger.error("error no find proxy method: " + serviceId); throw new Exception("error no find proxy method: " + serviceId); } for (Method m : proxyObjectMethods) { if (m.getName().equals(signature.getMethod().getName()) && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) { proxyObjectMethod = m; } } if (null == proxyObjectMethod) { logger.error("error no execute proxy method: " + serviceId); throw new Exception("error no execute proxy method: " + serviceId); } Object resultObj = null; try { resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs()); this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs()); } catch (InvocationTargetException e) { if (e.getMessage() != null) { throw new ServiceException(e.getMessage().toString()); } if (e.getTargetException().getMessage() != null) { throw new ServiceException(e.getTargetException().getMessage().toString()); } throw e; } catch (Exception e) { logger.error(e.getMessage().toString()); throw e; } logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName()); return resultObj; }
From source file:com.netsteadfast.greenstep.util.ServiceScriptExpressionUtils.java
License:Apache License
private static Map<String, Object> getParameters(TbSysBeanHelpExpr beanHelpExpr, List<TbSysBeanHelpExprMap> beanHelpExprMaps, Object resultObj, ProceedingJoinPoint pjp) { Object[] args = pjp.getArgs(); Map<String, Object> dataMap = new HashMap<String, Object>(); for (TbSysBeanHelpExprMap map : beanHelpExprMaps) { Object value = null;/*from w ww . ja va 2 s.com*/ if (YesNo.YES.equals(map.getMethodResultFlag())) { value = resultObj; } else { for (int i = 0; args != null && i < args.length; i++) { if (args[i] != null && args[i].getClass() != null && args[i].getClass().getName().equals(map.getMethodParamClass()) && map.getMethodParamIndex() == i) { value = args[i]; } } } dataMap.put(map.getVarName(), value); } return dataMap; }
From source file:com.newmainsoftech.spray.slingong.datastore.testmodel.book.AuthorAspect.java
License:Apache License
@Around("createNewAuthorPointcut()") public void aroundCreateNewAuthor(ProceedingJoinPoint proceedingJoinPoint) { Object[] argsArray = proceedingJoinPoint.getArgs(); String name = (String) argsArray[0]; if ((name == null) || "".equals(name)) { String message = "".equals(name) ? "Value of name property of Author entity cannot be empty string." : "Value of name property of Author entity cannot be null."; if (logger.isErrorEnabled()) { logger.error(message);// w w w. j ava 2 s. co m } throw new RuntimeException(message); } try { proceedingJoinPoint.proceed(); } catch (Throwable throwable) { Throwable cause = throwable.getCause(); if (cause == null) { cause = throwable; } if (logger.isErrorEnabled()) { logger.error("Failure at Author.createNewAuthor method", cause); } throw new RuntimeException(cause); } }
From source file:com.newtranx.util.monitoring.MonitorAspect.java
License:Apache License
@Around("@annotation(com.newtranx.util.monitoring.Monitoring)") public Object around(final ProceedingJoinPoint pjp) throws Throwable { final MethodSignature signature = (MethodSignature) pjp.getSignature(); final Method method = getMethod(signature, pjp); final long begin = System.currentTimeMillis(); MonitorContext monitorContext = new MonitorContext() { @Override/*w ww .java 2s .c o m*/ public void doReport() { long end = System.currentTimeMillis(); String name = method.getAnnotation(Monitoring.class).value().trim(); Optional<String> optName = StringUtils.isEmpty(name) ? Optional.empty() : Optional.of(name); for (Reporter r : reporters) { try { r.report(method, end - begin, optName); } catch (Throwable t) { t.printStackTrace(System.err); } } } }; Object[] args = pjp.getArgs(); AsyncHandler asyncHandler = null; for (AsyncHandler a : getAsyncHandlers()) { Object[] processedArgs = a.preProcess(method, args, monitorContext); if (monitorContext.isAsync()) { args = processedArgs; asyncHandler = a; break; } } Object result = pjp.proceed(args); if (monitorContext.isAsync()) { return asyncHandler.postProcess(result, monitorContext); } else { monitorContext.doReport(); return result; } }
From source file:com.newtranx.util.mysql.fabric.SpringMybatisSetShardKeyAspect.java
License:Apache License
@Around("@annotation(com.newtranx.util.mysql.fabric.WithShardKey) || @within(com.newtranx.util.mysql.fabric.WithShardKey)") public Object setShardKey(ProceedingJoinPoint pjp) throws Throwable { Method method = AspectJUtils.getMethod(pjp); String key = null;//from w w w. ja v a 2 s . c o m boolean force = method.getAnnotation(WithShardKey.class).force(); int i = 0; for (Parameter p : method.getParameters()) { ShardKey a = p.getAnnotation(ShardKey.class); if (a != null) { if (key != null) throw new RuntimeException("found multiple shardkey"); Object obj = pjp.getArgs()[i]; if (StringUtils.isEmpty(a.property())) key = obj.toString(); else { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(obj); key = bw.getPropertyValue(a.property()).toString(); } } i++; } if (key == null) throw new RuntimeException("can not find shardkey"); fabricShardKey.set(key, force); return pjp.proceed(); }
From source file:com.onboard.service.activity.impl.ActivityRecorderImpl.java
License:Apache License
/** * /*w ww . j a v a2 s . c om*/ * * @param item * */ @Override public Object recordUpdateActivity(ProceedingJoinPoint joinpoint) { BaseProjectItem original = (BaseProjectItem) joinpoint.getArgs()[0]; if (original == null) { return null; } ActivityGenerator activityGenerator = activityGenerators.get(original.getType()); if (activityGenerator != null) { original = activityGenerator.enrichModel(original); } try { BaseProjectItem updated = (BaseProjectItem) joinpoint.proceed(); if (activityGenerator != null) { // updated updated = activityGenerator.enrichModel(updated); Activity activity = activityGenerator.generateUpdateActivity(original, updated); if (activity != null) { activity = this.enrichActivity(activity); activityMapper.insert(activity); this.callActivityHook(activity, original, updated); } } return updated; } catch (ActivityRecorderException e) { logger.error("Fail to log activity:", e); } catch (Throwable t) { logger.error("Fail to log activity:", t); } return original; }
From source file:com.onboard.service.activity.impl.ActivityRecorderImpl.java
License:Apache License
@Override public Object deleteActivity(ProceedingJoinPoint joinpoint) { Object returnVal = null;/*from w ww . ja v a 2 s. c o m*/ String modelType = null; Class<?>[] serviceTypes = joinpoint.getTarget().getClass().getInterfaces(); for (Class<?> clazz : serviceTypes) { if (service2ModelMap.get(clazz.getName()) != null) { modelType = service2ModelMap.get(clazz.getName()); break; } } if (modelType != null) { Activity activity = new Activity(); activity.setAttachType(modelType); activity.setAttachId((Integer) joinpoint.getArgs()[0]); activityMapper.deleteByExample(new ActivityExample(activity)); /** * TODO delete notifications which reference the activity */ } try { returnVal = joinpoint.proceed(); } catch (Throwable e) { logger.error("fail to delete item: ", e); } return returnVal; }