Search in sources :

Example 1 with OpenEJBRuntimeException

use of org.apache.openejb.OpenEJBRuntimeException 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)

Example 2 with OpenEJBRuntimeException

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

the class EjbHomeProxyHandler method createProxy.

public Object createProxy(final Object primaryKey, final Class mainInterface) {
    try {
        final InterfaceType objectInterfaceType = this.interfaceType.getCounterpart();
        final BeanType type = getBeanContext().getComponentType();
        final EjbObjectProxyHandler handler = newEjbObjectHandler(getBeanContext(), primaryKey, objectInterfaceType, getInterfaces(), mainInterface);
        // TODO Is it correct for ManagedBean injection via managed bean class?
        if ((InterfaceType.LOCALBEAN.equals(objectInterfaceType) || getBeanContext().getComponentType().equals(BeanType.MANAGED)) && !getBeanContext().isDynamicallyImplemented()) {
            return LocalBeanProxyFactory.constructProxy(handler.getBeanContext().get(BeanContext.ProxyClass.class).getProxy(), handler);
        } else {
            final List<Class> proxyInterfaces = new ArrayList<Class>(handler.getInterfaces().size() + 2);
            proxyInterfaces.addAll(handler.getInterfaces());
            proxyInterfaces.add(Serializable.class);
            proxyInterfaces.add(IntraVmProxy.class);
            if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
                proxyInterfaces.add(BeanContext.Removable.class);
            }
            return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler);
        }
    } catch (final IllegalAccessException iae) {
        throw new OpenEJBRuntimeException("Could not create IVM proxy for " + getInterfaces().get(0), iae);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) BeanContext(org.apache.openejb.BeanContext) InterfaceType(org.apache.openejb.InterfaceType) BeanType(org.apache.openejb.BeanType) ArrayList(java.util.ArrayList)

Example 3 with OpenEJBRuntimeException

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

the class EjbObjectProxyHandler method _invoke.

@Override
public Object _invoke(final Object p, final Class interfce, final Method m, final Object[] a) throws Throwable {
    Object retValue = null;
    Throwable exc = null;
    final String methodName = m.getName();
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("EjbObjectProxyHandler: invoking method " + methodName + " on " + deploymentID + " with identity " + primaryKey);
        }
        Integer operation = dispatchTable.get(methodName);
        if (operation != null) {
            if (operation == 3) {
                if (m.getParameterTypes()[0] != EJBObject.class && m.getParameterTypes()[0] != EJBLocalObject.class) {
                    operation = null;
                }
            } else {
                operation = m.getParameterTypes().length == 0 ? operation : null;
            }
        }
        if (operation == null || !interfaceType.isComponent()) {
            retValue = businessMethod(interfce, m, a, p);
        } else {
            switch(operation) {
                case 1:
                    retValue = getHandle(m, a, p);
                    break;
                case 2:
                    retValue = getPrimaryKey(m, a, p);
                    break;
                case 3:
                    retValue = isIdentical(m, a, p);
                    break;
                case 4:
                    retValue = remove(interfce, m, a, p);
                    break;
                case 5:
                    retValue = getEJBHome(m, a, p);
                    break;
                case 6:
                    retValue = getEJBLocalHome(m, a, p);
                    break;
                default:
                    throw new OpenEJBRuntimeException("Inconsistent internal state");
            }
        }
        return retValue;
    /*
            * The ire is thrown by the container system and propagated by
            * the server to the stub.
            */
    } catch (final InvalidateReferenceException ire) {
        invalidateAllHandlers(getRegistryId());
        exc = ire.getRootCause() != null ? ire.getRootCause() : new RemoteException("InvalidateReferenceException: " + ire);
        throw exc;
    /*
            * Application exceptions must be reported dirctly to the client. They
            * do not impact the viability of the proxy.
            */
    } catch (final ApplicationException ae) {
        exc = ae.getRootCause() != null ? ae.getRootCause() : ae;
        if (exc instanceof EJBAccessException) {
            if (interfaceType.isBusiness()) {
                throw exc;
            } else {
                if (interfaceType.isLocal()) {
                    throw new AccessLocalException(exc.getMessage()).initCause(exc.getCause());
                } else {
                    throw new AccessException(exc.getMessage());
                }
            }
        }
        throw exc;
    /*
            * A system exception would be highly unusual and would indicate a sever
            * problem with the container system.
            */
    } catch (final SystemException se) {
        invalidateReference();
        exc = se.getRootCause() != null ? se.getRootCause() : se;
        logger.debug("The container received an unexpected exception: ", exc);
        throw new RemoteException("Container has suffered a SystemException", exc);
    } catch (final OpenEJBException oe) {
        exc = oe.getRootCause() != null ? oe.getRootCause() : oe;
        logger.debug("The container received an unexpected exception: ", exc);
        throw new RemoteException("Unknown Container Exception", oe.getRootCause());
    } finally {
        if (logger.isDebugEnabled()) {
            if (exc == null) {
                String ret = "void";
                if (null != retValue) {
                    try {
                        ret = retValue.toString();
                    } catch (final Exception e) {
                        ret = "toString() failed on (" + e.getMessage() + ")";
                    }
                }
                logger.debug("EjbObjectProxyHandler: finished invoking method " + methodName + ". Return value:" + ret);
            } else {
                logger.debug("EjbObjectProxyHandler: finished invoking method " + methodName + " with exception " + exc);
            }
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) AccessLocalException(javax.ejb.AccessLocalException) EJBLocalObject(javax.ejb.EJBLocalObject) EJBAccessException(javax.ejb.EJBAccessException) AccessException(java.rmi.AccessException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) ApplicationException(org.apache.openejb.ApplicationException) EJBAccessException(javax.ejb.EJBAccessException) OpenEJBException(org.apache.openejb.OpenEJBException) AccessLocalException(javax.ejb.AccessLocalException) RemoteException(java.rmi.RemoteException) ObjectStreamException(java.io.ObjectStreamException) SystemException(org.apache.openejb.SystemException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) 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) EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) RemoteException(java.rmi.RemoteException)

