Examples of EJBResponse


Examples of org.ow2.easybeans.rpc.api.EJBResponse

     */
    @Override
    public EJBResponse localCall(final EJBLocalRequest localCallRequest) {

        // build EJB Response and set the id
        EJBResponse ejbResponse = new JEJBResponse();

        EasyBeansSLSB bean = null;
        try {
            bean = getBean(null);
        } catch (IllegalArgumentException e) {
            ejbResponse.setRPCException(new RPCException("Cannot get element in the pool", e));
            return ejbResponse;
        } catch (NoSuchEJBException e) {
            ejbResponse.setRPCException(new RPCException("Bean has been removed", e));
            return ejbResponse;
        }

        Method m = getHashes().get(localCallRequest.getMethodHash());

        if (m == null) {
            ejbResponse.setRPCException(new RPCException("Cannot find method called on the bean '" + getClassName() + "'.",
                    new NoSuchMethodException("The method is not found on the bean")));
            return ejbResponse;
        }

        Object value = null;

        // set ClassLoader
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getContainer().getClassLoader());

        // Busines interface
        String oldInvokedBusinessInterface = getInvokedBusinessInterfaceNameThreadLocal().get();
        getInvokedBusinessInterfaceNameThreadLocal().set(localCallRequest.getInvokedBusinessInterfaceName());

        // Operation state
        OperationState oldState = getOperationState();
        getOperationStateThreadLocal().set(BUSINESS_METHOD);

        // Dispatch the bean invocation begin event.
        String methodEventProviderId = getJ2EEManagedObjectId() + "/" + J2EEManagedObjectNamingHelper.getMethodSignature(m)
                    + "@Local";
        boolean enabledEvent = !localCallRequest.isCalledFromRemoteRequest();

        EZBEventBeanInvocation event = null;
        long number = 0;

        IAuditID previousID = null;
        // Compute and send begin event only if required
        if (enabledEvent) {
            // Invocation ID
            if (getCurrentInvocationID() != null) {
                previousID = getCurrentInvocationID().newInvocation();
            }

            event = getInvocationEventBegin(methodEventProviderId, localCallRequest.getMethodArgs());
            number = event.getInvocationNumber();
            getEventDispatcher().dispatch(event);
        }

        // Invoke method
        try {
            value = m.invoke(bean, localCallRequest.getMethodArgs());
        } catch (IllegalArgumentException e) {
            ejbResponse.setRPCException(new RPCException(e));
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
            }
        } catch (IllegalAccessException e) {
            ejbResponse.setRPCException(new RPCException(e));
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            RPCException rpcException = new RPCException(cause);
            // ApplicationException ?
            ApplicationException applicationException = getBeanInfo().getApplicationExceptions().get(cause.getClass().getName());
            if (applicationException != null) {
                rpcException.setApplicationException();
            }
            ejbResponse.setRPCException(rpcException);
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
            }
        } finally {
            // send events only if not called remotely
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationEnd(methodEventProviderId, number, value));
                // Restore previous ID
                if (getCurrentInvocationID() != null) {
                    getCurrentInvocationID().setAuditID(previousID);
                }
            }

            Thread.currentThread().setContextClassLoader(oldClassLoader);
            getInvokedBusinessInterfaceNameThreadLocal().set(oldInvokedBusinessInterface);
            getOperationStateThreadLocal().set(oldState);

            // push back into the pool
            try {
                getPool().release(bean);
            } catch (PoolException e) {
                ejbResponse.setRPCException(new RPCException("cannot release bean", e));
            }

        }
        ejbResponse.setValue(value);
        return ejbResponse;
    }
View Full Code Here

