Search in sources :

Example 16 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)

Example 17 with EJBObject

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

the class SingletonContainer method invoke.

@Override
public Object invoke(final Object deployID, InterfaceType type, final Class callInterface, final Method callMethod, final Object[] args, final Object primKey) throws OpenEJBException {
    final BeanContext beanContext = this.getBeanContext(deployID);
    if (beanContext == null) {
        throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
    }
    // Use the backup way to determine call type if null was supplied.
    if (type == null) {
        type = beanContext.getInterfaceType(callInterface);
    }
    final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
    final ThreadContext callContext = new ThreadContext(beanContext, primKey);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    final CurrentCreationalContext currentCreationalContext = beanContext.get(CurrentCreationalContext.class);
    Object runAs = null;
    try {
        if (oldCallContext != null) {
            final BeanContext oldBc = oldCallContext.getBeanContext();
            if (oldBc.getRunAsUser() != null || oldBc.getRunAs() != null) {
                runAs = AbstractSecurityService.class.cast(securityService).overrideWithRunAsContext(callContext, beanContext, oldBc);
            }
        }
        final boolean authorized = type == InterfaceType.TIMEOUT || getSecurityService().isCallerAuthorized(callMethod, type);
        if (!authorized) {
            throw new org.apache.openejb.ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
        }
        final Class declaringClass = callMethod.getDeclaringClass();
        if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
            if (callMethod.getName().startsWith("create")) {
                return createEJBObject(beanContext, callMethod);
            } else {
                // EJBHome.remove( ) and other EJBHome methods are not process by the container
                return null;
            }
        } else if (EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) {
            // EJBObject.remove( ) and other EJBObject methods are not process by the container
            return null;
        }
        final Instance instance = instanceManager.getInstance(callContext);
        callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
        callContext.setCurrentAllowedStates(null);
        callContext.set(Method.class, runMethod);
        callContext.setInvokedInterface(callInterface);
        if (currentCreationalContext != null) {
            // noinspection unchecked
            currentCreationalContext.set(instance.creationalContext);
        }
        return _invoke(callMethod, runMethod, args, instance, callContext, type);
    } finally {
        if (runAs != null) {
            try {
                securityService.associate(runAs);
            } catch (final LoginException e) {
            // no-op
            }
        }
        ThreadContext.exit(oldCallContext);
        if (currentCreationalContext != null) {
            currentCreationalContext.remove();
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EJBHome(javax.ejb.EJBHome) ThreadContext(org.apache.openejb.core.ThreadContext) Method(java.lang.reflect.Method) EJBAccessException(javax.ejb.EJBAccessException) EJBLocalHome(javax.ejb.EJBLocalHome) CurrentCreationalContext(org.apache.openejb.cdi.CurrentCreationalContext) BeanContext(org.apache.openejb.BeanContext) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) LoginException(javax.security.auth.login.LoginException) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Example 18 with EJBObject

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

the class StatelessPojoHandleTests method setUp.

protected void setUp() throws Exception {
    super.setUp();
    final Object obj = initialContext.lookup("client/tests/stateless/BasicStatelessPojoHome");
    ejbHome = (BasicStatelessHome) obj;
    ejbObject = ejbHome.createObject();
    ejbHandle = ejbObject.getHandle();
}
Also used : EJBObject(javax.ejb.EJBObject)

Example 19 with EJBObject

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

the class StatelessRmiIiopTests method test40_returnEJBObject.

/*-------------------------------------------------*/
/*  EJBObject                                      */
/*-------------------------------------------------*/
public void test40_returnEJBObject() {
    try {
        final Object obj = initialContext.lookup("client/tests/stateless/EncBean");
        final EncStatelessHome home = (EncStatelessHome) obj;
        assertNotNull("The EJBHome returned from JNDI is null", home);
        final EncStatelessObject expected = home.create();
        assertNotNull("The EJBObject created is null", expected);
        final EncStatelessObject actual = (EncStatelessObject) ejbObject.returnEJBObject(expected);
        assertNotNull("The EJBObject returned is null", actual);
        assertTrue("The EJBObejcts are not identical", expected.isIdentical(actual));
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
Also used : EJBObject(javax.ejb.EJBObject) RemoteException(java.rmi.RemoteException)

Example 20 with EJBObject

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

the class StatelessRmiIiopTests method test52_returnNestedHandle.

public void test52_returnNestedHandle() {
    try {
        final Object obj = initialContext.lookup("client/tests/stateless/EncBean");
        final EncStatelessHome home = (EncStatelessHome) obj;
        assertNotNull("The EJBHome returned from JNDI is null", home);
        final EncStatelessObject object = home.create();
        assertNotNull("The EJBObject created is null", object);
        final Handle expected = object.getHandle();
        assertNotNull("The EJBObject Handle returned is null", expected);
        assertNotNull("The EJBObject in the Handle is null", expected.getEJBObject());
        final ObjectGraph graph = ejbObject.returnObjectGraph(new ObjectGraph(expected));
        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());
        final EJBObject exp = expected.getEJBObject();
        final EJBObject act = actual.getEJBObject();
        assertTrue("The EJBObjects in the Handles are not identical", exp.isIdentical(act));
    } catch (final Exception e) {
        fail("Received Exception " + e.getClass() + " : " + e.getMessage());
    }
}
Also used : EJBObject(javax.ejb.EJBObject) ObjectGraph(org.apache.openejb.test.object.ObjectGraph) EJBObject(javax.ejb.EJBObject) RemoteException(java.rmi.RemoteException) Handle(javax.ejb.Handle)

Aggregations

EJBObject (javax.ejb.EJBObject)109 RemoteException (java.rmi.RemoteException)46 Handle (javax.ejb.Handle)28 EJBLocalObject (javax.ejb.EJBLocalObject)12 ObjectGraph (org.apache.openejb.test.object.ObjectGraph)12 EJBException (javax.ejb.EJBException)11 RemoveException (javax.ejb.RemoveException)9 SystemException (javax.transaction.SystemException)9 CreateException (javax.ejb.CreateException)8 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)8 EncCmpObject (org.apache.openejb.test.entity.cmp.EncCmpObject)7 RmiIiopCmpObject (org.apache.openejb.test.entity.cmp.RmiIiopCmpObject)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 MarshalledObject (java.rmi.MarshalledObject)6 FinderException (javax.ejb.FinderException)6 EncCmpHome (org.apache.openejb.test.entity.cmp.EncCmpHome)6 Test (org.junit.Test)5 NoSuchObjectException (java.rmi.NoSuchObjectException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3