Search in sources :

Example 21 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class MessageDrivenComponentDescription method setupViewInterceptors.

@Override
protected void setupViewInterceptors(EJBViewDescription view) {
    // let the super do its job
    super.setupViewInterceptors(view);
    view.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            //add the invocation type to the start of the chain
            //TODO: is there a cleaner way to do this?
            configuration.addViewInterceptor(new ImmediateInterceptorFactory(new Interceptor() {

                @Override
                public Object processInvocation(final InterceptorContext context) throws Exception {
                    context.putPrivateData(InvocationType.class, InvocationType.MESSAGE_DELIVERY);
                    return context.proceed();
                }
            }), InterceptorOrder.View.INVOCATION_TYPE);
            // add the instance associating interceptor at the start of the interceptor chain
            configuration.addViewInterceptor(MessageDrivenComponentInstanceAssociatingFactory.instance(), InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
            final MessageDrivenComponentDescription mdb = (MessageDrivenComponentDescription) componentConfiguration.getComponentDescription();
            if (mdb.getTransactionManagementType() == TransactionManagementType.CONTAINER) {
                configuration.addViewInterceptor(CMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) InterceptorContext(org.jboss.invocation.InterceptorContext) CurrentInvocationContextInterceptor(org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor) Interceptor(org.jboss.invocation.Interceptor) LifecycleCMTTxInterceptor(org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor) TimerCMTTxInterceptor(org.jboss.as.ejb3.tx.TimerCMTTxInterceptor) CMTTxInterceptor(org.jboss.as.ejb3.tx.CMTTxInterceptor) EjbBMTInterceptor(org.jboss.as.ejb3.tx.EjbBMTInterceptor)

Example 22 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class CurrentInvocationContext method getEjbContext.

public static EJBContextImpl getEjbContext() {
    final InterceptorContext context = get();
    if (context == null) {
        throw EjbLogger.ROOT_LOGGER.noEjbContextAvailable();
    }
    final ComponentInstance component = context.getPrivateData(ComponentInstance.class);
    if (!(component instanceof EjbComponentInstance)) {
        throw EjbLogger.ROOT_LOGGER.currentComponentNotAEjb(component);
    }
    return ((EjbComponentInstance) component).getEjbContext();
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) EjbComponentInstance(org.jboss.as.ejb3.component.EjbComponentInstance) EjbComponentInstance(org.jboss.as.ejb3.component.EjbComponentInstance)

Example 23 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class NonFunctionalTimerService method assertInvocationAllowed.

private void assertInvocationAllowed() {
    AllowedMethodsInformation.checkAllowed(MethodType.TIMER_SERVICE_METHOD);
    final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
    if (currentInvocationContext == null) {
        return;
    }
    // If the method in current invocation context is null,
    // then it represents a lifecycle callback invocation
    Method invokedMethod = currentInvocationContext.getMethod();
    if (invokedMethod == null) {
        // it's a lifecycle callback
        Component component = currentInvocationContext.getPrivateData(Component.class);
        if (!(component instanceof SingletonComponent)) {
            throw EjbLogger.EJB3_TIMER_LOGGER.failToInvokeTimerServiceDoLifecycle();
        }
    }
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) SingletonComponent(org.jboss.as.ejb3.component.singleton.SingletonComponent) Method(java.lang.reflect.Method) SingletonComponent(org.jboss.as.ejb3.component.singleton.SingletonComponent) Component(org.jboss.as.ee.component.Component)

Example 24 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class TimedObjectInvokerImpl method callTimeout.

@Override
public void callTimeout(final TimerImpl timer, final Method timeoutMethod) throws Exception {
    final Interceptor interceptor;
    synchronized (this) {
        if (!started) {
            //this can happen if an invocation has been triggered as the deployment is shutting down
            throw EjbLogger.EJB3_TIMER_LOGGER.timerInvocationFailedDueToInvokerNotBeingStarted();
        }
        interceptor = timeoutInterceptors.get(timeoutMethod);
    }
    if (interceptor == null) {
        throw EjbLogger.EJB3_TIMER_LOGGER.failToInvokeTimeout(timeoutMethod);
    }
    final InterceptorContext context = new InterceptorContext();
    context.setContextData(new HashMap<String, Object>());
    context.setMethod(timeoutMethod);
    if (timeoutMethod.getParameterTypes().length == 0) {
        context.setParameters(new Object[0]);
    } else {
        final Object[] params = new Object[1];
        params[0] = timer;
        context.setParameters(params);
    }
    context.setTimer(timer);
    context.putPrivateData(Component.class, ejbComponent.getValue());
    context.putPrivateData(MethodIntf.class, MethodIntf.TIMER);
    context.putPrivateData(InvocationType.class, InvocationType.TIMER);
    interceptor.processInvocation(context);
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) Interceptor(org.jboss.invocation.Interceptor)

Example 25 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class TimerServiceImpl method isLifecycleCallbackInvocation.

/**
     * Returns true if the {@link CurrentInvocationContext} represents a lifecycle
     * callback invocation. Else returns false.
     * <p>
     * This method internally relies on {@link CurrentInvocationContext#get()} to obtain
     * the current invocation context.
     * <ul>
     * <li>If the context is available then it looks for the method that was invoked.
     * The absence of a method indicates a lifecycle callback.</li>
     * <li>If the context is <i>not</i> available, then this method returns false (i.e.
     * it doesn't consider the current invocation as a lifecycle callback). This is
     * for convenience, to allow the invocation of {@link javax.ejb.TimerService} methods
     * in the absence of {@link CurrentInvocationContext}</li>
     * </ul>
     * <p/>
     * </p>
     *
     * @return
     */
protected boolean isLifecycleCallbackInvocation() {
    final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
    if (currentInvocationContext == null) {
        return false;
    }
    // If the method in current invocation context is null,
    // then it represents a lifecycle callback invocation
    Method invokedMethod = currentInvocationContext.getMethod();
    if (invokedMethod == null) {
        // it's a lifecycle callback
        return true;
    }
    // not a lifecycle callback
    return false;
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) Method(java.lang.reflect.Method)

Aggregations

InterceptorContext (org.jboss.invocation.InterceptorContext)29 Interceptor (org.jboss.invocation.Interceptor)8 Method (java.lang.reflect.Method)4 Component (org.jboss.as.ee.component.Component)4 ComponentView (org.jboss.as.ee.component.ComponentView)4 ManagedReference (org.jboss.as.naming.ManagedReference)4 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)3 SessionBeanComponent (org.jboss.as.ejb3.component.session.SessionBeanComponent)3 SecurityContext (org.jboss.security.SecurityContext)3 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)3 PrivilegedAction (java.security.PrivilegedAction)2 HashMap (java.util.HashMap)2 ComponentFactory (org.jboss.as.ee.component.ComponentFactory)2 StartupCountdown (org.jboss.as.ee.component.deployers.StartupCountdown)2 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)2 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)2 CancellationFlag (org.jboss.as.ejb3.component.interceptors.CancellationFlag)2 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)2 SkeletonStrategy (org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy)2 ObjectStreamException (java.io.ObjectStreamException)1