List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:de.bstreit.java.springaop.observablebean.ObservableBeanAspectMixin.java
License:Apache License
/** * //w w w .j ava 2 s .c o m * @param pjp * @throws Throwable * not expected to happen with simple beans! */ @Around("execution (* @de.bstreit.java.springaop.observablebean.ObservableBean *.set*(..))") public void handleSetterInvocation(ProceedingJoinPoint pjp) throws Throwable { // the target is the actual bean, with the set and get methods final Object target = pjp.getTarget(); /* * It seems that aop does not create the mixin unless at least one of the * IObservableBean methods (e.g. addPropertyChangeListener) is actually * called. * * That certainly reduces overhead; we must, however, take into * consideration that in this case, we do not have a * PropertyChangeSupportWithInterface instance and need to call the setter * ourself, by calling pjp.proceed(). */ final boolean mixinExists = weakReferences.containsKey(target); if (mixinExists) { final PropertyChangeSupportWithInterface mixin = weakReferences.get(target); mixin.handleSetterInvocation(pjp); } else { // No listeners at all, simply call setter without firing property change // events pjp.proceed(); } }
From source file:de.codecentric.batch.metrics.AbstractBatchMetricsAspect.java
License:Apache License
protected Object profileMethod(ProceedingJoinPoint pjp) throws Throwable { StopWatch stopWatch = startStopWatch(); try {//from www .ja va2 s . c o m return pjp.proceed(); } finally { gaugeService.submit(TIMER_PREFIX + getStepIdentifier() + "." + ClassUtils.getShortName(pjp.getTarget().getClass()) + "." + pjp.getSignature().getName(), getTotalTimeMillis(stopWatch)); } }
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 w ww . j a v a 2s . c o 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.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 a va2 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.huxhorn.lilith.tracing.TracingAspect.java
License:Open Source License
public Object trace(ProceedingJoinPoint call) throws Throwable { if (logger == null) { setLoggerName(null);/*from www. j ava2 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); } } }
From source file:de.hybris.platform.acceleratorservices.dataimport.batch.aop.TimeMeasurementAspect.java
License:Open Source License
/** * Invokes a method and measures the execution time. * //from ww w . j a va 2 s.c o m * @param pjp * @return result of the invocation * @throws Throwable */ public Object measure(final ProceedingJoinPoint pjp) throws Throwable { final String methodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName(); final Object[] args = pjp.getArgs(); final long start = System.currentTimeMillis(); final Object result = pjp.proceed(); if (LOG.isInfoEnabled()) { final BatchHeader header = AspectUtils.getHeader(args); LOG.info("Processed " + methodName + (header == null ? "" : " [header=" + header + "]") + " in " + (System.currentTimeMillis() - start) + "ms"); } return result; }
From source file:de.hybris.platform.assistedservicestorefront.aspect.ChannelDecisionAspect.java
License:Open Source License
/** * Around advice for the decide method of classes in the org.springframework.security.web.access.channel package, * forcing HTTPS for all requests.//from w ww . j av a 2 s . com * * @param joinPoint * the join point * @throws Throwable * any exceptions thrown during advice execution */ @Around("execution(public void org.springframework.security.web.access.channel.*.decide(..))") public void decideAround(final ProceedingJoinPoint joinPoint) throws Throwable { if (isAssistedServiceMode(joinPoint)) { if (joinPoint.getTarget() instanceof SecureChannelProcessor) { processSecureChannelProcessor(joinPoint); } else if (joinPoint.getTarget() instanceof InsecureChannelProcessor) { // do nothing - we don't want the insecure processor to redirect to HTTP } else if (joinPoint.getTarget() instanceof ChannelDecisionManagerImpl) { processChannelDecisionManager(joinPoint); } else { joinPoint.proceed(); } } else { // if the assisted service mode is off just call the regular logic joinPoint.proceed(); } }
From source file:de.hybris.platform.assistedservicestorefront.aspect.ChannelDecisionAspect.java
License:Open Source License
private void processSecureChannelProcessor(final ProceedingJoinPoint joinPoint) throws IOException, ServletException { final SecureChannelProcessor processor = (SecureChannelProcessor) joinPoint.getTarget(); final FilterInvocation invocation = (FilterInvocation) joinPoint.getArgs()[0]; /* redirect any insecure request to HTTPS independent of its config */ if (!invocation.getHttpRequest().isSecure()) { processor.getEntryPoint().commence(invocation.getHttpRequest(), invocation.getHttpResponse()); }/*from w ww .j a v a2 s . co m*/ }
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;/*from w w w.jav a 2 s . c om*/ 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.harvard.med.screensaver.ui.arch.view.aspects.UICommandExceptionHandlerAspect.java
License:Open Source License
private Object handleException(ProceedingJoinPoint joinPoint, Throwable t, String errorMessageId, String errorMessageArg) { AbstractBackingBean backingBean = (AbstractBackingBean) joinPoint.getTarget(); log.error("backing bean " + backingBean.getClass().getSimpleName() + " method " + joinPoint.getSignature().getName() + " threw " + t.getClass().getSimpleName() + ": " + t.getMessage(), t);//from w w w.j a v a2s . co m _messages.setFacesMessageForComponent(errorMessageId, null, errorMessageArg); if (backingBean instanceof EditableEntityViewer) { // TODO not working... // ((EntityViewer) backingBean).reload(); // this is the best we can do with the current design EditableEntityViewer editableViewer = (EditableEntityViewer) backingBean; return editableViewer.cancel(); } return ScreensaverConstants.REDISPLAY_PAGE_ACTION_RESULT; }