Search in sources :

Example 1 with Ejb2xViewType

use of org.jboss.as.ejb3.component.Ejb2xViewType in project wildfly by wildfly.

the class StatefulRemoveInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);
    //if a session bean is participating in a transaction, it
    //is an error for a client to invoke the remove method
    //on the session object's home or component interface.
    final ComponentView view = context.getPrivateData(ComponentView.class);
    if (view != null) {
        Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
        if (viewType != null) {
            //this means it is an EJB 2.x view
            //which is not allowed to remove while enrolled in a TX
            final StatefulTransactionMarker marker = context.getPrivateData(StatefulTransactionMarker.class);
            if (marker != null && !marker.isFirstInvocation()) {
                throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
            }
        }
    }
    // just log a WARN and throw back the original exception
    if (component instanceof StatefulSessionComponent == false) {
        throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
    }
    final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
    Object invocationResult = null;
    try {
        // proceed
        invocationResult = context.proceed();
    } catch (Exception e) {
        // then just throw back the exception and don't remove the session instance.
        if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod()) && this.retainIfException) {
            throw e;
        }
        // otherwise, just remove it and throw back the original exception
        final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
        final SessionID sessionId = statefulComponentInstance.getId();
        statefulComponent.removeSession(sessionId);
        throw e;
    }
    final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
    final SessionID sessionId = statefulComponentInstance.getId();
    // just remove the session because of a call to @Remove method
    statefulComponent.removeSession(sessionId);
    // return the invocation result
    return invocationResult;
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) Ejb2xViewType(org.jboss.as.ejb3.component.Ejb2xViewType) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) SessionID(org.jboss.ejb.client.SessionID)

Aggregations

Component (org.jboss.as.ee.component.Component)1 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)1 ComponentView (org.jboss.as.ee.component.ComponentView)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1 Ejb2xViewType (org.jboss.as.ejb3.component.Ejb2xViewType)1 SessionID (org.jboss.ejb.client.SessionID)1