@AroundInvoke public Object log(InvocationContext context) throws Exception { Object[] parameters = context.getParameters(); if (parameters.length > 0 && parameters[0] instanceof String) { String param = (String) parameters[0]; parameters[0] = "Hi " + param + " !"; context.setParameters(parameters); } return context.proceed(); } }
@Override public Method getMethod() { return context.getMethod(); }
@Override public Object[] getParameters() { return context.getParameters(); }
@AroundInvoke public Object validateMethodInvocation(InvocationContext ctx) throws Exception { final boolean isJaxRsMethod = extension.jaxRsResourceCache.apply(ctx.getMethod().getDeclaringClass()); return isJaxRsMethod ? ctx.proceed() : interceptor.validateMethodInvocation(ctx); }
@AroundInvoke public Object intercept(final InvocationContext ic) throws Exception { try { return ic.proceed(); } catch (final WebApplicationException wae) { if (store != null) { store.setException(wae); } throw wae; } } }
@AroundInvoke private Object aroundMethod(InvocationContext context) throws Exception { return called(context, context.getMethod()); }
private Object doMethodInterception(InvocationContext invocationContext, InterceptionType interceptionType, InterceptorInstances interceptorInstances, InterceptorBindings interceptorBindings) throws Exception { if (interceptorBindings != null) { List<Interceptor<?>> currentInterceptors = interceptorBindings.getMethodInterceptors(interceptionType, invocationContext.getMethod()); return delegateInterception(invocationContext, interceptionType, currentInterceptors, interceptorInstances); } else { return invocationContext.proceed(); } }
public Object intercept(InterceptionType type, HelloInterceptorEnabler enabler, InvocationContext ctx) { try { return "Hello, " + ctx.proceed(); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Class used to enable (activate) the dynamic interceptor and sets its priority * * @author Arjan Tijms * */ @Interceptor @Priority(200) public class HelloInterceptorEnabler { }
@AroundConstruct private Object aroundConstructor(InvocationContext context) throws Exception { return called(context, context.getConstructor()); }
@AroundConstruct public void validateConstructor(InvocationContext context) { System.out.println("MyAroundConstructInterceptor.validateConstructor"); } }
@AroundInvoke public Object log(InvocationContext context) throws Exception { Object[] parameters = context.getParameters(); if (parameters.length > 0 && parameters[0] instanceof String) { String param = (String) parameters[0]; parameters[0] = "Hi " + param + " !"; context.setParameters(parameters); } return context.proceed(); } }
@Override protected Object prepareAndInvoke(Meter meter, Metered annotation, InvocationContext context) throws Exception { meter.mark(); return context.proceed(); } }
/** * Intercepteur pour CDI & pour EJB 3.1 (Java EE 6+), * configuré automatiquement pour les beans et méthodes ayant l'annotation @{@link Asynchronous}. * @author Emeric Vernat */ @Interceptor @Asynchronous public class MonitoringAsynchronousCdiInterceptor extends MonitoringInterceptor { private static final long serialVersionUID = 1L; // note: it would be cool to automatically monitor methods having @Schedule or @Schedules like @Asynchronous, // without having to add @Monitored on the method, but we can't }
@AroundConstruct public void validateConstructorInvocation(InvocationContext ctx) throws Exception { final boolean isJaxRsConstructor = extension.jaxRsResourceCache.apply(ctx.getConstructor().getDeclaringClass()); if (!isJaxRsConstructor) { interceptor.validateConstructorInvocation(ctx); } } }
@AroundInvoke public Object log(InvocationContext context) throws Exception { Object[] parameters = context.getParameters(); if (parameters.length > 0 && parameters[0] instanceof String) { String param = (String) parameters[0]; parameters[0] = param + " Nice to meet you."; context.setParameters(parameters); } return context.proceed(); } }
@Override protected Object prepareAndInvoke(Counter counter, Counted annot, InvocationContext context) throws Exception { counter.inc(); return context.proceed(); }
/** * Intercepteur pour CDI & pour EJB 3.1 (Java EE 6+). * Il est destiné à un compteur pour les statistiques d'exécutions de * méthodes @{@link javax.faces.bean.RequestScoped}, @{@link SessionScoped}, @{@link ApplicationScoped} * ( ainsi que @{@link Stateless}, @{@link Stateful} ou @{@link MessageDriven} ). * Il peut être paramétré par l'annotation @{@link Monitored} dans les sources java des classes d'implémentations de beans CDI ou d'ejb. * (ou alors par l'annotation @{@link javax.interceptor.Interceptors} dans les mêmes classes). * @author Emeric Vernat */ @Interceptor @Monitored public class MonitoringCdiInterceptor extends MonitoringInterceptor { private static final long serialVersionUID = 1L; }
/** * @author Arun Gupta */ @Priority(Interceptor.Priority.APPLICATION + 10) @Interceptor @MyAroundConstructInterceptorBinding public class MyAroundConstructInterceptor { @AroundConstruct public void validateConstructor(InvocationContext context) { System.out.println("MyAroundConstructInterceptor.validateConstructor"); } }