Search in sources :

Example 6 with SystemException

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

the class ManagedContainer method afterInvoke.

private void afterInvoke(final ThreadContext callContext, final TransactionPolicy txPolicy, final Instance instance) throws OpenEJBException {
    try {
        unregisterEntityManagers(instance, callContext);
        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);
    }
}
Also used : BeanTransactionPolicy(org.apache.openejb.core.transaction.BeanTransactionPolicy) SystemException(org.apache.openejb.SystemException) SuspendedTransaction(org.apache.openejb.core.transaction.BeanTransactionPolicy.SuspendedTransaction)

Example 7 with SystemException

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

the class RAFPassivater method passivate.

public synchronized void passivate(final Map stateTable) throws SystemException {
    try (final RandomAccessFile ras = new RandomAccessFile(JavaSecurityManagers.getSystemProperty("java.io.tmpdir", File.separator + "tmp") + File.separator + "passivation" + fileID + ".ser", "rw")) {
        fileID++;
        final Iterator iterator = stateTable.keySet().iterator();
        Pointer lastPointer = null;
        while (iterator.hasNext()) {
            final Object id = iterator.next();
            final Object obj = stateTable.get(id);
            final byte[] bytes = Serializer.serialize(obj);
            final long filepointer = ras.getFilePointer();
            if (lastPointer == null) {
                lastPointer = new Pointer(fileID, filepointer, (int) filepointer);
            } else {
                lastPointer = new Pointer(fileID, filepointer, (int) (filepointer - lastPointer.filepointer));
            }
            masterTable.put(id, lastPointer);
            ras.write(bytes);
        }
    } catch (final Exception e) {
        throw new SystemException(e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) SystemException(org.apache.openejb.SystemException) Iterator(java.util.Iterator) SystemException(org.apache.openejb.SystemException)

Example 8 with SystemException

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

the class RAFPassivater method activate.

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);
        ras.close();
        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 9 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);
        if (!sessionFile.exists() && !sessionFile.createNewFile()) {
            throw new Exception("Failed to create passivation file: " + sessionFile.getAbsolutePath());
        }
        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 10 with SystemException

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

the class AbstractEndpointHandler method deliverMessage.

public Object deliverMessage(final Method method, final Object[] args) throws Throwable {
    boolean callBeforeAfter = false;
    // verify current state
    switch(state) {
        case NONE:
            try {
                beforeDelivery(method);
            } catch (final ApplicationServerInternalException e) {
                throw (EJBException) new EJBException().initCause(e.getCause());
            }
            callBeforeAfter = true;
            state = State.METHOD_CALLED;
            break;
        case BEFORE_CALLED:
            state = State.METHOD_CALLED;
            break;
        case RELEASED:
            throw new IllegalStateException("Message endpoint factory has been released");
        case METHOD_CALLED:
        case SYSTEM_EXCEPTION:
            throw new IllegalStateException("The last message delivery must be completed with an afterDeliver before another message can be delivered");
    }
    Throwable throwable = null;
    Object value = null;
    try {
        // deliver the message
        value = container.invoke(instance, method, null, wrapMessageForAmq5(args));
    } catch (final SystemException se) {
        throwable = se.getRootCause() != null ? se.getRootCause() : se;
        state = State.SYSTEM_EXCEPTION;
    } catch (final ApplicationException ae) {
        throwable = ae.getRootCause() != null ? ae.getRootCause() : ae;
    } finally {
        // if the adapter is not using before/after, we must call afterDelivery to clean up
        if (callBeforeAfter) {
            try {
                afterDelivery();
            } catch (final ApplicationServerInternalException e) {
                throwable = throwable == null ? e.getCause() : throwable;
            } catch (final UnavailableException e) {
                throwable = throwable == null ? e : throwable;
            }
        }
    }
    if (throwable != null) {
        if (isValidException(method, throwable)) {
            throw throwable;
        } else {
            throw new EJBException().initCause(throwable);
        }
    }
    return value;
}
Also used : ApplicationException(org.apache.openejb.ApplicationException) SystemException(org.apache.openejb.SystemException) UnavailableException(javax.resource.spi.UnavailableException) ApplicationServerInternalException(javax.resource.spi.ApplicationServerInternalException) EJBException(javax.ejb.EJBException)

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