Search in sources :

Example 6 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRequestHandler method doEjbHome_METHOD.

protected void doEjbHome_METHOD(final EJBRequest req, final EJBResponse res) throws Exception {
    final CallContext call = CallContext.getCallContext();
    final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer();
    final Object result = c.invoke(req.getDeploymentId(), InterfaceType.EJB_HOME, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
    res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, result);
}
Also used : RpcContainer(org.apache.openejb.RpcContainer)

Example 7 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRequestHandler method doEjbHome_CREATE.

protected void doEjbHome_CREATE(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());
    if (result instanceof ProxyInfo) {
        final ProxyInfo info = (ProxyInfo) result;
        res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, info.getPrimaryKey());
    } else {
        result = new RemoteException("The bean is not EJB compliant.  The bean should be created or and exception should be thrown.");
        logger.error(req + "The bean is not EJB compliant.  The bean should be created or and exception should be thrown.");
        res.setResponse(req.getVersion(), ResponseCodes.EJB_SYS_EXCEPTION, new ThrowableArtifact((Throwable) result));
    }
}
Also used : ProxyInfo(org.apache.openejb.ProxyInfo) RpcContainer(org.apache.openejb.RpcContainer) ThrowableArtifact(org.apache.openejb.client.ThrowableArtifact) RemoteException(java.rmi.RemoteException)

Example 8 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRequestHandler method doEjbHome_REMOVE_BY_PKEY.

protected void doEjbHome_REMOVE_BY_PKEY(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 9 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRequestHandler method doEjbObject_BUSINESS_METHOD.

protected void doEjbObject_BUSINESS_METHOD(final EJBRequest req, final EJBResponse res) throws Exception {
    final CallContext call = CallContext.getCallContext();
    final BeanContext beanContext = call.getBeanContext();
    final boolean asynchronous = beanContext.isAsynchronous(req.getMethodInstance());
    try {
        if (asynchronous) {
            final AtomicBoolean invocationCancelTag = new AtomicBoolean(false);
            ThreadContext.initAsynchronousCancelled(invocationCancelTag);
            asynchronousInvocationCancelMap.put(req.getBody().getRequestId(), invocationCancelTag);
        }
        final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer();
        //            Object result = c.invoke(req.getDeploymentId(),
        //                    req.getInterfaceClass(), req.getMethodInstance(),
        //                    req.getMethodParameters(),
        //                    req.getPrimaryKey()
        //            );
        final EJBDSerializer serializer = daemon.getSerializer();
        if (serializer != null) {
            req.setSerializer(serializer);
        }
        Object result = c.invoke(req.getDeploymentId(), InterfaceType.EJB_OBJECT, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
        //Pass the internal value to the remote client, as AsyncResult is not serializable
        if (result != null && asynchronous) {
            result = ((Future) result).get();
        }
        final Object realResult;
        if (serializer != null && result != null) {
            realResult = new SerializationWrapper(serializer.serialize(result), result.getClass().getName());
        } else {
            realResult = result;
        }
        res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, realResult);
    } finally {
        if (asynchronous) {
            ThreadContext.removeAsynchronousCancelled();
            asynchronousInvocationCancelMap.remove(req.getBody().getRequestId());
        }
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SerializationWrapper(org.apache.openejb.client.serializer.SerializationWrapper) RpcContainer(org.apache.openejb.RpcContainer) EJBDSerializer(org.apache.openejb.client.serializer.EJBDSerializer)

Example 10 with RpcContainer

use of org.apache.openejb.RpcContainer in project tomee by apache.

the class EjbRequestHandler method doEjbObject_REMOVE.

protected void doEjbObject_REMOVE(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_OBJECT, req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey());
    res.setResponse(req.getVersion(), ResponseCodes.EJB_OK, null);
}
Also used : RpcContainer(org.apache.openejb.RpcContainer)

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