Example 4 with OpenEJBRuntimeException

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

the class EjbHomeProxyHandler method createHomeProxy.

public static Object createHomeProxy(final BeanContext beanContext, final InterfaceType interfaceType, final List<Class> objectInterfaces, final Class mainInterface) {
    if (!interfaceType.isHome()) {
        throw new IllegalArgumentException("InterfaceType is not a Home type: " + interfaceType);
    }
    try {
        final EjbHomeProxyHandler handler = createHomeHandler(beanContext, interfaceType, objectInterfaces, mainInterface);
        final List<Class> proxyInterfaces = new ArrayList<Class>(2);
        final Class homeInterface = beanContext.getInterface(interfaceType);
        proxyInterfaces.add(homeInterface);
        proxyInterfaces.add(IntraVmProxy.class);
        if (BeanType.STATEFUL.equals(beanContext.getComponentType()) || BeanType.MANAGED.equals(beanContext.getComponentType())) {
            proxyInterfaces.add(BeanContext.Removable.class);
        }
        return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler);
    } catch (final Exception e) {
        throw new OpenEJBRuntimeException("Can't create EJBHome stub" + e.getMessage(), e);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) BeanContext(org.apache.openejb.BeanContext) ArrayList(java.util.ArrayList) AccessException(java.rmi.AccessException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) ApplicationException(org.apache.openejb.ApplicationException) EJBAccessException(javax.ejb.EJBAccessException) OpenEJBException(org.apache.openejb.OpenEJBException) AccessLocalException(javax.ejb.AccessLocalException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) ObjectStreamException(java.io.ObjectStreamException) SystemException(org.apache.openejb.SystemException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 5 with OpenEJBRuntimeException

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

the class ActiveMQFactory method init.

private static void init() {
    synchronized (initialized) {
        if (!initialized.getAndSet(true)) {
            Class tmp;
            try {
                tmp = Class.forName("org.apache.openejb.resource.activemq.ActiveMQ5Factory");
                brokerPrefix = "amq5factory:";
            } catch (final Throwable t1) {
                try {
                    tmp = Class.forName("org.apache.openejb.resource.activemq.ActiveMQ4Factory");
                    brokerPrefix = "amq4factory:";
                } catch (final Throwable t2) {
                    throw new OpenEJBRuntimeException("Unable to load ActiveMQFactory: Check ActiveMQ jar files are on classpath", t1);
                }
            }
            final Class clazz = tmp;
            try {
                instance = clazz.newInstance();
            } catch (final InstantiationException e) {
                throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory instance", e);
            } catch (final IllegalAccessException e) {
                throw new OpenEJBRuntimeException("Unable to access ActiveMQFactory instance", e);
            }
            try {
                setThreadProperties = clazz.getDeclaredMethod("setThreadProperties", new Class[] { Properties.class });
            } catch (final NoSuchMethodException e) {
                throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory setThreadProperties method", e);
            }
            try {
                createBroker = clazz.getDeclaredMethod("createBroker", new Class[] { URI.class });
            } catch (final NoSuchMethodException e) {
                throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory createBroker method", e);
            }
            try {
                getBrokers = clazz.getDeclaredMethod("getBrokers", (Class[]) null);
            } catch (final NoSuchMethodException e) {
                throw new OpenEJBRuntimeException("Unable to create ActiveMQFactory createBroker method", e);
            }
        }
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) Properties(java.util.Properties) URI(java.net.URI)

Aggregations

OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)54 IOException (java.io.IOException)20 OpenEJBException (org.apache.openejb.OpenEJBException)17 ArrayList (java.util.ArrayList)13 Properties (java.util.Properties)12 NamingException (javax.naming.NamingException)9 MalformedURLException (java.net.MalformedURLException)8 BeanContext (org.apache.openejb.BeanContext)8 ObjectStreamException (java.io.ObjectStreamException)6 URISyntaxException (java.net.URISyntaxException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 File (java.io.File)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Method (java.lang.reflect.Method)4 URL (java.net.URL)4 ApplicationException (org.apache.openejb.ApplicationException)4 InvalidObjectException (java.io.InvalidObjectException)3 AccessException (java.rmi.AccessException)3 RemoteException (java.rmi.RemoteException)3