Search in sources :

Example 1 with EJBHome

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

the class SafeProperties method instantiateEJBHomeImpl.

private EJBHomeImpl instantiateEJBHomeImpl() throws Exception {
    EJBHomeInvocationHandler handler = getEJBHomeInvocationHandler(homeIntf);
    handler.setMethodMap(proxyInvocationInfoMap);
    EJBHomeImpl homeImpl = handler;
    // Maintain insertion order
    Set proxyInterfacesSet = new LinkedHashSet();
    addProxyInterfacesSetClass(proxyInterfacesSet, false);
    proxyInterfacesSet.add(homeIntf);
    Class[] proxyInterfaces = (Class[]) proxyInterfacesSet.toArray(new Class[proxyInterfacesSet.size()]);
    try {
        EJBHome ejbHomeProxy = (EJBHome) Proxy.newProxyInstance(loader, proxyInterfaces, handler);
        handler.setProxy(ejbHomeProxy);
    } catch (ClassCastException e) {
        String msg = localStrings.getLocalString("ejb.basecontainer_invalid_home_interface", "Home interface [{0}] is invalid since it does not extend javax.ejb.EJBHome.", homeIntf);
        throw new IllegalArgumentException(msg, e);
    }
    homeImpl.setContainer(this);
    return homeImpl;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) EJBHome(javax.ejb.EJBHome)

Example 2 with EJBHome

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

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

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

the class BeanContext method mapHomeInterface.

private void mapHomeInterface(final Class intrface) {
    final Method[] homeMethods = intrface.getMethods();
    for (final Method method : homeMethods) {
        final Class owner = method.getDeclaringClass();
        if (owner == EJBHome.class || owner == EJBLocalHome.class) {
            continue;
        }
        try {
            Method beanMethod = null;
            if (method.getName().startsWith("create")) {
                final StringBuilder ejbCreateName = new StringBuilder(method.getName());
                ejbCreateName.replace(0, 1, "ejbC");
                beanMethod = beanClass.getMethod(ejbCreateName.toString(), method.getParameterTypes());
                getLegacyView().createMethod = beanMethod;
                /*
                    Entity beans have a ejbCreate and ejbPostCreate methods with matching
                    parameters. This code maps that relationship.
                    */
                if (this.componentType == BeanType.BMP_ENTITY || this.componentType == BeanType.CMP_ENTITY) {
                    ejbCreateName.insert(3, "Post");
                    Class clazz = beanClass;
                    if (getCmp().cmpImplClass != null) {
                        clazz = getCmp().cmpImplClass;
                    }
                    final Method postCreateMethod = clazz.getMethod(ejbCreateName.toString(), method.getParameterTypes());
                    getCmp().postCreateMethodMap.put(getLegacyView().createMethod, postCreateMethod);
                }
            /*
                     * Stateless session beans only have one create method. The getCreateMethod is
                     * used by instance manager of the core.stateless.StatelessContainer as a convenience
                     * method for obtaining the ejbCreate method.
                    */
            } else if (method.getName().startsWith("find")) {
                if (this.componentType == BeanType.BMP_ENTITY) {
                    final String beanMethodName = "ejbF" + method.getName().substring(1);
                    beanMethod = beanClass.getMethod(beanMethodName, method.getParameterTypes());
                }
            } else {
                final String beanMethodName = "ejbHome" + method.getName().substring(0, 1).toUpperCase() + method.getName().substring(1);
                beanMethod = beanClass.getMethod(beanMethodName, method.getParameterTypes());
            }
            if (beanMethod != null) {
                mapMethods(method, beanMethod);
            }
        } catch (final NoSuchMethodException nsme) {
        // throw new OpenEJBRuntimeException("Invalid method [" + method + "] Not declared by " + beanClass.getName() + " class");
        }
    }
}
Also used : EJBHome(javax.ejb.EJBHome) Method(java.lang.reflect.Method) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) EJBLocalHome(javax.ejb.EJBLocalHome)

Example 5 with EJBHome

use of javax.ejb.EJBHome 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)

Aggregations

EJBHome (javax.ejb.EJBHome)67 RemoteException (java.rmi.RemoteException)15 EJBObject (javax.ejb.EJBObject)11 InitialContext (javax.naming.InitialContext)10 HomeHandle (javax.ejb.HomeHandle)8 ObjectNotFoundException (javax.ejb.ObjectNotFoundException)7 EJBException (javax.ejb.EJBException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 Method (java.lang.reflect.Method)3 MarshalledObject (java.rmi.MarshalledObject)3 EJBLocalHome (javax.ejb.EJBLocalHome)2 EJBMetaData (javax.ejb.EJBMetaData)2 Handle (javax.ejb.Handle)2 RemoveException (javax.ejb.RemoveException)2 PortableRemoteObject (javax.rmi.PortableRemoteObject)2 Test (org.junit.Test)2 InvalidServiceException (com.ing.ifsa.internal.exceptions.InvalidServiceException)1