Java Code Examples for javax.interceptor.InvocationContext#proceed()

The following examples show how to use javax.interceptor.InvocationContext#proceed() . 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: 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 2
Source File: PayloadExtractor.java    From training with MIT License 6 votes vote down vote up
@AroundInvoke
public Object onMessage(InvocationContext invocation) throws Exception {
	Object mdb = invocation.getTarget();

	if (invocation.getMethod().getName().equals("onMessage")) {
		Message message = (Message) invocation.getParameters()[0];
		try {
			Object payload = extractPayload(message);
			invokeConsumeMethod(mdb, payload);
		} catch (Exception e) {
			System.out.println("Report error: sending message to dead letter");
			e.printStackTrace();
			deadLetterSender.sendDeadLetter(message, e.getMessage(), e);
		}
	}
	return invocation.proceed();
}
 
Example 3
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 4
Source File: StatefulInterceptorTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object invoke(final InvocationContext context) throws Exception {
    calls.add(Call.Class_Invoke_BEFORE);
    final Object o = context.proceed();
    calls.add(Call.Class_Invoke_AFTER);
    return o;
}
 
Example 5
Source File: Breakr.java    From breakr with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object guard(InvocationContext ic) throws Exception {
    long maxFailures = IgnoreCallsWhen.MAX_FAILURES;
    long maxDuration = IgnoreCallsWhen.TIMEOUT;
    Method method = ic.getMethod();

    boolean closeCircuit = method.isAnnotationPresent(CloseCircuit.class);
    if (closeCircuit) {
        this.circuit.reset();
    }

    IgnoreCallsWhen configuration = method.
            getAnnotation(IgnoreCallsWhen.class);
    if (configuration != null) {
        maxFailures = configuration.failures();
        maxDuration = configuration.slowerThanMillis();
    }
    long start = System.currentTimeMillis();

    try {
        if (circuit.isOpen(maxFailures)) {
            return null;
        }
        return ic.proceed();
    } catch (Exception ex) {
        circuit.newException(ex);
        throw ex;
    } finally {
        long duration = System.currentTimeMillis() - start;
        if (duration > maxDuration) {
            this.circuit.newTimeout(duration);
        }
    }
}
 
Example 6
Source File: JaxRpcInvocationTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object invoke(final InvocationContext context) throws Exception {
    // Track this call so we can assert proper interceptor order
    calls.add(Call.EjbInterceptor_Invoke_BEFORE);
    final Object o = context.proceed();
    calls.add(Call.EjbInterceptor_Invoke_AFTER);
    return o;
}
 
Example 7
Source File: BookForAShowLoggingInterceptor.java    From tomee with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object logMethodEntry(InvocationContext ctx) throws Exception {
    logger.info("Before entering method:" + ctx.getMethod().getName());
    InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
    InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
    return ctx.proceed();
}
 
Example 8
Source File: JaxWsInvocationTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@AroundInvoke
public Object invoke(final InvocationContext context) throws Exception {

    /**
     * For JAX-WS invocations context.getContextData() must return the 
     * JAX-WS MessageContex. As per the agreement between OpenEJB and the Web Service Provider
     * the MessageContex should have been passed into the container.invoke method
     * and the container should then ensure it's available via getContextData()
     * for the duration of this call.
     */
    final MessageContext messageContext = (MessageContext) context.getContextData();

    org.junit.Assert.assertNotNull("message context should not be null", messageContext);
    org.junit.Assert.assertTrue("the Web Service Provider's message context should be used", messageContext instanceof FakeMessageContext);

    // Try to get JAX-RPC context, should throw an exception since it's JAX-WS
    try {
        ctx.getMessageContext();
        org.junit.Assert.fail("Did not throw exception");
    } catch (final IllegalStateException e) {
        // that's expected since it's JAX-WS
    }

    // test @Resource WebServiceContext injection
    org.junit.Assert.assertNotNull("web service context should not be null", wsContext);
    org.junit.Assert.assertEquals("msg context should be the smae", messageContext, wsContext.getMessageContext());

    org.junit.Assert.assertFalse("user in role 'foo'", wsContext.isUserInRole("foo"));
    org.junit.Assert.assertNotNull("user principal", wsContext.getUserPrincipal());

    calls.add(Call.Bean_Invoke_BEFORE);
    final Object o = context.proceed();
    calls.add(Call.Bean_Invoke_AFTER);
    return o;
}
 
