javax.interceptor.AroundInvoke Java Examples

The following examples show how to use javax.interceptor.AroundInvoke. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggingInterceptor.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
@AroundInvoke
public Object logMethodEntry(InvocationContext context) throws Exception {
    Logger logger = null;
    try {
        Class<?> targetClass = RegistryApplication.class;
        Object target = context.getTarget();
        if (target != null) {
            targetClass = target.getClass();
        }
        
        logger = getLogger(targetClass);
    } catch (Throwable t) {
    }

    logger.debug("ENTERING method [{}] with {} parameters", context.getMethod().getName(), context.getParameters().length);
    Object rval = context.proceed();
    logger.debug("LEAVING method [{}]", context.getMethod().getName());
    return rval;
}
 
Example #2
Source File: AbstractEjbTimingAspect.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
@AroundInvoke
public Object doPerfLogging(final InvocationContext ctx) throws Throwable {
   final Method executingMethod = ctx.getMethod();
   Profiled profiled = executingMethod == null ? DefaultProfiled.INSTANCE : (Profiled)ctx.getMethod().getAnnotation(Profiled.class);
   if (profiled == null) {
      profiled = DefaultProfiled.INSTANCE;
   }

   return this.runProfiledMethod(new AbstractJoinPoint() {
      public Object proceed() throws Throwable {
         return ctx.proceed();
      }

      public Object getExecutingObject() {
         return ctx.getTarget();
      }

      public Object[] getParameters() {
         return ctx.getParameters();
      }

      public String getMethodName() {
         return executingMethod == null ? "null" : executingMethod.getName();
      }
   }, (Profiled)profiled, this.newStopWatch(((Profiled)profiled).logger(), ((Profiled)profiled).level()));
}
 
Example #3
Source File: FaultToleranceInterceptor.java    From smallrye-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@AroundInvoke
public Object interceptCommand(InvocationContext invocationContext) throws Exception {
    Method method = invocationContext.getMethod();
    Class<?> beanClass = interceptedBean != null ? interceptedBean.getBeanClass() : method.getDeclaringClass();
    InterceptionPoint point = new InterceptionPoint(beanClass, invocationContext);

    FaultToleranceOperation operation = operationProvider.get(beanClass, method);

    MetricsCollector collector = getMetricsCollector(operation, point);

    if (operation.isAsync() && operation.returnsCompletionStage()) {
        return properAsyncFlow(operation, invocationContext, collector, point);
    } else if (operation.isAsync()) {
        return futureFlow(operation, invocationContext, collector, point);
    } else {
        return syncFlow(operation, invocationContext, collector, point);
    }
}
 
Example #4
Source File: Statisticalnterceptor.java    From Java-EE-8-Design-Patterns-and-Best-Practices with MIT License 6 votes vote down vote up
@AroundInvoke
public Object statisticMethod (InvocationContext invocationContext) throws Exception{
	System.out.println("Statistical method : "
			+ invocationContext.getMethod().getName() + " " 
			+ invocationContext.getMethod().getDeclaringClass()
			);
	
	// get the enrollment:
	TestRevisionTO testRevisionTO = (TestRevisionTO)invocationContext.getParameters()[0];
	
	System.out.println("Enrolment : " + testRevisionTO.getEnrollment());
	
	// event.fireAsync (testRevisionTO.getEnrollment());// fire an async statistical event. This is new in JEE8.
	event.fire (testRevisionTO.getEnrollment());
	
	Object o =  invocationContext.proceed();
	return o;
}
 
Example #5
Source File: InterceptedStaticMethodTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@AroundInvoke
Object aroundInvoke(InvocationContext ctx) throws Exception {
    if (!Modifier.isStatic(ctx.getMethod().getModifiers())) {
        throw new AssertionFailedError("Not a static method!");
    }
    assertNull(ctx.getTarget());
    Object ret = ctx.proceed();
    if (ret != null) {
        if (ret instanceof String) {
            return "OK:" + ctx.proceed();
        } else if (ret instanceof Double) {
            return 42.0;
        } else {
            throw new AssertionFailedError("Unsupported return type: " + ret.getClass());
        }
    } else {
        VOID_INTERCEPTIONS.incrementAndGet();
        return ret;
    }
}
 
Example #6
Source File: Statisticalnterceptor.java    From Java-EE-8-Design-Patterns-and-Best-Practices with MIT License 6 votes vote down vote up
@AroundInvoke
public Object statisticMethod (InvocationContext invocationContext) throws Exception{
	System.out.println("Statistical method : "
			+ invocationContext.getMethod().getName() + " " 
			+ invocationContext.getMethod().getDeclaringClass()
			);
	
	// get the enrollment:
	TestRevisionTO testRevisionTO = (TestRevisionTO)invocationContext.getParameters()[0];
	
	System.out.println("Enrolment : " + testRevisionTO.getEnrollment());
	
	// event.fireAsync (testRevisionTO.getEnrollment());// fire an async statistical event. This is new in JEE8.
	event.fire (testRevisionTO.getEnrollment());
	
	Object o =  invocationContext.proceed();
	return o;
}
 
