List of usage examples for org.aspectj.lang.reflect MethodSignature getMethod
Method getMethod();
From source file:de.escidoc.core.common.util.aop.StatisticInterceptor.java
License:Open Source License
/** * Around advice to create a statistic record for the current method call.<br> * * @param joinPoint The current {@link ProceedingJoinPoint}. * @return Returns the changed result.// www .jav a 2 s. co m * @throws Throwable Thrown in case of an error. */ @Around("execution(public * de.escidoc.core.*.service.*.*(..))" + " && !within(de.escidoc.core.aa.service.EscidocUserDetailsService)" + " && !execution(* de.escidoc.core..*.SemanticStoreHandler*.*(..))" + " && !execution(* de.escidoc.core..*.StatisticService*.*(..))" + " && !execution(* de.escidoc.core.common..*.*(..))") // enable this aspect only if you need public Object createStatisticRecord(final ProceedingJoinPoint joinPoint) throws Throwable { final long invocationStartTime = System.currentTimeMillis(); boolean successful = true; boolean internal = false; String exceptionName = null; String exceptionSource = null; try { // insert internal (0)/external (1) info if (!UserContext.isExternalUser()) { internal = true; } return proceed(joinPoint); } catch (final Exception e) { successful = false; exceptionName = e.getClass().getName(); final StackTraceElement[] elements = e.getStackTrace(); if (elements != null && elements.length > 0) { final StackTraceElement element = elements[0]; exceptionSource = StringUtility.format(element.getClassName(), element.getMethodName(), element.getLineNumber()); } else { exceptionSource = Constants.UNKNOWN; } if (e instanceof EscidocException) { throw e; } else { // this should not occur. To report this failure, the exception is wrapped by a SystemException throw new SystemException("Service throws unexpected exception. ", e); } } finally { // get callee and method info final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); // get interface info // create a new statistic data record stored in thread local for this scope final StatisticRecordBuilder statisticRecordBuilder = StatisticRecordBuilder.createStatisticRecord(); handleObjectIds(statisticRecordBuilder, methodSignature.getMethod().getName(), joinPoint.getArgs()); final String interfaceInfo = VALUE_INTERFACE_REST; final StatisticRecord statisticRecord = statisticRecordBuilder .withParameter(PARAM_HANDLER, methodSignature.getDeclaringTypeName().replaceAll("\\.interfaces", "") .replaceAll("Interface$", "")) .withParameter(PARAM_REQUEST, methodSignature.getMethod().getName()) .withParameter(PARAM_INTERFACE, interfaceInfo).withParameter(PARAM_INTERNAL, internal) .withParameter(PARAM_SUCCESSFUL, successful).withParameter(PARAM_EXCEPTION_NAME, exceptionName) .withParameter(PARAM_EXCEPTION_SOURCE, exceptionSource) .withParameter(PARAM_USER_ID, UserContext.getId()).withParameter(PARAM_ELAPSED_TIME, String.valueOf(System.currentTimeMillis() - invocationStartTime)) .build(); this.statisticService.createStatisticRecord(statisticRecord); } }
From source file:de.gmorling.methodvalidation.spring.ValidationInterceptor.java
License:Apache License
@Around("execution(public * *(..)) && @within(de.gmorling.methodvalidation.spring.AutoValidating)") public Object validateMethodInvocation(ProceedingJoinPoint pjp) throws Throwable { Object result;/*from w w w . j av a 2 s . c o m*/ MethodSignature signature = (MethodSignature) pjp.getSignature(); MethodValidator methodValidator = validator.unwrap(MethodValidator.class); Set<MethodConstraintViolation<Object>> parametersViolations = methodValidator .validateAllParameters(pjp.getTarget(), signature.getMethod(), pjp.getArgs()); if (!parametersViolations.isEmpty()) { throw new MethodConstraintViolationException(parametersViolations); } result = pjp.proceed(); //Execute the method Set<MethodConstraintViolation<Object>> returnValueViolations = methodValidator .validateReturnValue(pjp.getTarget(), signature.getMethod(), result); if (!returnValueViolations.isEmpty()) { throw new MethodConstraintViolationException(returnValueViolations); } return result; }
From source file:de.hska.ld.core.service.annotation.handler.LoggingHandler.java
License:Apache License
@Before("execution(* *.*(..)) && @annotation(logging)") public void before(JoinPoint joinPoint, Logging logging) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Class<?>[] parameterTypes = signature.getMethod().getParameterTypes(); threadLocal.set(new Args(joinPoint.getArgs(), parameterTypes)); }
From source file:de.huxhorn.lilith.tracing.TracingAspect.java
License:Open Source License
public Object trace(ProceedingJoinPoint call) throws Throwable { if (logger == null) { setLoggerName(null);//from ww w.j a v a 2 s . com // this initializes the logger } Signature signature = call.getSignature(); Class<?> clazz = signature.getDeclaringType(); Object theTarget = call.getTarget(); if (theTarget != null) { clazz = theTarget.getClass(); } String fullClassName = clazz.getName(); String methodName = signature.getName(); StringBuilder msg = new StringBuilder(); if (showingModifiers) { msg.append(Modifier.toString(signature.getModifiers())).append(' '); } if (usingShortClassName) { msg.append(clazz.getSimpleName()); } else { msg.append(fullClassName); } msg.append('.').append(methodName); String methodBaseName = msg.toString(); if (signature instanceof MethodSignature) { MethodSignature methodSignature = (MethodSignature) signature; msg.append('('); if (showingParameterValues) { Object[] args = call.getArgs(); boolean first = true; for (Object arg : args) { if (first) { first = false; } else { msg.append(", "); } msg.append(SafeString.toString(arg, SafeString.StringWrapping.ALL, SafeString.StringStyle.GROOVY, SafeString.MapStyle.GROOVY)); } } else { Method method = methodSignature.getMethod(); Class<?>[] parameterTypes = method.getParameterTypes(); boolean first = true; for (Class<?> param : parameterTypes) { if (first) { first = false; } else { msg.append(", "); } msg.append(param.getSimpleName()); } if (method.isVarArgs()) { int length = msg.length(); msg.delete(length - 2, length); // cut of existing [] msg.append("..."); } } msg.append(')'); } String methodSignatureString = msg.toString(); String previousClass = MDC.get(TRACED_CLASS_MDC_KEY); String previousMethod = MDC.get(TRACED_METHOD_MDC_KEY); long nanoSeconds = 0; try { MDC.put(TRACED_CLASS_MDC_KEY, fullClassName); MDC.put(TRACED_METHOD_MDC_KEY, methodName); if (logger.isInfoEnabled(ENTERING_MARKER)) logger.info(ENTERING_MARKER, "{} entered.", methodSignatureString); Object result; nanoSeconds = System.nanoTime(); result = call.proceed(); nanoSeconds = System.nanoTime() - nanoSeconds; profile(methodBaseName, methodSignatureString, nanoSeconds); if (result == null || !showingParameterValues) { if (logger.isInfoEnabled(EXITING_MARKER)) logger.info(EXITING_MARKER, "{} returned.", methodSignatureString); } else { if (logger.isInfoEnabled(EXITING_MARKER)) logger.info(EXITING_MARKER, "{} returned {}.", methodSignatureString, result); } return result; } catch (Throwable t) { nanoSeconds = System.nanoTime() - nanoSeconds; profile(methodBaseName, methodSignatureString, nanoSeconds); if (logger.isInfoEnabled(THROWING_MARKER)) logger.info(THROWING_MARKER, "{} failed.", methodSignatureString, t); throw t; // rethrow } finally { if (previousClass == null) { MDC.remove(TRACED_CLASS_MDC_KEY); } else { MDC.put(TRACED_CLASS_MDC_KEY, previousClass); } if (previousMethod == null) { MDC.remove(TRACED_METHOD_MDC_KEY); } else { MDC.put(TRACED_METHOD_MDC_KEY, previousMethod); } } }
From source file:de.hybris.platform.acceleratorstorefrontcommons.checkout.steps.validation.CheckoutStepValidationAspect.java
License:Open Source License
public Object validateCheckoutStep(final ProceedingJoinPoint pjp) throws Throwable { final MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); final PreValidateCheckoutStep preValidateCheckoutStep = methodSignature.getMethod() .getAnnotation(PreValidateCheckoutStep.class); final CheckoutGroup checkoutGroup = getCheckoutFlowGroupMap() .get(getCheckoutFacade().getCheckoutFlowGroupForCheckout()); final CheckoutStep checkoutStepBean = checkoutGroup.getCheckoutStepMap() .get(preValidateCheckoutStep.checkoutStep()); final ValidationResults validationResults = checkoutStepBean .validate((RedirectAttributesModelMap) pjp.getArgs()[1]); if (checkoutStepBean.checkIfValidationErrors(validationResults)) { return checkoutStepBean.onValidation(validationResults); }//from w ww . ja v a2s. com return pjp.proceed(); }
From source file:de.hybris.platform.acceleratorstorefrontcommons.checkout.steps.validation.CheckoutStepValidationAspectTest.java
License:Open Source License
private void setupPjp() throws Throwable { final MethodSignature signature = Mockito.mock(MethodSignature.class); final Method testMethod = this.getClass().getMethod("annotatedMethod"); given(signature.getMethod()).willReturn(testMethod); given(pjp.getSignature()).willReturn(signature); given(pjp.proceed()).willReturn(PROCEED); final Object[] args = new Object[2]; args[1] = Mockito.mock(RedirectAttributesModelMap.class); given(pjp.getArgs()).willReturn(args); }
From source file:de.kaiserpfalzEdv.office.core.license.impl.LicenseManager.java
License:Apache License
private OfficeModule getOfficeModuleFromMethodAnnotation(final JoinPoint invocation) { MethodSignature signature = (MethodSignature) invocation.getSignature(); return signature.getMethod().getAnnotation(OfficeModule.class); }
From source file:edu.eci.arsw.par1t.aspects.AspectsHandler.java
License:Open Source License
public Object analisis(ProceedingJoinPoint jp) { long start = System.currentTimeMillis(); Object object = null;// w w w .jav a 2 s. com try { MethodSignature signature = (MethodSignature) jp.getSignature(); Method method = signature.getMethod(); String nombre = method.getName(); object = jp.proceed(); start = System.currentTimeMillis() - start; if (jp.getTarget().toString().contains("DataLoaderOne")) { pw.println("Nombre del componente de carga : DataLoaderOne Tiempo " + start + " ms."); } else if (jp.getTarget().toString().contains("DataLoaderTwo")) { pw.println("Nombre del componente de carga : DataLoaderTwo Tiempo " + start + " ms."); } else if (jp.getTarget().toString().contains("SorterThree")) { pw.println("Nombre del componente de ordenamiendo : SorterThree Tiempo " + start + " ms."); } else if (jp.getTarget().toString().contains("SorterTwo")) { pw.println("Nombre del componente de ordenamiento: SorterTwo Tiempo " + start + " ms."); } } catch (Exception e) { e.printStackTrace(); } catch (Throwable ex) { ex.printStackTrace(); } pw.flush(); return object; }
From source file:edu.kit.dama.authorization.aspects.util.AuthorisationSignatureExtractor.java
License:Apache License
/** * Extract the authentication signature. * * @param jp The AspectJ JointPoint.// w ww . j av a 2 s.c o m * * @return The extracted AuthSignature information. */ protected final AuthSignature extractAuthSignature(final JoinPoint jp) { AuthSignature result = new AuthSignature(); Object[] args = jp.getArgs(); Signature signature = jp.getStaticPart().getSignature(); LOGGER.debug("Looking for method signature."); if (signature instanceof MethodSignature) { LOGGER.debug("Checking signature of method {}#{}", signature.getDeclaringTypeName(), signature.getName()); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); Class[] parametersTypes = method.getParameterTypes(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); LOGGER.debug("Checking {} parameter annotations.", parameterAnnotations.length); for (int i = 0; i < parameterAnnotations.length; i++) { Annotation[] annotations = parameterAnnotations[i]; LOGGER.debug("Checking {} annotations for parameter {} of type {}.", annotations.length, i, parametersTypes[i]); for (Annotation annotation : annotations) { LOGGER.debug("Checking argument annotation {} of type {}", annotation, annotation.annotationType()); if (Context.class.isAssignableFrom(annotation.annotationType())) { LOGGER.debug("Argument with @Context annotation found"); if (null == args[i]) { throw new IllegalArgumentException( "Argument annotated with @Context must not be 'null'. Argument skipped."); } else if (!(args[i] instanceof IAuthorizationContext)) { throw new IllegalArgumentException( "Argument annotated with @Context does not implement IAuthorizationContext. Argument skipped."); } else { LOGGER.debug("Setting provided argument {} as authorization context.", args[i]); result.setAuthContext((IAuthorizationContext) args[i]); } } else if (SecuredArgument.class.isAssignableFrom(annotation.annotationType())) { LOGGER.debug("Argument with @SecuredArgument annotation found"); if (null == args[i]) { //Just ignore argument LOGGER.debug("Argument {} is 'null' and therefore ignored.", i); } else if (args[i] instanceof SecurableResourceId) { LOGGER.debug("Adding SecurableResourceId {}.", args[i]); result.addSecurableResourceId((SecurableResourceId) args[i]); } else if (args[i] instanceof ISecurableResource) { LOGGER.debug("Adding SecurableResource {}.", args[i]); result.addSecurableResource((ISecurableResource) args[i]); } else { throw new IllegalArgumentException( "Argument annotated with @SecuredArgument does not implement ISecurableResourceId or ISecurableResource. Argument ignored."); } } else { LOGGER.debug("Annotation with unknown type {} found. Ignoring it.", annotation.annotationType()); } } LOGGER.debug("Checks for parameter {} of type {} finished.", i, parametersTypes[i]); } } else { LOGGER.info("Provided signature is no MethodSignature"); } if (!result.isValid()) { LOGGER.warn("No valid auth signature extracted."); } return result; }
From source file:edu.umn.msi.tropix.persistence.aop.AopUtils.java
License:Open Source License
public static Method getMethod(final JoinPoint joinPoint) { final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); return methodSignature.getMethod(); }