Search in sources :

Example 26 with SystemException

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

the class SimplePassivater method activate.

@Override
public Object activate(final Object primaryKey) throws SystemException {
    try {
        final String filename = primaryKey.toString().replace(':', '=');
        final File sessionFile = new File(sessionDirectory, filename);
        if (sessionFile.exists()) {
            logger.info("Activating from file " + sessionFile);
            try (final InputStream source = IO.read(sessionFile);
                final ObjectInputStream ois = new ObjectInputStreamFiltered(source)) {
                final Object state = ois.readObject();
                if (!sessionFile.delete()) {
                    sessionFile.deleteOnExit();
                }
                return state;
            }
        } else {
            logger.info("Activation failed: file not found " + sessionFile);
            return null;
        }
    } catch (final Exception t) {
        logger.info("Activation failed ", t);
        throw new SystemException(t);
    }
}
Also used : SystemException(org.apache.openejb.SystemException) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ObjectInputStreamFiltered(org.apache.openejb.core.ObjectInputStreamFiltered) File(java.io.File) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(org.apache.openejb.SystemException) ObjectInputStream(java.io.ObjectInputStream)

Example 27 with SystemException

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

the class MdbContainer method afterDelivery.

public void afterDelivery(final Object instance) throws SystemException {
    // get the mdb call context
    final ThreadContext callContext = ThreadContext.getThreadContext();
    final MdbCallContext mdbCallContext = callContext.get(MdbCallContext.class);
    // invoke the tx after method
    try {
        afterInvoke(mdbCallContext.txPolicy, callContext);
    } catch (final ApplicationException e) {
        throw new SystemException("Should never get an Application exception", e);
    } finally {
        ThreadContext.exit(mdbCallContext.oldCallContext);
    }
}
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)

Example 28 with SystemException

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

the class MdbContainer 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);
        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) SystemException(org.apache.openejb.SystemException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) ThreadContext(org.apache.openejb.core.ThreadContext) Operation(org.apache.openejb.core.Operation) Method(java.lang.reflect.Method)

Example 29 with SystemException

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

the class MdbInstanceManager method poolInstance.

/**
 * All instances are removed from the pool in getInstance(...).  They are only
 * returned by the Container via this method under two circumstances.
 * <p/>
 * 1.  The business method returns normally
 * 2.  The business method throws an application exception
 * <p/>
 * Instances are not returned to the pool if the business method threw a system
 * exception.
 *
 * @param callContext ThreadContext
 * @param bean        Object
 * @throws OpenEJBException
 */
public void poolInstance(final ThreadContext callContext, final Object bean) throws OpenEJBException {
    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();
    final Pool<Instance> pool = data.getPool();
    if (instance.getPoolEntry() != null) {
        pool.push(instance.getPoolEntry());
    } else {
        pool.push(instance);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) SystemException(org.apache.openejb.SystemException) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData)

Example 30 with SystemException

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

the class PoolEndpointHandler method beforeDelivery.

@Override
public void beforeDelivery(final Method method) throws ApplicationServerInternalException {
    // verify current state
    switch(state) {
        case RELEASED:
            throw new IllegalStateException("Message endpoint factory has been released");
        case BEFORE_CALLED:
            throw new IllegalStateException("beforeDelivery can not be called again until message is delivered and afterDelivery is called");
        case METHOD_CALLED:
        case SYSTEM_EXCEPTION:
            throw new IllegalStateException("The last message delivery must be completed with an afterDeliver before beforeDeliver can be called again");
    }
    // call beforeDelivery on the container
    try {
        instance = instanceManager.getInstance(new ThreadContext(deployment, null));
        container.beforeDelivery(deployment, instance, method, xaResource);
    } catch (final SystemException se) {
        final Throwable throwable = se.getRootCause() != null ? se.getRootCause() : se;
        throw new ApplicationServerInternalException(throwable);
    } catch (OpenEJBException oe) {
        throw new ApplicationServerInternalException(oe);
    }
    // before completed successfully we are now ready to invoke bean
    state = State.BEFORE_CALLED;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) SystemException(org.apache.openejb.SystemException) ThreadContext(org.apache.openejb.core.ThreadContext) ApplicationServerInternalException(javax.resource.spi.ApplicationServerInternalException)

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