Example #7
Source File: CacheInvalidateInterceptor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Object key = null;
    for (CacheInvalidateInterceptorBinding binding : getInterceptorBindings(context,
            CacheInvalidateInterceptorBinding.class)) {
        if (key == null) {
            key = buildCacheKey(binding.cacheName(), binding.cacheKeyParameterPositions(), context.getParameters());
        }
        CaffeineCache cache = cacheRepository.getCache(binding.cacheName());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debugf("Invalidating entry with key [%s] from cache [%s]", key, cache.getName());
        }
        cache.invalidate(key);
    }
    return context.proceed();
}
 
Example #8
Source File: SimpleInterceptor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
Object mySuperCoolAroundInvoke(InvocationContext ctx) throws Exception {
    Object bindings = ctx.getContextData().get(ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS);
    if (bindings == null) {
        throw new IllegalArgumentException("No bindings found");
    }
    return "" + counter.get() + ctx.proceed() + counter.incrementAndGet();
}
 
Example #9
Source File: RestMetricsInterceptor.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    if (!init) {
        init(); // @PostConstruct causes MethodNotFound ex.
    }
    counter.inc();
    gauge.inc();
    Timer.Context time = timer.time();
    try {
        return context.proceed();
    } finally {
        time.stop();
        gauge.dec();
    }
}
 
Example #10
Source File: PersistenceExceptionLivenessInterceptor.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    try {
        return context.proceed();
    } catch (Exception ex) {
        Set<Class<? extends Exception>> ignored = RegistryExceptionMapper.getIgnored();
        if (!ignored.contains(ex.getClass())) { // suspect and rethrow unless ignored
            check.suspectWithException(ex);
        }
        throw ex;
    }
}
 
Example #11
Source File: LoggedInterceptor.java    From Java-EE-8-Design-Patterns-and-Best-Practices with MIT License 5 votes vote down vote up
@AroundInvoke
public Object logMethod (InvocationContext invocationContext) throws Exception{
	System.out.println("Entering method : "
			+ invocationContext.getMethod().getName() + " " 
			+ invocationContext.getMethod().getDeclaringClass()
			);
	Object o =  invocationContext.proceed();
	return o;
}
 
Example #12
Source File: LoggedInterceptor.java    From Java-EE-8-Design-Patterns-and-Best-Practices with MIT License 5 votes vote down vote up
@AroundInvoke
public Object logMethod (InvocationContext invocationContext) throws Exception{
	System.out.println("Entering method : "
			+ invocationContext.getMethod().getName() + " " 
			+ invocationContext.getMethod().getDeclaringClass()
			);
	Object o =  invocationContext.proceed();
	return o;
}
 
Example #13
Source File: SecurePaymentInterceptor.java    From blog-tutorials with MIT License 5 votes vote down vote up
@AroundInvoke
public Object securePayment(InvocationContext invocationContext) throws Exception {

    String requiredHttpHeader = invocationContext
            .getMethod()
            .getAnnotation(SecurePayment.class)
            .requiredHttpHeader();

    if (headers.getRequestHeaders().containsKey(requiredHttpHeader)) {
        return invocationContext.proceed();
    } else {
        throw new WebApplicationException("Missing HTTP header: " + requiredHttpHeader, Response.Status.BAD_REQUEST);
    }

}
 
Example #14
Source File: WebsocketSecurityInterceptor.java    From datawave with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
    Session session = findSessionParameter(ctx);
    if (session != null) {
        final Principal principal = (Principal) session.getUserProperties().get(SESSION_PRINCIPAL);
        final Subject subject = (Subject) session.getUserProperties().get(SESSION_SUBJECT);
        final Object credential = session.getUserProperties().get(SESSION_CREDENTIAL);
        
        if (principal != null && subject != null) {
            setSubjectInfo(principal, subject, credential);
        }
    }
    
    return ctx.proceed();
}
 
Example #15
Source File: PaymentManipulationInterceptor.java    From blog-tutorials with MIT License 5 votes vote down vote up
@AroundInvoke
public Object manipulatePayment(InvocationContext invocationContext) throws Exception {

    if (invocationContext.getParameters()[0] instanceof String) {
        if (((String) invocationContext.getParameters()[0]).equalsIgnoreCase("duke")) {
            paymentManipulator.manipulatePayment();
            invocationContext.setParameters(new Object[]{
                    "Duke", new BigDecimal(999.99).setScale(2, RoundingMode.HALF_UP)
            });
        }
    }

    return invocationContext.proceed();
}
 
