Search in sources :

Example 1 with Handle

use of jakarta.ejb.Handle 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(jakarta.ejb.AccessLocalException) EJBAccessException(jakarta.ejb.EJBAccessException) Handle(jakarta.ejb.Handle) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) ApplicationException(org.apache.openejb.ApplicationException) AccessException(java.rmi.AccessException) EJBAccessException(jakarta.ejb.EJBAccessException) SystemException(org.apache.openejb.SystemException) RemoteException(java.rmi.RemoteException) EJBException(jakarta.ejb.EJBException) OpenEJBException(org.apache.openejb.OpenEJBException)

Example 2 with Handle

use of jakarta.ejb.Handle in project tomee by apache.

the class CrossClassLoaderProxyTestObject method testRemoteInterface.

public void testRemoteInterface() throws Exception {
    assertNotNull("widgetHome", widgetHome);
    // assertTrue("home should be an instance of WidgetHome", home instanceof CrossClassLoaderProxyTest.WidgetHome);
    // CrossClassLoaderProxyTest.WidgetHome widgetHome = (CrossClassLoaderProxyTest.WidgetHome)home;
    final Object object = widgetHome.create();
    assertNotNull("widgetHome.create()", object);
    assertTrue("object should be an instance of WidgetRemote", object instanceof CrossClassLoaderProxyTest.WidgetRemote);
    final CrossClassLoaderProxyTest.WidgetRemote widget = (CrossClassLoaderProxyTest.WidgetRemote) object;
    // Do a business method...
    final Stack<CrossClassLoaderProxyTest.Lifecycle> lifecycle = widget.getLifecycle();
    assertNotNull("lifecycle", lifecycle);
    assertNotSame("is copy", lifecycle, CrossClassLoaderProxyTest.WidgetBean.lifecycle);
    // Check the lifecycle of the bean
    final List expected = Arrays.asList(CrossClassLoaderProxyTest.Lifecycle.values());
    assertEquals(join("\n", expected), join("\n", lifecycle));
    // verify home ejb meta data
    final EJBMetaData metaData = widgetHome.getEJBMetaData();
    assertTrue("metaData.getEJBHome() should be an instance of WidgetHome", metaData.getEJBHome() instanceof CrossClassLoaderProxyTest.WidgetHome);
    assertEquals(CrossClassLoaderProxyTest.WidgetHome.class, metaData.getHomeInterfaceClass());
    assertEquals(CrossClassLoaderProxyTest.WidgetRemote.class, metaData.getRemoteInterfaceClass());
    // verify home handle
    final HomeHandle homeHandle = widgetHome.getHomeHandle();
    assertTrue("homeHandle.getEJBHome() should be an instance of WidgetHome", homeHandle.getEJBHome() instanceof CrossClassLoaderProxyTest.WidgetHome);
    // verify ejb object getHome
    assertTrue("widget.getEJBHome() should be an instance of WidgetHome", widget.getEJBHome() instanceof CrossClassLoaderProxyTest.WidgetHome);
    // verify ejb object handle
    final Handle objectHandle = widget.getHandle();
    assertTrue("objectHandle.getEJBObject() should be an instance of WidgetHome", objectHandle.getEJBObject() instanceof CrossClassLoaderProxyTest.WidgetRemote);
}
Also used : EJBMetaData(jakarta.ejb.EJBMetaData) HomeHandle(jakarta.ejb.HomeHandle) List(java.util.List) HomeHandle(jakarta.ejb.HomeHandle) Handle(jakarta.ejb.Handle)

Example 3 with Handle

use of jakarta.ejb.Handle in project tomee by apache.

the class RmiIiopBmpBean method returnHandle.

public Handle returnHandle() throws jakarta.ejb.EJBException {
    Handle data = null;
    try {
        final InitialContext ctx = new InitialContext();
        final EncBmpHome home = (EncBmpHome) ctx.lookup("java:comp/env/bmp/rmi-iiop/home");
        final EncBmpObject object = home.create("Test03 BmpBean");
        data = object.getHandle();
    } catch (final Exception e) {
        throw new jakarta.ejb.EJBException(e);
    }
    return data;
}
Also used : EJBException(jakarta.ejb.EJBException) InitialContext(javax.naming.InitialContext) RemoveException(jakarta.ejb.RemoveException) EJBException(jakarta.ejb.EJBException) RemoteException(java.rmi.RemoteException) Handle(jakarta.ejb.Handle)

Example 4 with Handle

use of jakarta.ejb.Handle in project tomee by apache.

the class CmpRmiIiopTests method test54_returnHandleArray.

public void test54_returnHandleArray() {
    try {
        final Object obj = initialContext.lookup("client/tests/entity/cmp/EncBean");
        final EncCmpHome home = (EncCmpHome) obj;
        assertNotNull("The EJBHome returned from JNDI is null", home);
        final EncCmpObject object = home.create("test_54 CmpBean");
        assertNotNull("The EJBObject created is null", object);
        final Handle[] expected = new Handle[3];
        for (int i = 0; i < expected.length; i++) {
            expected[i] = object.getHandle();
            assertNotNull("The EJBObject Handle returned is null", expected[i]);
        }
        final Handle[] actual = (Handle[]) ejbObject.returnHandleArray(expected);
        assertNotNull("The Handle array returned is null", actual);
        assertEquals(expected.length, actual.length);
        for (int i = 0; i < expected.length; i++) {
            assertNotNull("The EJBObject Handle returned is null", actual[i]);
            assertNotNull("The EJBObject in the Handle is null", actual[i].getEJBObject());
            assertTrue("The EJBObjects in the Handles are not equal", expected[i].getEJBObject().isIdentical(actual[i].getEJBObject()));
        }
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
Also used : EJBObject(jakarta.ejb.EJBObject) RemoteException(java.rmi.RemoteException) Handle(jakarta.ejb.Handle)

Example 5 with Handle

use of jakarta.ejb.Handle in project tomee by apache.

the class CmpRmiIiopTests method test53_returnNestedHandle2.

public void test53_returnNestedHandle2() {
    try {
        final ObjectGraph graph = ejbObject.returnNestedHandle();
        assertNotNull("The ObjectGraph is null", graph);
        final Handle actual = (Handle) graph.getObject();
        assertNotNull("The EJBObject Handle returned is null", actual);
        assertNotNull("The EJBObject in the Handle is null", actual.getEJBObject());
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
Also used : ObjectGraph(org.apache.openejb.test.object.ObjectGraph) RemoteException(java.rmi.RemoteException) Handle(jakarta.ejb.Handle)

Aggregations

Handle (jakarta.ejb.Handle)45 RemoteException (java.rmi.RemoteException)37 EJBObject (jakarta.ejb.EJBObject)25 ObjectGraph (org.apache.openejb.test.object.ObjectGraph)12 EJBException (jakarta.ejb.EJBException)7 InitialContext (javax.naming.InitialContext)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 MarshalledObject (java.rmi.MarshalledObject)3 EncCmpHome (org.apache.openejb.test.entity.cmp.EncCmpHome)3 EncCmpObject (org.apache.openejb.test.entity.cmp.EncCmpObject)3 RmiIiopCmpObject (org.apache.openejb.test.entity.cmp.RmiIiopCmpObject)3 RemoveException (jakarta.ejb.RemoveException)2 AccessLocalException (jakarta.ejb.AccessLocalException)1 CreateException (jakarta.ejb.CreateException)1 EJBAccessException (jakarta.ejb.EJBAccessException)1 EJBMetaData (jakarta.ejb.EJBMetaData)1 HomeHandle (jakarta.ejb.HomeHandle)1