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 Payara by payara.
the class EJBHomeInvocationHandler method invoke.
/**
* Called by EJBHome proxy.
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
ClassLoader originalClassLoader = null;
// if method signature has 0 arguments.
try {
((BaseContainer) getContainer()).onEnteringContainer();
if (Thread.currentThread().getContextClassLoader() != getContainer().getClassLoader()) {
originalClassLoader = Utility.setContextClassLoader(getContainer().getClassLoader());
}
Class methodClass = method.getDeclaringClass();
if (methodClass == java.lang.Object.class) {
return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args);
} else if (invokeSpecialEJBHomeMethod(method, methodClass, args)) {
return null;
}
// Use optimized version of get that takes param count as an
// argument.
InvocationInfo invInfo = (InvocationInfo) invocationInfoMap_.get(method, ((args != null) ? args.length : 0));
if (invInfo == null) {
throw new RemoteException("Unknown Home interface method :" + method);
} else if ((methodClass == javax.ejb.EJBHome.class) || invInfo.ejbIntfOverride) {
return invokeEJBHomeMethod(method.getName(), args);
} else if (GenericEJBHome.class.isAssignableFrom(methodClass)) {
if (method.getName().equals("create")) {
// This is an internal creation request through the EJB 3.0
// client view, so just create an business object and return it
EJBObjectImpl busObjectImpl = createRemoteBusinessObjectImpl();
return busObjectImpl.getStub((String) args[0]);
} else {
EjbAsyncInvocationManager asyncManager = ((EjbContainerUtilImpl) ejbContainerUtil).getEjbAsyncInvocationManager();
Long asyncTaskID = (Long) args[0];
RemoteAsyncResult asyncResult = null;
if (method.getName().equals("cancel")) {
asyncResult = asyncManager.remoteCancel(asyncTaskID);
} else if (method.getName().equals("get")) {
asyncResult = asyncManager.remoteGet(asyncTaskID);
} else if (method.getName().equals("isDone")) {
asyncResult = asyncManager.remoteIsDone(asyncTaskID);
} else if (method.getName().equals("getWithTimeout")) {
Long timeout = (Long) args[1];
TimeUnit unit = TimeUnit.valueOf((String) args[2]);
asyncResult = asyncManager.remoteGetWithTimeout(asyncTaskID, timeout, unit);
}
return asyncResult;
}
}
// Process finder, create method, or home method.
EJBObjectImpl ejbObjectImpl = null;
Object returnValue = null;
if (invInfo.startsWithCreate) {
ejbObjectImpl = createEJBObjectImpl();
if (ejbObjectImpl != null) {
// Entity beans are created differently
returnValue = ejbObjectImpl.getStub();
}
}
if (!isStatelessSession_) {
if (invInfo.targetMethod1 == null) {
_logger.log(Level.SEVERE, "ejb.bean_class_method_not_found", new Object[] { invInfo.ejbName, "Home", invInfo.method.toString() });
// in exception use message without ID
String errorMsg = localStrings.getLocalString("ejb.bean_class_method_not_found", "", new Object[] { invInfo.ejbName, "Home", invInfo.method.toString() });
throw new RemoteException(errorMsg);
}
EjbInvocation inv = ((BaseContainer) getContainer()).createEjbInvocation();
inv.isRemote = true;
inv.method = method;
inv.isHome = true;
inv.clientInterface = homeIntfClass_;
// Set cached invocation params. This will save
// additional lookups in BaseContainer.
inv.transactionAttribute = invInfo.txAttr;
inv.invocationInfo = invInfo;
if (ejbObjectImpl != null && invInfo.startsWithCreate) {
inv.ejbObject = (EJBLocalRemoteObject) ejbObjectImpl;
}
BaseContainer container = (BaseContainer) getContainer();
try {
container.preInvoke(inv);
if (invInfo.startsWithCreate) {
Object ejbCreateReturnValue = invokeTargetBeanMethod(container, invInfo.targetMethod1, inv, inv.ejb, args);
postCreate(container, inv, invInfo, ejbCreateReturnValue, args);
if (inv.ejbObject != null) {
returnValue = ((EJBObjectImpl) inv.ejbObject).getStub();
}
} else if (invInfo.startsWithFindByPrimaryKey) {
returnValue = container.invokeFindByPrimaryKey(invInfo.targetMethod1, inv, args);
} else if (invInfo.startsWithFind) {
Object pKeys = invokeTargetBeanMethod(container, invInfo.targetMethod1, inv, inv.ejb, args);
returnValue = container.postFind(inv, pKeys, null);
} else {
returnValue = invokeTargetBeanMethod(container, invInfo.targetMethod1, inv, inv.ejb, args);
}
} catch (InvocationTargetException ite) {
inv.exception = ite.getCause();
} catch (Throwable c) {
inv.exception = c;
} finally {
container.postInvoke(inv);
}
if (inv.exception != null) {
InvocationHandlerUtil.throwRemoteException(inv.exception, method.getExceptionTypes());
}
}
return returnValue;
} finally {
if (originalClassLoader != null) {
Utility.setContextClassLoader(originalClassLoader);
}
((BaseContainer) getContainer()).onLeavingContainer();
}
}
use of javax.ejb.EJBHome in project tomee by apache.
the class CrossClassLoaderProxyTest method testRemoteInterface.
public void testRemoteInterface() throws Exception {
final InitialContext ctx = new InitialContext();
final EJBHome home = (EJBHome) ctx.lookup("WidgetBeanRemoteHome");
assertNotNull("home", home);
assertTrue("home should be an instance of WidgetHome", home instanceof WidgetHome);
CrossClassLoaderProxyTestObject.widgetHome = (WidgetHome) home;
final CrossClassLoaderProxyTestObject proxyTestObject = new CrossClassLoaderProxyTestObject();
proxyTestObject.testRemoteInterface();
}
use of javax.ejb.EJBHome in project tomee by apache.
the class StatelessPojoHomeHandleTests method test01_getEJBHome.
// =================================
// Test home handle methods
//
public void test01_getEJBHome() {
try {
final EJBHome home = ejbHomeHandle.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
use of javax.ejb.EJBHome in project tomee by apache.
the class StatelessRmiIiopTests method test39_returnEJBHomeArray.
public void test39_returnEJBHomeArray() {
try {
final EncStatelessHome[] expected = new EncStatelessHome[3];
for (int i = 0; i < expected.length; i++) {
final Object obj = initialContext.lookup("client/tests/stateless/EncBean");
expected[i] = (EncStatelessHome) obj;
assertNotNull("The EJBHome returned from JNDI is null", expected[i]);
}
final EJBHome[] actual = ejbObject.returnEJBHomeArray(expected);
assertNotNull("The EJBHome array returned is null", actual);
assertEquals(expected.length, actual.length);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
Aggregations