List of usage examples for org.aspectj.lang.reflect MethodSignature getParameterNames
String[] getParameterNames();
From source file:org.slc.sli.dal.repository.tenancy.apsect.TenantAwareCallAspect.java
License:Apache License
private String extractTenant(JoinPoint jp) { MethodSignature ms = (MethodSignature) jp.getSignature(); String[] params = ms.getParameterNames(); TenantCall tenantParam = ms.getMethod().getAnnotation(TenantCall.class); for (int i = 0; i < params.length; i++) { if (tenantParam.param().equals(params[i])) { return (String) jp.getArgs()[i]; }//from w w w.ja va 2 s . c om } throw new IllegalStateException("Expected method parameter [" + tenantParam.param() + "] was not found"); }
From source file:org.slc.sli.dashboard.web.util.ControllerInputValidatorAspect.java
License:Apache License
/** * Around for pointcut defined by controllerMethodInvocation * @param joinPoint//from ww w. j av a2s. c o m * @return * @throws Throwable */ @Around("controllerMethodInvocation()") public Object aroundController(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Annotation[][] annotations = methodSignature.getMethod().getParameterAnnotations(); String[] paramNames = methodSignature.getParameterNames(); Object[] args = joinPoint.getArgs(); for (int i = 0; i < args.length; i++) { if (checkAnnotations(annotations[i])) { validateArg(args[i], paramNames[i]); } } return joinPoint.proceed(args); }
From source file:org.smallmind.nutsnbolts.reflection.aop.AOPUtility.java
License:Open Source License
public static Object getParameterValue(JoinPoint joinPoint, String parameterName, boolean nullable) throws BeanAccessException, BeanInvocationException { Object argumentValue;/* w ww.ja v a2 s. c o m*/ MethodSignature methodSignature = ((MethodSignature) joinPoint.getSignature()); String[] parameterNames; String baseParameter; String parameterGetter = null; int dotPos; if ((dotPos = parameterName.indexOf('.')) < 0) { baseParameter = parameterName; } else { baseParameter = parameterName.substring(0, dotPos); parameterGetter = parameterName.substring(dotPos + 1); } parameterNames = methodSignature.getParameterNames(); for (int index = 0; index < parameterNames.length; index++) { if (parameterNames[index].equals(baseParameter)) { argumentValue = (parameterGetter == null) ? joinPoint.getArgs()[index] : BeanUtility.executeGet(joinPoint.getArgs()[index], parameterGetter, nullable); if (argumentValue == null) { if (methodSignature.getParameterTypes()[index].isPrimitive()) { throw new BeanAccessException( "A 'null' parameter can't be assigned to the primitive type '%s'", methodSignature.getParameterTypes()[index]); } else if (!nullable) { throw new NullPointerException("Null value in a non-nullable parameter access"); } } return argumentValue; } } throw new BeanAccessException("The parameter(%s) was not found as part of the method(%s) signature", baseParameter, methodSignature.getName()); }
From source file:org.throwable.trace.core.utils.extend.AopUtils.java
License:Apache License
/** * AroundProceedingJoinPoint??/*from ww w.j a va 2 s . c om*/ * * @param pjp ? * @return ??? cn.hello.helloWorldjava.lang.String name1,java.lang.String name2 */ public static String getMethodAndParamsName(ProceedingJoinPoint pjp) { StringBuilder methodName = new StringBuilder(pjp.getSignature().getName()).append("("); MethodSignature signature = (MethodSignature) pjp.getSignature(); String[] names = signature.getParameterNames(); Class[] args = signature.getParameterTypes(); for (int i = 0, len = args.length; i < len; i++) { if (i != 0) { methodName.append(","); } methodName.append(args[i].getSimpleName()).append(" ").append(names[i]); } return methodName.append(")").toString(); }
From source file:org.wso2.carbon.apimgt.gateway.MethodTimeLogger.java
License:Open Source License
/** * If the pointcuts results true, this method is invoked every time a method satisfies the * criteria given in the pointcut./* w ww .j av a 2s .com*/ * * @param point The JoinPoint before method execution * @return result of method execution * @throws Throwable */ @Around("isConfigEnabled() && (pointCut() || pointCutAll())") public Object log(ProceedingJoinPoint point) throws Throwable { long start = System.currentTimeMillis(); MethodSignature signature = (MethodSignature) point.getSignature(); Object result = point.proceed(); String[] args = signature.getParameterNames(); String argString; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("["); if (args != null && args.length != 0) { String delimiter = ""; for (String arg : args) { stringBuilder.append(delimiter); delimiter = ", "; stringBuilder.append(arg); } } stringBuilder.append("]"); argString = stringBuilder.toString(); MessageContext messageContext = MessageContext.getCurrentMessageContext(); if (MDC.get(APIConstants.CORRELATION_ID) == null) { if (messageContext != null) { Map headers = (Map) messageContext .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null) { String correlationId = (String) headers.get(APIConstants.AM_ACTIVITY_ID); if (correlationId != null) { MDC.put(APIConstants.CORRELATION_ID, correlationId); } } } } log.info((System.currentTimeMillis() - start) + "|METHOD|" + MethodSignature.class.cast(point.getSignature()).getDeclaringTypeName() + "|" + MethodSignature.class.cast(point.getSignature()).getMethod().getName() + "|" + argString); return result; }
From source file:org.wso2.carbon.apimgt.impl.MethodTimeLogger.java
License:Open Source License
/** * If the pointcuts results true, this method is invoked every time a method satisfies the * criteria given in the pointcut./* w w w . j a v a 2 s . c o m*/ * * @param point The JoinPoint before method execution * @return result of method execution * @throws Throwable */ @Around("isConfigEnabled() && (pointCut() || pointCutAll())") public Object log(ProceedingJoinPoint point) throws Throwable { long start = System.currentTimeMillis(); MethodSignature signature = (MethodSignature) point.getSignature(); Object result = point.proceed(); String[] args = signature.getParameterNames(); String argString; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("["); if (args != null && args.length != 0) { String delimiter = ""; for (String arg : args) { stringBuilder.append(delimiter); delimiter = ", "; stringBuilder.append(arg); } } stringBuilder.append("]"); argString = stringBuilder.toString(); MessageContext messageContext = MessageContext.getCurrentMessageContext(); if (messageContext != null) { Map headers = (Map) messageContext .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null) { String correlationId = (String) headers.get(APIConstants.AM_ACTIVITY_ID); if (correlationId != null) { MDC.put(APIConstants.CORRELATION_ID, correlationId); } } } log.info((System.currentTimeMillis() - start) + "|METHOD|" + MethodSignature.class.cast(point.getSignature()).getDeclaringTypeName() + "|" + MethodSignature.class.cast(point.getSignature()).getMethod().getName() + "|" + argString); return result; }
From source file:uk.gov.ofwat.fountain.aspect.audit.AuditAdvice.java
License:Open Source License
private HashMap<String, String> getParams(ProceedingJoinPoint pjp) { HashMap<String, String> params = new HashMap<String, String>(); Object[] args = pjp.getArgs(); Signature signature = pjp.getStaticPart().getSignature(); if (signature instanceof MethodSignature) { MethodSignature ms = (MethodSignature) signature; Method method = ms.getMethod(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); String[] parameterNames = ms.getParameterNames(); for (int i = 0; i < args.length; i++) { String argsString = ""; if (args[i] != null) { argsString = args[i].toString(); }//from w w w .jav a 2 s. co m params.put(parameterNames[i], argsString); } } return params; }
From source file:uk.gov.ofwat.fountain.aspect.audit.AuditAdvice.java
License:Open Source License
private HashMap<String, Object> getContent(ProceedingJoinPoint pjp) { HashMap<String, Object> content = new HashMap<String, Object>(); Object[] args = pjp.getArgs(); Signature signature = pjp.getStaticPart().getSignature(); if (signature instanceof MethodSignature) { MethodSignature ms = (MethodSignature) signature; Method method = ms.getMethod(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); String[] parameterNames = ms.getParameterNames(); Class<?>[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterAnnotations.length; i++) { if (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput.class == parameterTypes[i] || javax.ws.rs.core.SecurityContext.class == parameterTypes[i] || javax.ws.rs.core.UriInfo.class == parameterTypes[i] || javax.servlet.http.HttpServletRequest.class == parameterTypes[i]) { continue; }/*from ww w . j a v a2 s . c om*/ content.put(parameterNames[i], args[i]); } } return content; }