Search in sources :

Example 11 with EJBException

use of javax.ejb.EJBException in project wildfly by wildfly.

the class StatefulSessionComponentInstance method execute.

private Object execute(final Interceptor interceptor, final Method method, final Object... parameters) {
    if (interceptor == null)
        return null;
    final InterceptorContext interceptorContext = new InterceptorContext();
    //we need the method so this does not count as a lifecycle invocation
    interceptorContext.setMethod(method);
    interceptorContext.putPrivateData(Component.class, getComponent());
    interceptorContext.putPrivateData(ComponentInstance.class, this);
    interceptorContext.putPrivateData(InvokeMethodOnTargetInterceptor.PARAMETERS_KEY, parameters);
    interceptorContext.setContextData(new HashMap<String, Object>());
    interceptorContext.setTarget(getInstance());
    final AbstractTransaction transaction = ContextTransactionManager.getInstance().getTransaction();
    interceptorContext.setTransactionSupplier(() -> transaction);
    try {
        return interceptor.processInvocation(interceptorContext);
    } catch (Error e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new EJBException(e);
    }
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) AbstractTransaction(org.wildfly.transaction.client.AbstractTransaction) EJBException(javax.ejb.EJBException) EJBException(javax.ejb.EJBException) ObjectStreamException(java.io.ObjectStreamException)

Example 12 with EJBException

use of javax.ejb.EJBException in project wildfly by wildfly.

the class TimerAttributeDefinition method addPersistent.

