use of org.apache.openejb.RpcContainer in project tomee by apache.
the class EjbRequestHandler method doEjbHome_REMOVE_BY_HANDLE.
protected void doEjbHome_REMOVE_BY_HANDLE(final EJBRequest req, final EJBResponse res) throws Exception {
final CallContext call = CallContext.getCallContext();
final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer();
c.invoke(req.getDeploymentId(), InterfaceType.EJB_HOME, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, null);
}
use of org.apache.openejb.RpcContainer in project tomee by apache.
the class EjbRequestHandler method doEjbHome_FIND.
protected void doEjbHome_FIND(final EJBRequest req, final EJBResponse res) throws Exception {
final CallContext call = CallContext.getCallContext();
final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer();
Object result = c.invoke(req.getDeploymentId(), InterfaceType.EJB_HOME, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
/* Multiple instances found */
if (result instanceof Collection) {
final Object[] primaryKeys = ((Collection) result).toArray();
for (int i = 0; i < primaryKeys.length; i++) {
final ProxyInfo proxyInfo = ((ProxyInfo) primaryKeys[i]);
if (proxyInfo == null) {
primaryKeys[i] = null;
} else {
primaryKeys[i] = proxyInfo.getPrimaryKey();
}
}
res.setResponse(req.getVersion(), ResponseCodes.EJB_OK_FOUND_COLLECTION, primaryKeys);
} else if (result instanceof java.util.Enumeration) {
final java.util.Enumeration resultAsEnum = (java.util.Enumeration) result;
final java.util.List<Object> listOfPKs = new ArrayList<Object>();
while (resultAsEnum.hasMoreElements()) {
final ProxyInfo proxyInfo = ((ProxyInfo) resultAsEnum.nextElement());
if (proxyInfo == null) {
listOfPKs.add(null);
} else {
listOfPKs.add(proxyInfo.getPrimaryKey());
}
}
res.setResponse(req.getVersion(), ResponseCodes.EJB_OK_FOUND_ENUMERATION, listOfPKs.toArray(new Object[listOfPKs.size()]));
/* Single instance found */
} else if (result instanceof ProxyInfo) {
final ProxyInfo proxyInfo = ((ProxyInfo) result);
result = proxyInfo.getPrimaryKey();
res.setResponse(req.getVersion(), ResponseCodes.EJB_OK_FOUND, result);
} else if (result == null) {
res.setResponse(req.getVersion(), ResponseCodes.EJB_OK_FOUND, null);
} else {
final String message = "The bean is not EJB compliant. " + "The finder method [" + req.getMethodInstance().getName() + "] is declared " + "to return neither Collection nor the Remote Interface, " + "but [" + result.getClass().getName() + "]";
result = new RemoteException(message);
logger.error(req + " " + message);
res.setResponse(req.getVersion(), ResponseCodes.EJB_SYS_EXCEPTION, result);
}
}
Aggregations