Package org.ow2.easybeans.rpc

Examples of org.ow2.easybeans.rpc.JEJBResponse


    @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


        Method calledMethod = getHashes().get(request.getMethodHash());
        // Invalid method
        if (calledMethod == null) {
            logger.debug("Requested method {0} is not present on the bean class ''{1}''", request.getMethodName(),
                    getBeanClass());
            return new JEJBResponse();
        }

        // Get Args (use context classloader for the Serialization)
        Object[] args = null;
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
View Full Code Here

     * @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

            // Register Object MBean
            try {
                CommonsModelerHelper.registerModelerMBean(standardContext, objectName);
            } catch (CommonsModelerException e) {
                throw new DeployerException("Cannot register the object '" + standardContext + "' with the objectname '"
                        + objectName + "'.", e);
            }

            // set the context-root

            standardContext.setPath(war.getContextRoot());

            // Get the URL for this War
            URL warURL = null;
            try {
                warURL = war.getArchive().getURL();
            } catch (ArchiveException e) {
                throw new DeployerException("Cannot get the URL for the archive '" + war.getArchive() + "'.", e);
            }


            // Analyze the war archive
            IWarDeployableMetadata warDeployableMetadata = null;
            try {
                warDeployableMetadata = new WarDeployableMetadataFactory().createDeployableMetadata(war);
            } catch (DeployableMetadataException e) {
                logger.error("Unable to analyze the metadata of the war '" + warURL + "'.", e);
            }

            // Now, get the bindings for this web application
            ENCBindingHolder encBindingHolder = null;
            if (warDeployableMetadata != null) {
                try {
                    encBindingHolder = ENCBindingBuilder.analyze(warDeployableMetadata);
                } catch (ENCBindingException e) {
                    logger.error("Unable to analyze metadata of '" + warURL + "'", e);
                }
            }

            // File of this war
            File warFile = URLUtils.urlToFile(warURL);

            // docbase
            String docBase = warFile.getPath();

            // File and not a directory --> unpack it
            if (warFile.isFile()) {
                // Need to unpack the file
                File unpackDir = unpack(warFile, war, earURL);
                docBase = unpackDir.getPath();
            }

            // set the path to the war file (needs to be unpacked else it will
            // be unpacked by tomcat in the webapps folder and it will try to
            // deploy twice the webapp with wrong classloader)
            standardContext.setDocBase(docBase);

            // default XML files
            standardContext.setDefaultWebXml("conf/web.xml");
            standardContext.setDefaultContextXml("context.xml");


            File contextXmlFile = new File(docBase + File.separator + "META-INF" + File.separator + "context.xml");
            // META-INF/context.xml file support
            if (contextXmlFile.exists()) {
                standardContext.setConfigFile(contextXmlFile.getAbsolutePath());
            }

            // Set the parent class loader
            standardContext.setParentClassLoader(parentClassLoader);

            // Set the java delegation model
            standardContext.setDelegate(true);

            // Set our naming context listener
            EasyBeansNamingContextListener namingContextListener = new EasyBeansNamingContextListener();
            namingContextListener.setEncBindingHolder(encBindingHolder);
            namingContextListener.setInjectionHolder(ejbInjectionHolder);
            namingContextListener.setName(getNamingContextName(standardContext));
            standardContext.addLifecycleListener(namingContextListener);
            standardContext.setNamingContextListener(namingContextListener);

            // Start the context
            try {
                standardContext.start();
            } catch (LifecycleException e) {
                throw new DeployerException("Cannot start the context of the War '" + warURL + "'.", e);
            }

            // War has been deployed
            logger.info("The war ''{0}'' has been deployed on the ''{1}'' context.", war, war.getContextRoot());
        }
View Full Code Here

        // Now, search the MBean of this context
        ObjectName contextObjectName = null;
        try {
            contextObjectName = new ObjectName(buildObjectName(warDeployable));
        } catch (MalformedObjectNameException e) {
            throw new DeployerException("Cannot get the ObjectName for the WAR deployable '" + warDeployable + "'.", e);
        } catch (NullPointerException e) {
            throw new DeployerException("Cannot get the ObjectName for the WAR deployable '" + warDeployable + "'.", e);
        }

        // Now, search if the MBean of this context is present
        try {
            if (!MBeanServerHelper.getMBeanServerServer().isRegistered(contextObjectName)) {
                throw new DeployerException("There is no MBean with the ObjectName '" + contextObjectName
                        + "' in the MBean Server for the WAR deployable '" + warDeployable + "'.");
            }
        } catch (JMXRemoteException e) {
            throw new DeployerException("Cannot check if the MBean with the ObjectName '" + contextObjectName
                    + "'is registered in the MBean Server for the WAR deployable '" + warDeployable + "'.");
        }

        // Undeploy
        try {
            MBeanServerHelper.getMBeanServerServer().invoke(contextObjectName, DESTROY_OPERATION, null, null);
        } catch (InstanceNotFoundException e) {
            throw new DeployerException("Cannot remove the context '" + contextRoot + "' of the war deployable '"
                    + warDeployable + "'.", e);
        } catch (MBeanException e) {
            throw new DeployerException("Cannot remove the context '" + contextRoot + "' of the war deployable '"
                    + warDeployable + "'.", e);
        } catch (ReflectionException e) {
            throw new DeployerException("Cannot remove the context '" + contextRoot + "' of the war deployable '"
                    + warDeployable + "'.", e);
        } catch (JMXRemoteException e) {
            throw new DeployerException("Cannot remove the context '" + contextRoot + "' of the war deployable '"
                    + warDeployable + "'.", e);
        }

        logger.info("The context ''{0}'' of the War ''{1}'' has been undeployed", contextRoot, warDeployable);
    }
