use of jakarta.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();
}
}
}
use of jakarta.ejb.EJBObject in project tomee by apache.
the class EntityContext method getEJBObject.
public EJBObject getEJBObject() throws IllegalStateException {
doCheck(Call.getEJBObject);
final ThreadContext threadContext = ThreadContext.getThreadContext();
final BeanContext di = threadContext.getBeanContext();
if (di.getRemoteInterface() == null) {
throw new IllegalStateException("EJB " + di.getDeploymentID() + " does not have a remote interface");
}
final EjbObjectProxyHandler handler = new EntityEjbObjectHandler(di.getContainer().getBeanContext(di.getDeploymentID()), threadContext.getPrimaryKey(), InterfaceType.EJB_OBJECT, new ArrayList<>(), di.getRemoteInterface());
try {
final Class[] interfaces = new Class[] { di.getRemoteInterface(), IntraVmProxy.class };
return (EJBObject) ProxyManager.newProxyInstance(interfaces, handler);
} catch (final IllegalAccessException iae) {
throw new InternalErrorException("Could not create IVM proxy for " + di.getRemoteInterface() + " interface", iae);
}
}
use of jakarta.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());
}
use of jakarta.ejb.EJBObject in project tomee by apache.
the class CmpRmiIiopTests method test54_returnHandleArray.
public void test54_returnHandleArray() {
try {
final Object obj = initialContext.lookup("client/tests/entity/cmp/EncBean");
final EncCmpHome home = (EncCmpHome) obj;
assertNotNull("The EJBHome returned from JNDI is null", home);
final EncCmpObject object = home.create("test_54 CmpBean");
assertNotNull("The EJBObject created is null", object);
final Handle[] expected = new Handle[3];
for (int i = 0; i < expected.length; i++) {
expected[i] = object.getHandle();
assertNotNull("The EJBObject Handle returned is null", expected[i]);
}
final Handle[] actual = (Handle[]) ejbObject.returnHandleArray(expected);
assertNotNull("The Handle array returned is null", actual);
assertEquals(expected.length, actual.length);
for (int i = 0; i < expected.length; i++) {
assertNotNull("The EJBObject Handle returned is null", actual[i]);
assertNotNull("The EJBObject in the Handle is null", actual[i].getEJBObject());
assertTrue("The EJBObjects in the Handles are not equal", expected[i].getEJBObject().isIdentical(actual[i].getEJBObject()));
}
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
use of jakarta.ejb.EJBObject in project tomee by apache.
the class CmpRmiIiopTests method test44_returnEJBObjectArray.
public void test44_returnEJBObjectArray() {
try {
final Object obj = initialContext.lookup("client/tests/entity/cmp/EncBean");
final EncCmpHome home = (EncCmpHome) obj;
assertNotNull("The EJBHome returned from JNDI is null", home);
final EncCmpObject[] expected = new EncCmpObject[3];
for (int i = 0; i < expected.length; i++) {
expected[i] = home.create("test_44 CmpBean");
assertNotNull("The EJBObject created is null", expected[i]);
}
final EJBObject[] actual = ejbObject.returnEJBObjectArray(expected);
assertNotNull("The EJBObject array returned is null", actual);
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i++) {
assertTrue("The EJBObejcts are not identical", expected[i].isIdentical(actual[i]));
}
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
Aggregations