Search in sources :

Example 31 with SystemException

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

the class PoolEndpointHandler method afterDelivery.

public void afterDelivery() throws ApplicationServerInternalException, UnavailableException {
    // verify current state
    switch(state) {
        case RELEASED:
            throw new IllegalStateException("Message endpoint factory has been released");
        case NONE:
            throw new IllegalStateException("afterDelivery may only be called if message delivery began with a beforeDelivery call");
    }
    // call afterDelivery on the container
    try {
        container.afterDelivery(instance);
    } catch (final SystemException se) {
        final Throwable throwable = se.getRootCause() != null ? se.getRootCause() : se;
        throw new ApplicationServerInternalException(throwable);
    } finally {
        // we are now in the default NONE state
        state = State.NONE;
        this.instance = null;
    }
}
Also used : SystemException(org.apache.openejb.SystemException) ApplicationServerInternalException(javax.resource.spi.ApplicationServerInternalException)

Example 32 with SystemException

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

the class RAFPassivater method activate.

@Override
public synchronized Object activate(final Object primaryKey) throws SystemException {
    final Pointer pointer = (Pointer) masterTable.get(primaryKey);
    if (pointer == null) {
        return null;
    }
    try (final RandomAccessFile ras = new RandomAccessFile(JavaSecurityManagers.getSystemProperty("java.io.tmpdir", File.separator + "tmp") + File.separator + "passivation" + pointer.fileid + ".ser", "r")) {
        final byte[] bytes = new byte[pointer.bytesize];
        ras.seek(pointer.filepointer);
        ras.readFully(bytes);
        return Serializer.deserialize(bytes);
    } catch (final Exception e) {
        throw new SystemException(e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) SystemException(org.apache.openejb.SystemException) SystemException(org.apache.openejb.SystemException)

Example 33 with SystemException

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

the class SimplePassivater method passivate.

public void passivate(final Object primaryKey, final Object state) throws SystemException {
    try {
        final String filename = primaryKey.toString().replace(':', '=');
        final File sessionFile = new File(sessionDirectory, filename);
        logger.info("Passivating to file " + sessionFile);
        try (final OutputStream os = IO.write(sessionFile);
            final ObjectOutputStream oos = new ObjectOutputStream(os)) {
            // passivate just the bean instance
            oos.writeObject(state);
        } finally {
            sessionFile.deleteOnExit();
        }
    } catch (final NotSerializableException nse) {
        logger.error("Passivation failed ", nse);
        throw (SystemException) new SystemException("The type " + nse.getMessage() + " is not serializable as mandated by the EJB specification.").initCause(nse);
    } catch (final Exception t) {
        logger.error("Passivation failed ", t);
        throw new SystemException(t);
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) SystemException(org.apache.openejb.SystemException) OutputStream(java.io.OutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(org.apache.openejb.SystemException)

Example 34 with SystemException

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

the class LocalClientRunner method createDeployment.

private BeanContext createDeployment(final Class<?> testClass) {
    try {
        final AppContext appContext = new AppContext("", SystemInstance.get(), testClass.getClassLoader(), new IvmContext(), new IvmContext(), false);
        final ModuleContext moduleContext = new ModuleContext("", null, "", appContext, new IvmContext(), null);
        return new BeanContext(null, new IvmContext(), moduleContext, testClass, null, null, null, null, null, null, null, null, null, BeanType.MANAGED, false, false);
    } catch (final SystemException e) {
        throw new IllegalStateException(e);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) SystemException(org.apache.openejb.SystemException) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext)

Example 35 with SystemException

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

the class StatefulContainer method afterInvoke.

private void afterInvoke(final ThreadContext callContext, final TransactionPolicy txPolicy, final Instance instance) throws OpenEJBException {
    try {
        if (instance != null && txPolicy instanceof BeanTransactionPolicy) {
            // suspend the currently running transaction if any
            SuspendedTransaction suspendedTransaction = null;
            try {
                final BeanTransactionPolicy beanTxEnv = (BeanTransactionPolicy) txPolicy;
                suspendedTransaction = beanTxEnv.suspendUserTransaction();
            } catch (final SystemException e) {
                EjbTransactionUtil.handleSystemException(txPolicy, e, callContext);
            } finally {
                instance.setBeanTransaction(suspendedTransaction);
            }
        }
    } finally {
        if (instance != null) {
            instance.setInUse(false);
        }
        EjbTransactionUtil.afterInvoke(txPolicy, callContext);
        if (instance != null) {
            instance.releaseLock();
        }
    }
}
Also used : BeanTransactionPolicy(org.apache.openejb.core.transaction.BeanTransactionPolicy) SystemException(org.apache.openejb.SystemException) SuspendedTransaction(org.apache.openejb.core.transaction.BeanTransactionPolicy.SuspendedTransaction)

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