List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringControllerAspect.java
License:Apache License
@Around("classAnnotatedWithControllerPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()") public Object intercept(ProceedingJoinPoint pjp) throws Throwable { MethodSignature signature = (MethodSignature) pjp.getSignature(); // metrics/* ww w.j a v a2s . c o m*/ if (metricEventPublisher != null) metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.CONTROLLER); chaosMonkey.callChaosMonkey(createSignature(signature)); return pjp.proceed(); }
From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringRepositoryAspect.java
License:Apache License
@Around("implementsCrudRepository() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()") public Object intercept(ProceedingJoinPoint pjp) throws Throwable { // metrics//from ww w. ja v a 2 s. c o m if (metricEventPublisher != null) metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.REPOSITORY); MethodSignature signature = (MethodSignature) pjp.getSignature(); chaosMonkey.callChaosMonkey(createSignature(signature)); return pjp.proceed(); }
From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringRestControllerAspect.java
License:Apache License
@Around("classAnnotatedWithControllerPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()") public Object intercept(ProceedingJoinPoint pjp) throws Throwable { // metrics/*from w w w . j ava 2s . c o m*/ if (metricEventPublisher != null) metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.RESTCONTROLLER); MethodSignature signature = (MethodSignature) pjp.getSignature(); chaosMonkey.callChaosMonkey(createSignature(signature)); return pjp.proceed(); }
From source file:de.codecentric.spring.boot.chaos.monkey.watcher.SpringServiceAspect.java
License:Apache License
@Around("classAnnotatedWithControllerPointcut() && allPublicMethodPointcut() && !classInChaosMonkeyPackage()") public Object intercept(ProceedingJoinPoint pjp) throws Throwable { LOGGER.debug(/*from www.ja va 2 s. c o m*/ LOGGER.isDebugEnabled() ? "Service class and public method detected: " + pjp.getSignature() : null); if (metricEventPublisher != null) metricEventPublisher.publishMetricEvent(calculatePointcut(pjp.toShortString()), MetricType.SERVICE); MethodSignature signature = (MethodSignature) pjp.getSignature(); chaosMonkey.callChaosMonkey(createSignature(signature)); return pjp.proceed(); }
From source file:de.dan_nrw.caching.CachingAspect.java
License:Open Source License
@Around("cachablePointcut()") public Object aroundCachable(final ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Cachable cachableAnnotation = (Cachable) methodSignature.getMethod().getAnnotation(Cachable.class); Cache cache = Cache.getCurrent();/*w w w . ja va2s . c om*/ try { if (cache.containsKey(cachableAnnotation.key())) { // if key is already in cache and data is not expired return cache.get(cachableAnnotation.key()); } } catch (IllegalArgumentException ex) { // if key does not exists, data must be retrieved } catch (CachedDataExpiredException ex) { // if data stored in cache is expired, it must be retrieved } // determinig data Object data = joinPoint.proceed(); // cache is filled if (data != null) { cache.put(cachableAnnotation.key(), data, cachableAnnotation.durability()); } // returning result return data; }
From source file:de.escidoc.core.aa.security.aop.SecurityInterceptor.java
License:Open Source License
/** * Around advice to perform the authorization of the current request. * <p/>/* w ww . j a v a 2 s. c o m*/ * This method is called every time the Interceptor is intercepting a method call. * <p/> * It does the following steps: <ul> <li>Fetch the credentials (techUser, handle) of the current user from class * {@code UserContext}.</li> <li>Checks the technical username. Has to be either <ul> * <li>{@code ShibbolethUser}, which means that the service has been invoked from via a webservice, </li> * <li>{@code internal}, which means that the service has been called internally from another component and * {@code INTERNAL_INTERCEPTION} is turned off, or</li> <li>{@code authorization}, which means that the * service has been called internally from the authorization component.</li> </ul> <li>In case the technical * username is {@code internal}, no further security checks are done, the intercepted method is invoked and its * return value is returned to the originally invoking method.</li> <li>In case the technical username is * {@code ShibbolethUser}, the following steps are executed.</li> <li>The private method * {@code doAuthentication} is called, which returns the "real" username for the handle fetched from * {@code UserContext}.</li> <li>The private method {@code doAuthorisation} is called, which calls the * XACML engine with the current input parameters in order to decide whether invoking the intercepted method is * permitted or denied. In case of denial, an exception is thrown.</li> <li>The intercepted method is invoked, * returning some return values.</li> <li>If the return values are a list of objects, these have to filtered before * returned to the invoking service. For this the private method {@code doFiltering} is called, which returns * the (filtered) return value of the intercepted method.</li> <li>The (filtered) return value of the intercepted * method is returned back to the invoking service.</li> </ul> * * @param joinPoint The current {@link ProceedingJoinPoint}. * @throws Throwable Thrown in case of an error. * @return */ @Around("execution(public * de.escidoc.core.*.service.*.*(..))" + " && !within(de.escidoc.core.aa.service.EscidocUserDetailsService)" + " && !within(de.escidoc.core.common.util.aop..*)") public Object authorize(final ProceedingJoinPoint joinPoint) throws Throwable { final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); final Method calledMethod = methodSignature.getMethod(); final String target = getTargetInterface(joinPoint); final String methodName = calledMethod.getName(); final String handle = UserContext.getHandle(); // ------------------- // --- Preparation --- // ------------------- if (LOGGER.isDebugEnabled()) { LOGGER.debug(StringUtility.concatenateWithColonToString("The callee", target)); LOGGER.debug(StringUtility.concatenateWithColonToString("Method name", methodName)); LOGGER.debug(StringUtility.concatenateWithColonToString("The handle/password", handle)); } final Object[] arguments = joinPoint.getArgs(); if (LOGGER.isDebugEnabled()) { if (arguments.length > 0) { LOGGER.debug(StringUtility.concatenateWithColon("First Argument", arguments[0]).toString()); } else { LOGGER.debug("Method called without arguments."); } } // --------------------- // --- Authorization --- // --------------------- // authorization is not performed if the current request is executed as // an internal user. Only external users are authorized. if (!UserContext.isInternalUser()) { // Calls from the authorization component to other components run // with privileges of the internal authorization user (superuser). // They will not be further intercepted. UserContext.runAsInternalUser(); doAuthorisation(target, methodName, arguments); // -------------------- // --- Continuation --- // -------------------- // if everything is fine, finally call the method. // This method runs with privileges of an internal user that will // not be // further intercepted, as the access to the resource has been // granted, // now. } try { return proceed(joinPoint); } catch (final ResourceNotFoundException e) { // see issue 475, 500 // this exception may be thrown if the user tries to access // a versionized resource without providing the version number. // If the access is denied for the latest version, the business // logic is asked to retrieve the latest release. If no release // exists, a Resource not found exception is thrown containing // an error message indicating the missing release. // As this is an authorization failure, this kind of // ResourceNotFoundException must be caught and a // AuthorizationException has to be thrown, instead if (UserContext.isRetrieveRestrictedToReleased() && ERR_MSG_LATEST_RELEASE_NOT_FOUND.equals(e.getMessage())) { throw createAuthorizationException(target, methodName, arguments); } else { throw e; } } }
From source file:de.escidoc.core.aa.security.aop.SecurityInterceptor.java
License:Open Source License
private static String getTargetInterface(final ProceedingJoinPoint joinPoint) { String target = null;//from www. j a v a2 s .co m final Method calledMethod = ((MethodSignature) joinPoint.getSignature()).getMethod(); final Class[] interfaces = joinPoint.getTarget().getClass().getInterfaces(); for (final Class interfaze : interfaces) { final Method[] methods = interfaze.getMethods(); for (final Method method : methods) { if (method.getName().equals(calledMethod.getName()) && method.getReturnType().equals(calledMethod.getReturnType())) { target = interfaze.getName(); } } } return target; }
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.//from w w w. jav a2 s.com * @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;/* w ww.j ava 2 s . co 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.huxhorn.lilith.tracing.TracingAspect.java
License:Open Source License
public Object trace(ProceedingJoinPoint call) throws Throwable { if (logger == null) { setLoggerName(null);//from w ww. ja v a 2 s . c om // 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); } } }