View Full Code Here

        // Build Engine object name
        ObjectName engineObjectName = null;
        try {
            engineObjectName = new ObjectName(ENGINE_OBJECT_NAME);
        } catch (MalformedObjectNameException e) {
            throw new DeployerException("Cannot build Tomcat Engine MBean.", e);
        } catch (NullPointerException e) {
            throw new DeployerException("Cannot build Tomcat Engine MBean.", e);
        }

        // Ask the MBean server
        Set<ObjectName> objectNames = null;
        try {
            // Get the list
            objectNames = MBeanServerHelper.getMBeanServerServer().queryNames(engineObjectName, null);
        } catch (JMXRemoteException e) {
            throw new DeployerException("Cannot get Tomcat Engine MBean.", e);
        }

        // Find objects ?
        if (objectNames.size() == 0) {
            throw new DeployerException("No Tomcat Engine MBean was found in the MBean server");
        }

        // Return the domain of this object name
        return (objectNames.iterator().next());
    }
View Full Code Here

    private String getDefaultHost() throws DeployerException {
        ObjectName engineObjectName = getEngineObjectName();
        try {
            return MBeanServerHelper.getMBeanServerServer().getAttribute(engineObjectName, "defaultHost").toString();
        } catch (AttributeNotFoundException e) {
            throw new DeployerException("Cannot get the default host on the object name '" + engineObjectName + "'.", e);
        } catch (InstanceNotFoundException e) {
            throw new DeployerException("Cannot get the default host on the object name '" + engineObjectName + "'.", e);
        } catch (MBeanException e) {
            throw new DeployerException("Cannot get the default host on the object name '" + engineObjectName + "'.", e);
        } catch (ReflectionException e) {
            throw new DeployerException("Cannot get the default host on the object name '" + engineObjectName + "'.", e);
        } catch (JMXRemoteException e) {
            throw new DeployerException("Cannot get the default host on the object name '" + engineObjectName + "'.", e);
        }
    }
View Full Code Here

        }

        // Client Archive ?
        if (CARDeployable.class.isInstance(deployable)) {
            // Create metadata
            ICarDeployableMetadata carDeployableMetadata = null;
            try {
                carDeployableMetadata = new CarDeployableMetadataFactory().createDeployableMetadata(CARDeployable.class
                        .cast(deployable), classLoader);
            } catch (DeployableMetadataException e) {
                throw new ArchiveInjectionException("Unable to get metadata on archive '" + this.archive + "'.", e);
            }

            // Use only common part
            this.metadataCollection = carDeployableMetadata.getCarClassMetadataCollection();
        } else {
            // TODO : adapt for other archives
            throw new UnsupportedOperationException("Can only manage injection for Client Deployable. Deployable found is '"
                    + deployable + "'.");
        }
View Full Code Here

        // Client Archive ?
        if (CARDeployable.class.isInstance(deployable)) {
            // Create metadata
            ICarDeployableMetadata carDeployableMetadata = null;
            try {
                carDeployableMetadata = new CarDeployableMetadataFactory().createDeployableMetadata(CARDeployable.class
                        .cast(deployable), classLoader);
            } catch (DeployableMetadataException e) {
                throw new ArchiveInjectionException("Unable to get metadata on archive '" + this.archive + "'.", e);
            }
View Full Code Here

            // inject field
            injectEJB(jejb, sharedMetadata, clazz, instance);
        }

        // Inject Resources
        IJAnnotationResource jAnnotationResource = sharedMetadata.getJAnnotationResource();
        if (jAnnotationResource != null) {
            // Update interface name
            jAnnotationResource.setType(getInterfaceName(sharedMetadata));

            // inject field
            injectResource(jAnnotationResource, sharedMetadata, clazz, instance);
        }
View Full Code Here

TOP

Related Classes of org.ow2.easybeans.rpc.JEJBResponse

Copyright © 2018 www.massapicom. 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.