Search in sources :

Example 1 with EJBObject

use of javax.ejb.EJBObject in project Payara by payara.

the class SafeProperties method instantiateEJBLocalObjectImpl.

protected EJBLocalObjectImpl instantiateEJBLocalObjectImpl(Object key) throws Exception {
    EJBLocalObjectImpl localObjImpl = null;
    EJBLocalObjectInvocationHandler handler = new EJBLocalObjectInvocationHandler(proxyInvocationInfoMap, localIntf);
    localObjImpl = handler;
    try {
        EJBLocalObject localObjectProxy = (EJBLocalObject) ejbLocalObjectProxyCtor.newInstance(new Object[] { handler });
        handler.setProxy(localObjectProxy);
    } catch (ClassCastException e) {
        String msg = localStrings.getLocalString("ejb.basecontainer_invalid_local_interface", "Local component interface [{0}] is invalid since it does not extend javax.ejb.EJBLocalObject.", localIntf);
        throw new IllegalArgumentException(msg, e);
    }
    localObjImpl.setContainer(this);
    if (key != null) {
        // associate the EJBObject with the key
        localObjImpl.setKey(key);
    }
    return localObjImpl;
}
Also used : EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Example 2 with EJBObject

use of javax.ejb.EJBObject 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 3 with EJBObject

use of javax.ejb.EJBObject 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 4 with EJBObject

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

the class RemoveMethodUnitTestCase method testEjbRemoveInvokedOnRemoval.

/**
 * Test that ejbRemove() method was invoked on the bean when the remove() is invoked on the EJBObject
 * of an EJB2.x view of a bean
 *
 * @throws Exception
 */
@Test
public void testEjbRemoveInvokedOnRemoval() throws Exception {
    // Obtain stub
    Object obj = ctx.lookup("java:app/" + DD_BASED_MODULE_NAME + "/" + Ejb21ViewDDBean.class.getSimpleName() + "!" + Ejb21ViewHome.class.getName());
    Ejb21ViewHome home = (Ejb21ViewHome) PortableRemoteObject.narrow(obj, Ejb21ViewHome.class);
    Ejb21View bean = home.create();
    // Ensure EJBObject
    Assert.assertTrue(bean instanceof EJBObject);
    String result = bean.test();
    bean.remove();
    try {
        bean.test();
        Assert.fail("Invocation on a removed bean was expected to fail");
    } catch (NoSuchObjectException e) {
    // expected
    }
    final RemoveMethodInvocationTracker ejbRemoveMethodInvocationTracker = (RemoveMethodInvocationTracker) ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + RemoveMethodInvocationTrackerBean.class.getSimpleName() + "!" + RemoveMethodInvocationTracker.class.getName());
    Assert.assertTrue("ejbRemove() method was not invoked after bean removal", ejbRemoveMethodInvocationTracker.wasEjbRemoveCallbackInvoked());
}
Also used : EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) PortableRemoteObject(javax.rmi.PortableRemoteObject) NoSuchObjectException(java.rmi.NoSuchObjectException) Test(org.junit.Test)

Example 5 with EJBObject

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

the class BaseSessionContext method getEJBObject.

public EJBObject getEJBObject() throws IllegalStateException {
    doCheck(Call.getEJBObject);
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final BeanContext di = threadContext.getBeanContext();
    if (di.getHomeInterface() == null) {
        throw new IllegalStateException("Bean does not have an EJBObject interface: " + di.getDeploymentID());
    }
    return (EJBObject) EjbObjectProxyHandler.createProxy(di, threadContext.getPrimaryKey(), InterfaceType.EJB_OBJECT, di.getRemoteInterface());
}
Also used : BeanContext(org.apache.openejb.BeanContext) EJBObject(javax.ejb.EJBObject)

Aggregations

EJBObject (javax.ejb.EJBObject)104 RemoteException (java.rmi.RemoteException)41 Handle (javax.ejb.Handle)28 ObjectGraph (org.apache.openejb.test.object.ObjectGraph)12 EJBLocalObject (javax.ejb.EJBLocalObject)8 EJBException (javax.ejb.EJBException)7 EncCmpObject (org.apache.openejb.test.entity.cmp.EncCmpObject)7 RmiIiopCmpObject (org.apache.openejb.test.entity.cmp.RmiIiopCmpObject)7 MarshalledObject (java.rmi.MarshalledObject)6 EncCmpHome (org.apache.openejb.test.entity.cmp.EncCmpHome)6 Test (org.junit.Test)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 NoSuchObjectException (java.rmi.NoSuchObjectException)4 RemoveException (javax.ejb.RemoveException)4 SystemException (javax.transaction.SystemException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 NotSerializableException (java.io.NotSerializableException)3 ObjectInputStream (java.io.ObjectInputStream)3