Examples of org.ow2.easybeans.rpc.api.EJBResponse

    @Override
    public EJBResponse localCall(final EJBLocalRequest localCallRequest) {
        Long id = getId(localCallRequest.getBeanId());

        // build EJB Response and set the id
        EJBResponse ejbResponse = new JEJBResponse();
        ejbResponse.setBeanId(id);

        EasyBeansSFSB bean = null;
        try {
            bean = getBean(id);
        } catch (IllegalArgumentException e) {
            ejbResponse.setRPCException(new RPCException("Cannot get element in the pool", e));
            return ejbResponse;
        } catch (NoSuchEJBException e) {
            ejbResponse.setRPCException(new RPCException("Bean has been removed", e));
            return ejbResponse;
        }

        Method m = getHashes().get(localCallRequest.getMethodHash());

        if (m == null) {
            ejbResponse.setRPCException(new RPCException("Cannot find method called on the bean '" + getClassName() + "'.",
                    new NoSuchMethodException("The method is not found on the bean")));
            return ejbResponse;
        }

        Object value = null;

        // set ClassLoader
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getContainer().getClassLoader());
        // Set InvokedBusiness Interface
        String oldInvokedBusinessInterface = getInvokedBusinessInterfaceNameThreadLocal().get();
        getInvokedBusinessInterfaceNameThreadLocal().set(localCallRequest.getInvokedBusinessInterfaceName());

        // Operation state
        OperationState oldState = getOperationState();
        getOperationStateThreadLocal().set(BUSINESS_METHOD);



        // Dispatch the bean invocation begin event.
        String methodEventProviderId = getJ2EEManagedObjectId() + "/" + J2EEManagedObjectNamingHelper.getMethodSignature(m)
                    + "@Local";
        boolean enabledEvent = !localCallRequest.isCalledFromRemoteRequest();

        EZBEventBeanInvocation event = null;
        long number = 0;

        // Invocation ID
        IAuditID previousID = null;
        // Compute and send begin event only if required
        if (enabledEvent) {
            if (getCurrentInvocationID() != null) {
                previousID = getCurrentInvocationID().newInvocation();
            }
            event = getInvocationEventBegin(methodEventProviderId, localCallRequest.getMethodArgs());
            number = event.getInvocationNumber();
            getEventDispatcher().dispatch(event);
        }

        synchronized (bean) {
            try {
                value = m.invoke(bean, localCallRequest.getMethodArgs());
            } catch (IllegalArgumentException e) {
                ejbResponse.setRPCException(new RPCException(e));
                if (enabledEvent) {
                    getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
                }
            } catch (IllegalAccessException e) {
                ejbResponse.setRPCException(new RPCException(e));
                if (enabledEvent) {
                    getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
                }
            } catch (InvocationTargetException e) {
                Throwable cause = e.getCause();
                RPCException rpcException = new RPCException(cause);
                // ApplicationException ?
                ApplicationException applicationException = getBeanInfo().getApplicationExceptions().get(
                        cause.getClass().getName());
                if (applicationException != null) {
                    rpcException.setApplicationException();
                }
                ejbResponse.setRPCException(rpcException);
                if (enabledEvent) {
                    getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
                }
            } finally {
                Thread.currentThread().setContextClassLoader(oldClassLoader);
                getInvokedBusinessInterfaceNameThreadLocal().set(oldInvokedBusinessInterface);
                getOperationStateThreadLocal().set(oldState);

                // send events only if not called remotely
                if (enabledEvent) {
                    getEventDispatcher().dispatch(new EventBeanInvocationEnd(methodEventProviderId, number, value));
                    // Restore previous ID
                    if (getCurrentInvocationID() != null) {
                        getCurrentInvocationID().setAuditID(previousID);
                    }
                }

                // push back into the pool
                try {
                    getPool().release(bean);
                } catch (PoolException e) {
                    ejbResponse.setRPCException(new RPCException("cannot release bean", e));
                }

                // If the bean has been removed (stateful), flag it as a removed
                // bean, so the client won't call again any methods.
                if (bean.getEasyBeansRemoved()) {
                    ejbResponse.setRemoved(true);
                }

            }
        }
        ejbResponse.setValue(value);
        return ejbResponse;

    }
