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;
}
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));
}
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));
}
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");
}
}
}
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();
}
}
}
Aggregations