Example 9
Source File: StatefulInterceptorTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void construct(final InvocationContext context) throws Exception {
    calls.add(Call.Default_PostConstruct_BEFORE);
    context.proceed();
    calls.add(Call.Default_PostConstruct_AFTER);
}
 
Example 10
Source File: StatefulSessionSynchronizationTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AfterCompletion
public void afterComplete(final InvocationContext invocationContext) throws Exception {
    result.add(Call.INTERCEPTOR_AFTER_COMPLETION);
    invocationContext.proceed();
}
 
Example 11
Source File: AroundConstructTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundConstruct
void mySuperCoolAroundConstruct(InvocationContext ctx) throws Exception {
    INTERCEPTOR_CALLED.set(true);
    ctx.proceed();
}
 
Example 12
Source File: PrivateInterceptorMethodTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
private Object mySuperCoolAroundInvoke(InvocationContext ctx) throws Exception {
    return "private" + ctx.proceed();
}
 
Example 13
Source File: ContainerManagedTransactionStrategy.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(InvocationContext invocationContext) throws Exception
{
    return invocationContext.proceed();
}
 
Example 14
Source File: AddInterceptor.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object invoke(InvocationContext context) throws Exception {
    // Log Add
    return context.proceed();
}
 
Example 15
Source File: SubclassConstructorGuardTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
Object mySuperCoolAroundInvoke(InvocationContext ctx) throws Exception {
    return "foo" + "::" + ctx.proceed();
}
 
Example 16
Source File: CalculatorBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
    ExecutionChannel.getInstance().notifyObservers(ctx.getMethod().getName());
    return ctx.proceed();
}
 
Example 17
Source File: BravoInterceptor.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object aroundInvoke(InvocationContext ctx) throws Exception {
    return "B:" + ctx.proceed() + ":B";
}
 
Example 18
Source File: EarlyFtInterceptor.java    From microprofile-fault-tolerance with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
    orderFactory.getOrderQueue().add("EarlyOrderFtInterceptor");
    return ctx.proceed();
}
 
Example 19
Source File: BasicStatelessInterceptedBean.java    From tomee with Apache License 2.0 3 votes vote down vote up
/**
 * The interceptor method.
 * This should intercept all business methods in this bean class.
 * It cannot exclude even those annotated with <code>@ExcludeClassInterceptors</code>
 *
 * @param ctx - InvocationContext
 * @return - the result of the next method invoked. If a method returns void, proceed returns null.
 * For lifecycle callback interceptor methods, if there is no callback method defined on the bean class,
 * the invocation of proceed in the last interceptor method in the chain is a no-op, and null is returned.
 * If there is more than one such interceptor method, the invocation of proceed causes the container to execute those methods in order.
 * @throws Exception runtime exceptions or application exceptions that are allowed in the throws clause of the business method.
 */
@AroundInvoke
public Object inBeanInterceptor(final InvocationContext ctx) throws Exception {
    final Map<String, Object> ctxData = Interceptor.profile(ctx, "inBeanInterceptor");
    setContextData(ctxData);
    return ctx.proceed();
}
 
Example 20
Source File: DefaultInterceptor.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * The interceptor method.
 * This should intercept postActivate of the bean
 *
 * @param ctx - InvocationContext
 * @throws Exception runtime exceptions.
 */
@PostActivate
public void defaultInterceptorPostActivate(final InvocationContext ctx) throws Exception {
    Interceptor.profile(ctx, "defaultInterceptorPostActivate");
    ctx.proceed();
}