View Full Code Here

Examples of org.ow2.easybeans.rpc.api.EJBResponse

        EJBRemoteRequest request = new EJBRemoteRequestImpl(mName, hashLong, args, getContainerId(), getFactoryName(),
                getBeanId(), getInterfaceClassName());

        // send response
        EJBResponse response;
        try {
            response = client.sendEJBRequest(request);
        } catch (RuntimeException e) {
            // Exception due to protocol
            throw new EJBException("Error while sending a request", e);
        }
        // Sets the bean ID
        setBeanId(response.getBeanId());

        // toString() call on the remote side for initializing the bean id is done
        // so we return toString() computing
        if (method.getDeclaringClass().getName().equals("java.lang.Object")) {
            if (getBeanId() != null && method.getName().equals("toString")) {
                return handleObjectMethods(method, args);
            }
        }


        // bean removed ?
        setRemoved(response.isRemoved());

        // Handle exception
        RPCException rpcException = response.getRPCException();
        if (rpcException != null) {
            handleThrowable(convertThrowable(rpcException.getCause()), rpcException.isApplicationException(), method,
                    rpcException);
        }

        // Needs to rebuild the proxy as we only have the invocation handler
        if (RECREATE_DYNAMIC_PROXY) {
            Object value = response.getValue();
            if (value != null) {
                if (value instanceof ClientRPCInvocationHandler) {
                    ClientRPCInvocationHandler invocationHandler = (ClientRPCInvocationHandler) value;
                    if (invocationHandler.isBusinessObjectMode()) {
                        Class<?> interfaceClass = Thread.currentThread().getContextClassLoader().loadClass(
                                invocationHandler.getInterfaceClassName());
                        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                                new Class[] {interfaceClass}, invocationHandler);
                    }
                }
            }
        }


        return response.getValue();
    }
View Full Code Here

Examples of org.ow2.easybeans.rpc.api.EJBResponse

            hashLong = hashMethod;
        }

        // Now, need to invoke the bean
        EJBLocalRequest localRequest = new EJBLocalRequestImpl(hashLong, args, getBeanId(), getInterfaceClassName());
        EJBResponse response = this.factory.localCall(localRequest);
        setBeanId(response.getBeanId());

        // toString() call on the remote side for initializing the bean id is done
        // so we return toString() computing
        if (method.getDeclaringClass().getName().equals("java.lang.Object")) {
            if (getBeanId() != null && method.getName().equals("toString")) {
                return handleObjectMethods(method, args);
            }
        }

        // bean removed ?
        setRemoved(response.isRemoved());

        RPCException rpcException = response.getRPCException();
        if (rpcException != null) {
            handleThrowable(rpcException.getCause(), rpcException.isApplicationException(), method, rpcException);
        }




        return response.getValue();

    }
View Full Code Here