private static void addPersistent(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final ModelNode detailNode = timerNode.get(PERSISTENT);
        boolean b = timer.isPersistent();
        detailNode.set(b);
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

Example 13 with EJBException

use of javax.ejb.EJBException in project wildfly by wildfly.

the class TimerAttributeDefinition method addTimeRemaining.

private static void addTimeRemaining(Timer timer, ModelNode timerNode, final String componentName) {
    try {
        final ModelNode detailNode = timerNode.get(TIME_REMAINING);
        long time = timer.getTimeRemaining();
        detailNode.set(time);
    } catch (IllegalStateException e) {
    // ignore
    } catch (NoSuchObjectLocalException e) {
    // ignore
    } catch (EJBException e) {
        logTimerFailure(componentName, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ModelNode(org.jboss.dmr.ModelNode) EJBException(javax.ejb.EJBException)

Example 14 with EJBException

use of javax.ejb.EJBException in project wildfly by wildfly.

the class TimerServiceImpl method registerSynchronization.

private void registerSynchronization(Synchronization synchronization) {
    try {
        final Transaction tx = this.getTransaction();
        // register for lifecycle events of transaction
        tx.registerSynchronization(synchronization);
    } catch (RollbackException e) {
        throw new EJBException(e);
    } catch (SystemException e) {
        throw new EJBException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) EJBException(javax.ejb.EJBException)

Example 15 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class EjbHomeProxyHandler method _invoke.

@Override
protected Object _invoke(final Object proxy, final Class interfce, final Method method, final Object[] args) throws Throwable {
    final String methodName = method.getName();
    if (logger.isDebugEnabled()) {
        logger.debug("EjbHomeProxyHandler: invoking method " + methodName + " on " + deploymentID);
    }
    try {
        final Object retValue;
        final MethodType operation = dispatchTable.get(methodName);
        if (operation == null) {
            retValue = homeMethod(interfce, method, args, proxy);
        } else {
            switch(operation) {
                /*-- CREATE ------------- <HomeInterface>.create(<x>) ---*/
                case CREATE:
                    retValue = create(interfce, method, args, proxy);
                    break;
                case FIND:
                    retValue = findX(interfce, method, args, proxy);
                    break;
                /*-- GET EJB METADATA ------ EJBHome.getEJBMetaData() ---*/
                case META_DATA:
                    retValue = getEJBMetaData(method, args, proxy);
                    break;
                /*-- GET HOME HANDLE -------- EJBHome.getHomeHandle() ---*/
                case HOME_HANDLE:
                    retValue = getHomeHandle(method, args, proxy);
                    break;
                /*-- REMOVE ------------------------ EJBHome.remove() ---*/
                case REMOVE:
                    {
                        final Class type = method.getParameterTypes()[0];
                        /*-- HANDLE ------- EJBHome.remove(Handle handle) ---*/
                        if (Handle.class.isAssignableFrom(type)) {
                            retValue = removeWithHandle(interfce, method, args, proxy);
                        } else {
                            /*-- PRIMARY KEY ----- EJBHome.remove(Object key) ---*/
                            retValue = removeByPrimaryKey(interfce, method, args, proxy);
                        }
                        break;
                    }
                default:
                    throw new OpenEJBRuntimeException("Inconsistent internal state: value " + operation + " for operation " + methodName);
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("EjbHomeProxyHandler: finished invoking method " + method.getName() + ". Return value:" + retValue);
        }
        return retValue;
    /*
            * The ire is thrown by the container system and propagated by
            * the server to the stub.
            */
    } catch (final RemoteException re) {
        if (interfaceType.isLocal()) {
            throw new EJBException(re.getMessage()).initCause(re.detail);
        } else {
            throw re;
        }
    } catch (final InvalidateReferenceException ire) {
        Throwable cause = ire.getRootCause();
        if (cause instanceof RemoteException && interfaceType.isLocal()) {
            final RemoteException re = (RemoteException) cause;
            final Throwable detail = re.detail != null ? re.detail : re;
            cause = new EJBException(re.getMessage()).initCause(detail);
        }
        throw cause;
    /*
            * Application exceptions must be reported dirctly to the client. They
            * do not impact the viability of the proxy.
            */
    } catch (final ApplicationException ae) {
        final Throwable exc = ae.getRootCause() != null ? ae.getRootCause() : ae;
        if (exc instanceof EJBAccessException) {
            if (interfaceType.isBusiness()) {
                throw exc;
            } else {
                if (interfaceType.isLocal()) {
                    throw (AccessLocalException) new AccessLocalException(exc.getMessage()).initCause(exc);
                } else {
                    try {
                        throw new AccessException(exc.getMessage()).initCause(exc);
                    } catch (final IllegalStateException vmbug) {
                        // bug affects using initCause on any RemoteException subclasses in Sun 1.5_07 or lower
                        throw new AccessException(exc.getMessage(), (Exception) exc);
                    }
                }
            }
        }
        throw exc;
    /*
            * A system exception would be highly unusual and would indicate a sever
            * problem with the container system.
            */
    } catch (final SystemException se) {
        if (interfaceType.isLocal()) {
            throw new EJBException("Container has suffered a SystemException").initCause(se.getRootCause());
        } else {
            throw new RemoteException("Container has suffered a SystemException", se.getRootCause());
        }
    } catch (final OpenEJBException oe) {
        if (interfaceType.isLocal()) {
            throw new EJBException("Unknown Container Exception").initCause(oe.getRootCause());
        } else {
            throw new RemoteException("Unknown Container Exception", oe.getRootCause());
        }
    } catch (final Throwable t) {
        logger.debug("EjbHomeProxyHandler: finished invoking method " + method.getName() + " with exception:" + t, t);
        throw t;
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) AccessLocalException(javax.ejb.AccessLocalException) EJBAccessException(javax.ejb.EJBAccessException) Handle(javax.ejb.Handle) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) ApplicationException(org.apache.openejb.ApplicationException) AccessException(java.rmi.AccessException) EJBAccessException(javax.ejb.EJBAccessException) SystemException(org.apache.openejb.SystemException) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Aggregations

EJBException (javax.ejb.EJBException)86 InitialContext (javax.naming.InitialContext)40 OpenEJBException (org.apache.openejb.OpenEJBException)24 Test (org.junit.Test)16 RemoteException (java.rmi.RemoteException)13 CreateException (javax.ejb.CreateException)12 NamingException (javax.naming.NamingException)11 Connection (java.sql.Connection)10 PreparedStatement (java.sql.PreparedStatement)10 DataSource (javax.sql.DataSource)10 Properties (java.util.Properties)9 ThreadContext (org.apache.openejb.core.ThreadContext)9 FinderException (javax.ejb.FinderException)7 HashMap (java.util.HashMap)6 RemoveException (javax.ejb.RemoveException)6 BeanContext (org.apache.openejb.BeanContext)6 File (java.io.File)5 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)5 JMSException (javax.jms.JMSException)5 Assembler (org.apache.openejb.assembler.classic.Assembler)5