Search in sources :

Example 1 with Handle

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

the class ClientEjb method getRemoteViaHandleMessage.

public String getRemoteViaHandleMessage() throws RemoteException {
    final IIOPBasicRemote object = home.create();
    final Handle handle = object.getHandle();
    final IIOPBasicRemote newObject = (IIOPBasicRemote) PortableRemoteObject.narrow(handle.getEJBObject(), IIOPBasicRemote.class);
    return newObject.hello();
}
Also used : HomeHandle(javax.ejb.HomeHandle) Handle(javax.ejb.Handle)

Example 2 with Handle

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

the class HomeRemoveInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
    final Handle handle = (Handle) context.getParameters()[0];
    handle.getEJBObject().remove();
    return null;
}
Also used : Handle(javax.ejb.Handle)

Example 3 with Handle

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

the class ReferenceAnnotationDescriptorTestCase method testStateful21Interfaces.

@Test
public void testStateful21Interfaces() throws Exception {
    InitialContext jndiContext = new InitialContext();
    StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30Home.class.getName());
    Assert.assertNotNull(home);
    EJBMetaData metadata = home.getEJBMetaData();
    Assert.assertNotNull(metadata);
    Assert.assertEquals(StatefulSession30.class, metadata.getRemoteInterfaceClass());
    HomeHandle homeHandle = home.getHomeHandle();
    Assert.assertNotNull(homeHandle);
    EJBHome ejbHome = homeHandle.getEJBHome();
    Assert.assertNotNull(ejbHome);
    metadata = ejbHome.getEJBMetaData();
    Assert.assertNotNull(metadata);
    Assert.assertEquals(StatefulSession30.class, metadata.getRemoteInterfaceClass());
    StatefulSession30 session = home.create();
    Assert.assertNotNull(session);
    ejbHome = session.getEJBHome();
    Assert.assertNotNull(ejbHome);
    Handle handle = session.getHandle();
    Assert.assertNotNull(handle);
    EJBObject ejbObject = handle.getEJBObject();
    Assert.assertNotNull(ejbObject);
    ejbHome = ejbObject.getEJBHome();
    Assert.assertNotNull(ejbHome);
    Handle handle1 = ejbObject.getHandle();
    Assert.assertNotNull(handle1);
    StatefulSession30 session1 = home.create();
    Assert.assertFalse(session.isIdentical(session1));
    Assert.assertTrue(session.isIdentical(session));
}
Also used : EJBMetaData(javax.ejb.EJBMetaData) EJBHome(javax.ejb.EJBHome) EJBObject(javax.ejb.EJBObject) HomeHandle(javax.ejb.HomeHandle) InitialContext(javax.naming.InitialContext) HomeHandle(javax.ejb.HomeHandle) Handle(javax.ejb.Handle) Test(org.junit.Test)

Example 4 with Handle

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

the class ReferenceAnnotationDescriptorTestCase method testStateless21Interfaces.

@Test
public void testStateless21Interfaces() throws Exception {
    InitialContext jndiContext = new InitialContext();
    Session30Home home = (Session30Home) jndiContext.lookup("java:module/Session30!" + Session30Home.class.getName());
    Assert.assertNotNull(home);
    EJBMetaData metadata = home.getEJBMetaData();
    Assert.assertNotNull(metadata);
    Assert.assertEquals(Session30.class.getName(), metadata.getRemoteInterfaceClass().getName());
    HomeHandle homeHandle = home.getHomeHandle();
    Assert.assertNotNull(homeHandle);
    EJBHome ejbHome = homeHandle.getEJBHome();
    Assert.assertNotNull(ejbHome);
    metadata = ejbHome.getEJBMetaData();
    Assert.assertNotNull(metadata);
    Assert.assertEquals(Session30.class.getName(), metadata.getRemoteInterfaceClass().getName());
    Session30 session = home.create();
    Assert.assertNotNull(session);
    ejbHome = session.getEJBHome();
    Assert.assertNotNull(ejbHome);
    Handle handle = session.getHandle();
    Assert.assertNotNull(handle);
    EJBObject ejbObject = handle.getEJBObject();
    Assert.assertNotNull(ejbObject);
    ejbHome = ejbObject.getEJBHome();
    Assert.assertNotNull(ejbHome);
    Handle handle1 = ejbObject.getHandle();
    Assert.assertNotNull(handle1);
    Session30 session1 = home.create();
    Assert.assertTrue(session.isIdentical(session1));
}
Also used : EJBMetaData(javax.ejb.EJBMetaData) EJBHome(javax.ejb.EJBHome) EJBObject(javax.ejb.EJBObject) HomeHandle(javax.ejb.HomeHandle) InitialContext(javax.naming.InitialContext) Session30(org.jboss.as.test.integration.ejb.ejb2.reference.global.Session30) HomeHandle(javax.ejb.HomeHandle) Handle(javax.ejb.Handle) Test(org.junit.Test)

Example 5 with Handle

use of javax.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(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

Handle (javax.ejb.Handle)51 RemoteException (java.rmi.RemoteException)37 EJBObject (javax.ejb.EJBObject)28 ObjectGraph (org.apache.openejb.test.object.ObjectGraph)12 InitialContext (javax.naming.InitialContext)9 EJBException (javax.ejb.EJBException)7 HomeHandle (javax.ejb.HomeHandle)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 EJBMetaData (javax.ejb.EJBMetaData)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 Test (org.junit.Test)3 EJBHome (javax.ejb.EJBHome)2 RemoveException (javax.ejb.RemoveException)2 AccessException (java.rmi.AccessException)1