Search in sources :

Example 51 with OpenEJBException

use of org.apache.openejb.OpenEJBException 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 52 with OpenEJBException

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

the class ServiceJarXmlLoader method parse.

private void parse(final String namespace) {
    try {
        // Load and try again
        final ServicesJar servicesJar = JaxbOpenejb.readServicesJar(namespace);
        for (final ServiceProvider provider : servicesJar.getServiceProvider()) {
            final ID found = new ID(namespace, provider.getId());
            loaded.put(found, provider);
        }
    } catch (final OpenEJBException e) {
        throw new IllegalStateException(e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ServiceProvider(org.apache.openejb.config.sys.ServiceProvider) ServicesJar(org.apache.openejb.config.sys.ServicesJar)

Example 53 with OpenEJBException

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

the class CheckAsynchronous method getMethod.

private Method getMethod(final Class<?> clazz, final AsyncMethod asyncMethod) {
    try {
        final MethodParams methodParams = asyncMethod.getMethodParams();
        final Class<?>[] parameterTypes;
        if (methodParams != null) {
            parameterTypes = new Class[methodParams.getMethodParam().size()];
            int arrayIndex = 0;
            for (final String parameterType : methodParams.getMethodParam()) {
                parameterTypes[arrayIndex++] = loadClass(parameterType);
            }
        } else {
            parameterTypes = new Class[0];
        }
        return clazz.getMethod(asyncMethod.getMethodName(), parameterTypes);
    } catch (final NoSuchMethodException e) {
        return null;
    } catch (final OpenEJBException e) {
        throw new OpenEJBRuntimeException(e);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) OpenEJBException(org.apache.openejb.OpenEJBException) MethodParams(org.apache.openejb.jee.MethodParams)

Example 54 with OpenEJBException

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

the class CheckMethods method check_unusedPostCreateMethods.

public void check_unusedPostCreateMethods(final RemoteBean b) {
    Class bean = null;
    try {
        bean = loadClass(b.getEjbClass());
    } catch (final OpenEJBException e) {
        return;
    }
    for (final Method postCreate : bean.getMethods()) {
        if (!postCreate.getName().startsWith("ejbPostCreate")) {
            continue;
        }
        final StringBuilder ejbCreate = new StringBuilder(postCreate.getName());
        ejbCreate.replace(0, "ejbPostCreate".length(), "ejbCreate");
        try {
            bean.getMethod(ejbCreate.toString(), postCreate.getParameterTypes());
        } catch (final NoSuchMethodException e) {
            final String paramString = getParameters(postCreate);
            warn(b, "unused.ejbPostCreate", b.getEjbClass(), postCreate.getName(), paramString, ejbCreate.toString());
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) Method(java.lang.reflect.Method)

Example 55 with OpenEJBException

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

the class WebContext method newWeakableInstance.

public <T> Instance newWeakableInstance(final Class<T> beanClass) throws OpenEJBException {
    final WebBeansContext webBeansContext = getWebBeansContext();
    final ConstructorInjectionBean<Object> beanDefinition = getConstructorInjectionBean(beanClass, webBeansContext);
    CreationalContext<Object> creationalContext;
    final Object o;
    if (webBeansContext == null) {
        creationalContext = null;
        try {
            o = beanClass.newInstance();
        } catch (final InstantiationException | IllegalAccessException e) {
            throw new OpenEJBException(e);
        }
    } else {
        creationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(beanDefinition);
        o = beanDefinition.create(creationalContext);
    }
    // Create bean instance
    final Context unwrap = InjectionProcessor.unwrap(getInitialContext());
    final InjectionProcessor injectionProcessor = new InjectionProcessor(o, injections, unwrap);
    final Object beanInstance;
    try {
        beanInstance = injectionProcessor.createInstance();
        if (webBeansContext != null) {
            final InjectionTargetBean<Object> bean = InjectionTargetBean.class.cast(beanDefinition);
            bean.getInjectionTarget().inject(beanInstance, creationalContext);
            if (shouldBeReleased(bean.getScope())) {
                creationalContexts.put(beanInstance, creationalContext);
            }
        }
    } catch (final OpenEJBException oejbe) {
        if (creationalContext != null) {
            creationalContext.release();
        }
        throw oejbe;
    }
    return new Instance(beanInstance, creationalContext);
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) AppContext(org.apache.openejb.AppContext) ServletContext(javax.servlet.ServletContext) OpenEJBException(org.apache.openejb.OpenEJBException) WebBeansContext(org.apache.webbeans.config.WebBeansContext) InjectionProcessor(org.apache.openejb.InjectionProcessor)

Aggregations

OpenEJBException (org.apache.openejb.OpenEJBException)187 IOException (java.io.IOException)55 NamingException (javax.naming.NamingException)34 URL (java.net.URL)31 MalformedURLException (java.net.MalformedURLException)30 ApplicationException (org.apache.openejb.ApplicationException)29 BeanContext (org.apache.openejb.BeanContext)29 File (java.io.File)26 ArrayList (java.util.ArrayList)26 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)23 SystemException (org.apache.openejb.SystemException)22 Method (java.lang.reflect.Method)20 HashMap (java.util.HashMap)18 ThreadContext (org.apache.openejb.core.ThreadContext)17 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)15 RemoteException (java.rmi.RemoteException)14 EJBException (javax.ejb.EJBException)14 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)14 HashSet (java.util.HashSet)13 Properties (java.util.Properties)13