@PostConstruct private void inject(final InvocationContext context) throws Exception { final Object beanInstance = context.getTarget(); injectionManager.inject(beanInstance, CdiComponentProvider.CDI_CLASS_ANALYZER); // Invoke next interceptor in chain context.proceed(); } }
@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 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(); } }
@PostConstruct public void postConstruct(InvocationContext ctx) throws Exception { InterceptorMdbBean.classLevelCreateMethodInterception = true; ctx.proceed(); }
@PostConstruct public void postConstruct(InvocationContext ctx) { getMethodReturnsNull = ctx.getMethod() == null; try { ctx.proceed(); } catch (Exception e) { } }
@AroundConstruct @PostConstruct @PreDestroy public void intercept(InvocationContext ctx) { numberOfInterceptions++; try { ctx.proceed(); } catch (Exception e) { throw new RuntimeException(); } }
@PostConstruct public Object logPostConstruct(final InvocationContext invocationContext) { LOG.trace("Skipping @PostConstruct for " + invocationContext.getTarget()); return null; } }
@AroundInvoke public Object intercept(InvocationContext ctx) throws Exception { ctx.getContextData().put("foo", "bar"); Object result = ctx.proceed(); contextDataOK = ctx.getContextData().get("foo").equals("barbar"); return result; }
@AroundInvoke public Object intercept(InvocationContext ctx) throws Exception { Integer[] parameters = new Integer[] { 1, 2, 3 }; ctx.setParameters(parameters); return ctx.proceed(); } }
@AroundConstruct public void intercept(InvocationContext ctx) { try { ctx.proceed(); } catch (Exception e) { throw new RuntimeException(e); } } }
@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; } } }
@AroundConstruct public Object onConstruct(InvocationContext context) throws Exception { // null before the InvocationContext.proceed() returns Object target = context.getTarget(); isNull(target); // null in case of AroundConstruct Method method = context.getMethod(); isNull(method); // NOT null in case of AroundConstruct Constructor ctor = context.getConstructor(); isNotNull(ctor); // perform the constructor injection Object result = context.proceed(); isNull(result); // NOT null after the InvocationContext.proceed() completes target = context.getTarget(); isNotNull(target); // a constructor should have been called GreetingBean bean = (GreetingBean) target; isBoolean(bean.isConstructed(), true); isBoolean(bean.isInitialized(), false); // constructor injection should have been done isNotNull(bean.getParam()); return null; }
/** * Intercepts a call to bean method annotated by any of the fault tolerance * annotations. * * @param context Invocation context. * @return Whatever the intercepted method returns. * @throws Throwable If a problem occurs. */ @AroundInvoke public Object interceptCommand(InvocationContext context) throws Throwable { try { LOGGER.fine("Interceptor called for '" + context.getTarget().getClass() + "::" + context.getMethod().getName() + "'"); // Create method introspector and executer retrier final MethodIntrospector introspector = new MethodIntrospector( context.getTarget().getClass(), context.getMethod()); final CommandRetrier retrier = new CommandRetrier(context, introspector); return retrier.execute(); } catch (Throwable t) { LOGGER.fine("Throwable caught by interceptor '" + t.getMessage() + "'"); throw t; } } }
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(); } }
/** * This interceptor will catch all exception and convert them using the exceptionhandler * @param ctx the invocation context * @return the result * @throws JaxRsResponseException an exception that can be handled by a jee container */ @AroundInvoke public Object intercept(final InvocationContext ctx) throws JaxRsResponseException { try { return ctx.proceed(); } catch (final Exception theException) { final AbstractJaxRsProvider theServer = (AbstractJaxRsProvider) ctx.getTarget(); throw convertException(theServer, theException); } }
public Object intercept(InterceptionType type, HelloInterceptorEnabler enabler, InvocationContext ctx) { try { return "Hello, " + ctx.proceed(); } catch (Exception e) { throw new RuntimeException(e); } }
@AroundConstruct public void validateConstructorInvocation(InvocationContext ctx) throws Exception { ExecutableValidator executableValidator = validator.forExecutables(); Set<? extends ConstraintViolation<?>> violations = executableValidator.validateConstructorParameters( ctx.getConstructor(), ctx.getParameters() ); getMessage( ctx.getConstructor(), ctx.getParameters(), violations ), violations ); ctx.proceed(); Object createdObject = ctx.getTarget(); ctx.getConstructor(), createdObject ); getMessage( ctx.getConstructor(), ctx.getParameters(), violations ), violations );
@AroundInvoke private Object aroundMethod(InvocationContext context) throws Exception { return called(context, context.getMethod()); }
@AroundConstruct public void intercept(InvocationContext ctx) { if (proceed) { try { ctx.proceed(); Baz instance = (Baz) ctx.getTarget(); instance.accessed = true; } catch (Exception e) { throw new RuntimeException(e); } } }