Examples of org.ow2.easybeans.rpc.api.EJBResponse

                    .getInvokedBusinessInterfaceName());
            // Avoid to send events as local calls
            localRequest.setCalledFromRemoteRequest(true);

            // call the method
            EJBResponse result = localCall(localRequest);

            // Create the bean invocation end event.
            event = new EventBeanInvocationEnd(methodEventProviderId, number, result);

            // JacORB enabled ? Needs to return the invocation handler instead of the dynamic proxy to the client proxy
            if (RECREATE_DYNAMIC_PROXY) {
                Object value = result.getValue();
                if (value != null) {
                    try {
                        InvocationHandler handler = Proxy.getInvocationHandler(value);
                        if (handler instanceof ClientRPCInvocationHandler
                                && ((ClientRPCInvocationHandler) handler).isBusinessObjectMode()) {
                            result.setValue(handler);
                            return result;
                        }
                    } catch (IllegalArgumentException e) {
                        logger.debug("Not a proxy instance", e);
                    }
View Full Code Here

Examples of org.ow2.easybeans.rpc.api.EJBResponse

     * @return response with the value of the call and the bean ID (if any)
     */
    @Override
    public EJBResponse localCall(final EJBLocalRequest localCallRequest) {
        // build EJB Response and set the id
        EJBResponse ejbResponse = new JEJBResponse();

        EasyBeansSingletonSB bean = null;
        try {
            bean = getBean(null);
        } catch (IllegalArgumentException e) {
            ejbResponse.setRPCException(new RPCException("Cannot get element in the pool", e));
            return ejbResponse;
        } catch (NoSuchEJBException e) {
            ejbResponse.setRPCException(new RPCException("Bean has been removed", e));
            return ejbResponse;
        }

        Method m = getHashes().get(localCallRequest.getMethodHash());

        if (m == null) {
            ejbResponse.setRPCException(new RPCException("Cannot find method called on the bean '" + getClassName() + "'."));
            return ejbResponse;
        }

        Object value = null;

        // set ClassLoader
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getContainer().getClassLoader());

        // Busines interface
        String oldInvokedBusinessInterface = getInvokedBusinessInterfaceNameThreadLocal().get();
        getInvokedBusinessInterfaceNameThreadLocal().set(localCallRequest.getInvokedBusinessInterfaceName());

        // Operation state
        OperationState oldState = getOperationState();
        getOperationStateThreadLocal().set(BUSINESS_METHOD);



        // Dispatch the bean invocation begin event.
        String methodEventProviderId = getJ2EEManagedObjectId() + "/" + J2EEManagedObjectNamingHelper.getMethodSignature(m)
                    + "@Local";
        boolean enabledEvent = !localCallRequest.isCalledFromRemoteRequest();

        EZBEventBeanInvocation event = null;
        long number = 0;
        IAuditID previousID = null;

        // Compute and send begin event only if required
        if (enabledEvent) {
            // Invocation ID
            if (getCurrentInvocationID() != null) {
                previousID = getCurrentInvocationID().newInvocation();
            }
            event = getInvocationEventBegin(methodEventProviderId, localCallRequest.getMethodArgs());
            number = event.getInvocationNumber();
            getEventDispatcher().dispatch(event);
        }

        // TODO: manage lock per method and read or write lock !
        // for now, use only write lock

        // acquire lock
        Lock writeLock = this.lock.writeLock();
        writeLock.lock();

        try {
            value = m.invoke(bean, localCallRequest.getMethodArgs());
        } catch (IllegalArgumentException e) {
            ejbResponse.setRPCException(new RPCException(e));
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
            }
        } catch (IllegalAccessException e) {
            ejbResponse.setRPCException(new RPCException(e));
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            RPCException rpcException = new RPCException(cause);
            // ApplicationException ?
            ApplicationException applicationException = getBeanInfo().getApplicationExceptions().get(cause.getClass().getName());
            if (applicationException != null) {
                rpcException.setApplicationException();
            }
            ejbResponse.setRPCException(rpcException);
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationError(methodEventProviderId, number, e));
            }
        } finally {
            if (enabledEvent) {
                getEventDispatcher().dispatch(new EventBeanInvocationEnd(methodEventProviderId, number, value));
                // Restore previous ID
                if (getCurrentInvocationID() != null) {
                    getCurrentInvocationID().setAuditID(previousID);
                }
            }

            Thread.currentThread().setContextClassLoader(oldClassLoader);
            getInvokedBusinessInterfaceNameThreadLocal().set(oldInvokedBusinessInterface);
            getOperationStateThreadLocal().set(oldState);

            // push back into the pool
            try {
                getPool().release(bean);
            } catch (PoolException e) {
                ejbResponse.setRPCException(new RPCException("cannot release bean", e));
            }
            // release lock
            writeLock.unlock();
        }
        ejbResponse.setValue(value);
        return ejbResponse;

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.