Search in sources :

Example 11 with SystemException

use of org.apache.openejb.SystemException in project tomee by apache.

the class MdbContainer method beforeDelivery.

public void beforeDelivery(final BeanContext deployInfo, final Object instance, final Method method, final XAResource xaResource) throws SystemException {
    // intialize call context
    final ThreadContext callContext = new ThreadContext(deployInfo, null);
    final ThreadContext oldContext = ThreadContext.enter(callContext);
    // create mdb context
    final MdbCallContext mdbCallContext = new MdbCallContext();
    callContext.set(MdbCallContext.class, mdbCallContext);
    mdbCallContext.deliveryMethod = method;
    mdbCallContext.oldCallContext = oldContext;
    // call the tx before method
    try {
        mdbCallContext.txPolicy = createTransactionPolicy(deployInfo.getTransactionType(method), callContext);
        // if we have an xaResource and a transaction was not imported from the adapter, enlist the xaResource
        if (xaResource != null && mdbCallContext.txPolicy.isNewTransaction()) {
            mdbCallContext.txPolicy.enlistResource(xaResource);
        }
    } catch (final ApplicationException e) {
        ThreadContext.exit(oldContext);
        throw new SystemException("Should never get an Application exception", e);
    } catch (final SystemException e) {
        ThreadContext.exit(oldContext);
        throw e;
    } catch (final Exception e) {
        ThreadContext.exit(oldContext);
        throw new SystemException("Unable to enlist xa resource in the transaction", e);
    }
}
Also used : EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) ApplicationException(org.apache.openejb.ApplicationException) SystemException(org.apache.openejb.SystemException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) ThreadContext(org.apache.openejb.core.ThreadContext) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ReflectionException(javax.management.ReflectionException) OpenEJBException(org.apache.openejb.OpenEJBException) UnavailableException(javax.resource.spi.UnavailableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedObjectNameException(javax.management.MalformedObjectNameException) SystemException(org.apache.openejb.SystemException) AttributeNotFoundException(javax.management.AttributeNotFoundException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) ApplicationException(org.apache.openejb.ApplicationException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ConstraintViolationException(javax.validation.ConstraintViolationException)

Example 12 with SystemException

use of org.apache.openejb.SystemException in project tomee by apache.

the class MdbContainer method invoke.

public Object invoke(final Object deploymentId, final InterfaceType type, final Class callInterface, final Method method, final Object[] args, final Object primKey) throws OpenEJBException {
    final BeanContext beanContext = getBeanContext(deploymentId);
    final EndpointFactory endpointFactory = (EndpointFactory) beanContext.getContainerData();
    final MdbInstanceFactory instanceFactory = endpointFactory.getInstanceFactory();
    final Instance instance;
    try {
        instance = (Instance) instanceFactory.createInstance(true);
    } catch (final UnavailableException e) {
        throw new SystemException("Unable to create instance for invocation", e);
    }
    try {
        beforeDelivery(beanContext, instance, method, null);
        final Object value = invoke(instance, method, type, args);
        afterDelivery(instance);
        return value;
    } finally {
        instanceFactory.freeInstance(instance, true);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) SystemException(org.apache.openejb.SystemException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) SystemInstance(org.apache.openejb.loader.SystemInstance) UnavailableException(javax.resource.spi.UnavailableException)

Example 13 with SystemException

use of org.apache.openejb.SystemException in project tomee by apache.

the class MdbInstanceManager method discardInstance.

/**
 * This method is called to release the semaphore in case of the business method
 * throwing a system exception
 *
 * @param callContext ThreadContext
 * @param bean        Object
 */
public void discardInstance(final ThreadContext callContext, final Object bean) throws SystemException {
    if (bean == null) {
        throw new SystemException("Invalid arguments");
    }
    final Instance instance = Instance.class.cast(bean);
    final BeanContext beanContext = callContext.getBeanContext();
    final Data data = (Data) beanContext.getContainerData();
    if (null != data) {
        final Pool<Instance> pool = data.getPool();
        pool.discard(instance.getPoolEntry());
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) SystemException(org.apache.openejb.SystemException) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData)

Example 14 with SystemException

use of org.apache.openejb.SystemException in project tomee by apache.

the class MdbPoolContainer method invoke.

public Object invoke(final Object instance, final Method method, final InterfaceType type, Object... args) throws SystemException, ApplicationException {
    if (args == null) {
        args = NO_ARGS;
    }
    // get the context data
    final ThreadContext callContext = ThreadContext.getThreadContext();
    final BeanContext deployInfo = callContext.getBeanContext();
    final MdbCallContext mdbCallContext = callContext.get(MdbCallContext.class);
    if (mdbCallContext == null) {
        throw new IllegalStateException("beforeDelivery was not called");
    }
    // verify the delivery method passed to beforeDeliver is the same method that was invoked
    if (!mdbCallContext.deliveryMethod.getName().equals(method.getName()) || !Arrays.deepEquals(mdbCallContext.deliveryMethod.getParameterTypes(), method.getParameterTypes())) {
        throw new IllegalStateException("Delivery method specified in beforeDelivery is not the delivery method called");
    }
    // remember the return value or exception so it can be logged
    Object returnValue = null;
    OpenEJBException openEjbException = null;
    final Operation oldOperation = callContext.getCurrentOperation();
    callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
    try {
        if (logger.isDebugEnabled()) {
            logger.info("invoking method " + method.getName() + " on " + deployInfo.getDeploymentID());
        }
        // determine the target method on the bean instance class
        final Method targetMethod = deployInfo.getMatchingBeanMethod(method);
        callContext.set(Method.class, targetMethod);
        // invoke the target method
        returnValue = _invoke(instance, targetMethod, args, deployInfo, type, mdbCallContext, callContext);
        return returnValue;
    } catch (final ApplicationException | SystemException e) {
        openEjbException = e;
        throw e;
    } finally {
        callContext.setCurrentOperation(oldOperation);
        // Log the invocation results
        if (logger.isDebugEnabled()) {
            if (openEjbException == null) {
                logger.debug("finished invoking method " + method.getName() + ". Return value:" + returnValue);
            } else {
                final Throwable exception = openEjbException.getRootCause() != null ? openEjbException.getRootCause() : openEjbException;
                logger.debug("finished invoking method " + method.getName() + " with exception " + exception);
            }
        }
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) OpenEJBException(org.apache.openejb.OpenEJBException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) ApplicationException(org.apache.openejb.ApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) SystemException(org.apache.openejb.SystemException) ThreadContext(org.apache.openejb.core.ThreadContext) Operation(org.apache.openejb.core.Operation) Method(java.lang.reflect.Method)

Example 15 with SystemException

use of org.apache.openejb.SystemException in project tomee by apache.

the class MdbPoolContainer method beforeDelivery.

public void beforeDelivery(final BeanContext deployInfo, final Object instance, final Method method, final XAResource xaResource) throws SystemException {
    // intialize call context
    final ThreadContext callContext = new ThreadContext(deployInfo, null);
    final ThreadContext oldContext = ThreadContext.enter(callContext);
    // create mdb context
    final MdbCallContext mdbCallContext = new MdbCallContext();
    callContext.set(MdbCallContext.class, mdbCallContext);
    mdbCallContext.deliveryMethod = method;
    mdbCallContext.oldCallContext = oldContext;
    // call the tx before method
    try {
        mdbCallContext.txPolicy = createTransactionPolicy(deployInfo.getTransactionType(method), callContext);
        // if we have an xaResource and a transaction was not imported from the adapter, enlist the xaResource
        if (xaResource != null && mdbCallContext.txPolicy.isNewTransaction()) {
            mdbCallContext.txPolicy.enlistResource(xaResource);
        }
    } catch (final ApplicationException e) {
        ThreadContext.exit(oldContext);
        throw new SystemException("Should never get an Application exception", e);
    } catch (final SystemException e) {
        ThreadContext.exit(oldContext);
        throw e;
    } catch (final Exception e) {
        ThreadContext.exit(oldContext);
        throw new SystemException("Unable to enlist xa resource in the transaction", e);
    }
}
Also used : EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) ApplicationException(org.apache.openejb.ApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) SystemException(org.apache.openejb.SystemException) ThreadContext(org.apache.openejb.core.ThreadContext) ResourceException(javax.resource.ResourceException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) NamingException(javax.naming.NamingException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConstraintViolationException(javax.validation.ConstraintViolationException) SystemException(org.apache.openejb.SystemException)

Aggregations

SystemException (org.apache.openejb.SystemException)37 ApplicationException (org.apache.openejb.ApplicationException)16 OpenEJBException (org.apache.openejb.OpenEJBException)12 BeanContext (org.apache.openejb.BeanContext)10 EjbTransactionUtil.handleSystemException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException)9 RemoteException (java.rmi.RemoteException)7 ThreadContext (org.apache.openejb.core.ThreadContext)7 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)7 InvalidateReferenceException (org.apache.openejb.InvalidateReferenceException)6 Operation (org.apache.openejb.core.Operation)6 EJBException (javax.ejb.EJBException)5 NamingException (javax.naming.NamingException)5 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)5 File (java.io.File)4 IOException (java.io.IOException)4 NotSerializableException (java.io.NotSerializableException)4 RandomAccessFile (java.io.RandomAccessFile)4 EJBAccessException (javax.ejb.EJBAccessException)4 UnavailableException (javax.resource.spi.UnavailableException)4 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)4