Example #16
Source File: ValidationInterceptor.java    From krazo with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object validateMethodInvocation(InvocationContext ctx) throws Exception {

    Object resource = ctx.getTarget();
    Method method = ctx.getMethod();

    log.log(Level.FINE, "Starting validation for controller method: {0}#{1}", new Object[]{
            resource.getClass().getName(), method.getName()
    });

    Validator validator = validatorFactory.getValidator();
    ExecutableValidator executableValidator = validator.forExecutables();

    // validate controller property parameters
    processViolations(ctx,
            validator.validate(resource)
    );

    // validate controller method parameters
    processViolations(ctx,
            executableValidator.validateParameters(resource, method, ctx.getParameters())
    );

    // execute method
    Object result = ctx.proceed();

    // TODO: Does this make sense? Nobody will be able to handle these. Remove?
    processViolations(ctx,
            executableValidator.validateReturnValue(resource, method, result)
    );

    return result;

}
 
Example #17
Source File: ActivateRequestContextInterceptor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
Object aroundInvoke(InvocationContext ctx) throws Exception {
    ManagedContext requestContext = Arc.container().requestContext();
    if (requestContext.isActive()) {
        return ctx.proceed();
    } else {
        try {
            requestContext.activate();
            return ctx.proceed();
        } finally {
            requestContext.terminate();
        }
    }
}
 
Example #18
Source File: CacheInvalidateAllInterceptor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    for (CacheInvalidateAllInterceptorBinding binding : getInterceptorBindings(context,
            CacheInvalidateAllInterceptorBinding.class)) {
        CaffeineCache cache = cacheRepository.getCache(binding.cacheName());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debugf("Invalidating all entries from cache [%s]", cache.getName());
        }
        cache.invalidateAll();
    }
    return context.proceed();
}
 
Example #19
Source File: CacheResultInterceptor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    CacheResultInterceptorBinding binding = getInterceptorBinding(context, CacheResultInterceptorBinding.class);
    Object key = buildCacheKey(binding.cacheName(), binding.cacheKeyParameterPositions(), context.getParameters());
    CaffeineCache cache = cacheRepository.getCache(binding.cacheName());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debugf("Loading entry with key [%s] from cache [%s]", key, cache.getName());
    }
    return cache.get(key, () -> context.proceed(), binding.lockTimeout());
}
 
Example #20
Source File: AsyncContinuationTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
Object around(InvocationContext ctx) throws Exception {
    executor.submit(() -> {
        try {
            asyncResult = ctx.proceed().toString();
            latch.countDown();
        } catch (Exception e) {
            throw new RuntimeException();
        }
    });
    return "dummy";
}
 
Example #21
Source File: JaxrsEndPointValidationInterceptor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
@Override
public Object validateMethodInvocation(InvocationContext ctx) throws Exception {
    try {
        return super.validateMethodInvocation(ctx);
    } catch (ConstraintViolationException e) {
        throw new ResteasyViolationExceptionImpl(e.getConstraintViolations(), getAccept(ctx.getMethod()));
    }
}
 
Example #22
Source File: ExceptionHandlingInterceptor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
Object intercept(InvocationContext ctx) throws Exception {
    if (ctx.getParameters()[0] == ExceptionHandlingCase.OTHER_EXCEPTIONS) {
        throw new MyOtherException();
    }
    return ctx.proceed();
}
 
Example #23
Source File: CompleteTaskInterceptor.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
  try {
    Object result = ctx.proceed();

    CompleteTask completeTaskAnnotation = ctx.getMethod().getAnnotation(CompleteTask.class);
    boolean endConversation = completeTaskAnnotation.endConversation();
    businessProcess.completeTask(endConversation);

    return result;
  } catch (InvocationTargetException e) {
    throw new ActivitiCdiException("Error while completing task: " + e.getCause().getMessage(), e.getCause());
  }
}
 
Example #24
Source File: PersistenceTimeoutReadinessInterceptor.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Instant start = Instant.now();
    Object result = context.proceed();
    if (start.plus(check.getTimeoutSec()).isBefore(Instant.now())) {
        check.suspectSuper();
    }
    return result;
}
 
Example #25
Source File: MethodValidationInterceptor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
@Override
public Object validateMethodInvocation(InvocationContext ctx) throws Exception {
    return super.validateMethodInvocation(ctx);
}
 
Example #26
Source File: OkInterceptor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
Object aroundInvoke(InvocationContext ctx) throws Exception {
    return "OK";
}
 
Example #27
Source File: RolesAllowedInterceptor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception {
    return handler.handle(ic);
}
 
Example #28
Source File: TransactionalInterceptorSupports.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception {
    return super.intercept(ic);
}
 
Example #29
Source File: BindingDefaultValueTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
Object mySuperCoolAroundInvoke(InvocationContext ctx) throws Exception {
    return ctx.proceed() + "::alpha";
}
 
Example #30
Source File: AuthenticatedInterceptor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception {
    return handler.handle(ic);
}