Search in sources :

Example 11 with RpcContainer

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);
}
Also used : RpcContainer(org.apache.openejb.RpcContainer)

Example 12 with RpcContainer

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);
    }
}
Also used : ProxyInfo(org.apache.openejb.ProxyInfo) RpcContainer(org.apache.openejb.RpcContainer) Collection(java.util.Collection) ArrayList(java.util.ArrayList) RemoteException(java.rmi.RemoteException)

Aggregations

RpcContainer (org.apache.openejb.RpcContainer)12 Method (java.lang.reflect.Method)3 ApplicationException (org.apache.openejb.ApplicationException)3 BeanContext (org.apache.openejb.BeanContext)3 RemoteException (java.rmi.RemoteException)2 ProxyInfo (org.apache.openejb.ProxyInfo)2 Assembler (org.apache.openejb.assembler.classic.Assembler)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)2 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)2 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)2 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)2 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)2 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)2 ContainerSystem (org.apache.openejb.spi.ContainerSystem)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EJBException (javax.ejb.EJBException)1