Package org.ow2.chameleon.testing.helpers

Examples of org.ow2.chameleon.testing.helpers.OSGiHelper


        // Create classloader with these URLs
        URL[] arrayURLs = urls.toArray(new URL[urls.size()]);

        // Child of the EAR classloader with RARs
        ClassLoader ejbClassLoader = new EasyBeansClassLoader(arrayURLs, earClassLoader);

        // Get Persistence unit manager
        PersistenceUnitManager persistenceUnitManager = getPersistenceUnitManager(earDeployable, ejbClassLoader);

        // Get Extra libraries
View Full Code Here


            if (this.warService == null) {
                logger.warn("There are WAR files in the EAR ''{0}'' but the 'web' service is not available", earDeployable);
            } else {

                // Build context for sending parameters
                Context ctx = new ContextImpl(earURL.toExternalForm());
                try {
                    ctx.rebind("earURL", earURL);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the EAR URL parameter '" + earURL + "'", e);
                }
                // Get URLS of the wars and context-root
                List<URL> urls = new LinkedList<URL>();
                List<String> ctxRoots = new LinkedList<String>();
                for (WARDeployable warDeployable : wars) {

                    // URL
                    URL url = null;
                    try {
                        url = warDeployable.getArchive().getURL();
                    } catch (ArchiveException e) {
                        throw new DeployerException("Cannot get the URL for the archive '" + warDeployable.getArchive() + "'",
                                e);
                    }
                    urls.add(url);

                    // Context-root
                    ctxRoots.add(warDeployable.getContextRoot());

                }
                try {
                    ctx.rebind("urls", urls.toArray(new URL[urls.size()]));
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the urls parameter '" + urls + "'", e);
                }

                // Bind the parent classloader of the web application
                try {
                    ctx.rebind("parentClassLoader", parentClassLoader);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the parentClassLoader parameter '" + parentClassLoader + "'", e);
                }

                // Bind the earClassLoader of the web application
                try {
                    ctx.rebind("earClassLoader", earClassLoader);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the earClassLoader parameter '" + earClassLoader + "'", e);
                }

                // No alt-dd yet, give an empty array
                try {
                    ctx.rebind("altDDs", new URL[urls.size()]);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the altDDs parameter.'", e);
                }

                // Build context roots
                try {
                    ctx.rebind("contextRoots", ctxRoots.toArray(new String[ctxRoots.size()]));
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the contextRoots parameter '" + urls + "'", e);
                }

                try {
View Full Code Here

        List<RARDeployable> rars = earDeployable.getRARDeployables();
        if (rars.size() > 0) {
            if (this.rarService == null) {
                logger.warn("There are RAR files in the EAR ''{0}'' but the resource service is not available", earDeployable);
            } else {
                Context ctx = new ContextImpl(earURL.toExternalForm());
                try {
                    ctx.rebind("earUrl", earURL);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the EAR URL parameter '" + earURL + "'", e);
                }
                List<URL> urls = new ArrayList<URL>();
                for (RARDeployable rarDeployable : rars) {
                    try {
                        urls.add(rarDeployable.getArchive().getURL());
                    } catch (ArchiveException e) {
                        throw new DeployerException("Cannot get the URL for the archive '" + rarDeployable.getArchive() + "'",
                                e);
                    }
                }
                try {
                    ctx.rebind("urls", urls.toArray(new URL[urls.size()]));
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the urls parameter '" + urls + "'", e);
                }
                try {
                    ctx.rebind("earClassLoader", earClassLoader);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the earClassLoader parameter '" + earClassLoader + "'", e);
                }
                try {
                    ctx.rebind("altDDs", new URL[urls.size()]);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the altDDs parameter.'", e);
                }

                try {
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

    public static void resolve(final EasyBeansEjbJarClassMetadata sessionBean) {

        Iterator<EasyBeansEjbJarMethodMetadata> itMethods = sessionBean.getMethodMetadataCollection().iterator();
        while (itMethods.hasNext()) {
            EasyBeansEjbJarMethodMetadata method = itMethods.next();
            IJavaxJwsWebMethod webMethod = method.getJavaxJwsWebMethod();
            // Annotation present and not excluded
            if (webMethod != null && !webMethod.getExclude()) {
                method.setBusinessMethod(true);
            }
        }
    }
View Full Code Here

        List<String> allInterfaces = getAllInterfacesFromClass(sessionBean);

        // if SESSION_BEAN_INTERFACE is contained in the list, add some metadata
        if (allInterfaces.contains(SESSION_BEAN_INTERFACE)) {
            // first add dependency injection for setSessionContext method.
            JAnnotationResource jAnnotationResource = new JAnnotationResource();

            // add resource on setSessionContext method
            EasyBeansEjbJarMethodMetadata setCtxMethod = getMethod(sessionBean, SETSESSIONCONTEXT_METHOD, false,
                    SESSION_BEAN_INTERFACE);
            setCtxMethod.setJAnnotationResource(jAnnotationResource);
View Full Code Here

     * @see <a href="http://www.jcp.org/en/jsr/detail?id=220">EJB 3.0 Spec ?4.6.6</a>
     * @param sessionBean Session bean to analyze
     */
    public static void resolve(final EasyBeansEjbJarClassMetadata sessionBean) {

        IJLocal jLocal = sessionBean.getLocalInterfaces();
        IJRemote jRemote = sessionBean.getRemoteInterfaces();

        // No business interface or empty annotation (@Remote or @Local)
        if ((jLocal == null && jRemote == null) || (jLocal == null && jRemote != null && jRemote.getInterfaces().isEmpty())
                || (jRemote == null && jLocal != null && jLocal.getInterfaces().isEmpty())) {

            // The following interfaces are excluded when determining whether
            // the bean class has
            // more than one interface: java.io.Serializable;
            // java.io.Externalizable;
View Full Code Here

        // As the Bean class may not implement the interface, ads also the local and remote business interfaces
        List<String> businessInterfaces = new ArrayList<String>();
        // Add implemented interfaces
        businessInterfaces.addAll(Arrays.asList(visitingclassAnnotationMetadata.getInterfaces()));
        // Add local interfaces
        IJLocal localInterfaces = beanclassAnnotationMetadata.getLocalInterfaces();
        if (localInterfaces != null) {
            for (String itf : localInterfaces.getInterfaces()) {
                if (!businessInterfaces.contains(itf)) {
                    businessInterfaces.add(itf);
                }
            }
        }
View Full Code Here

     * @param sessionBean Session bean to analyze
     */
    public static void resolve(final EasyBeansEjbJarClassMetadata sessionBean) {

        IJLocal jLocal = sessionBean.getLocalInterfaces();
        IJRemote jRemote = sessionBean.getRemoteInterfaces();

        // No business interface or empty annotation (@Remote or @Local)
        if ((jLocal == null && jRemote == null) || (jLocal == null && jRemote != null && jRemote.getInterfaces().isEmpty())
                || (jRemote == null && jLocal != null && jLocal.getInterfaces().isEmpty())) {

            // The following interfaces are excluded when determining whether
            // the bean class has
            // more than one interface: java.io.Serializable;
            // java.io.Externalizable;
            // any of the interfaces defined by the javax.ejb package.
            String[] interfaces = sessionBean.getInterfaces();
            List<String> inheritedInterfaces = sessionBean.getInheritedInterfaces();

            int numberItfFound = 0;
            String itfFound = null;
            for (String itf : interfaces) {
                if (!itf.equals(java.io.Serializable.class.getName().replace(".", "/"))
                        && !itf.equals(java.io.Externalizable.class.getName().replace(".", "/"))
                        && !itf.startsWith("javax/ejb")
                        // Should not be inherited
                        && !inheritedInterfaces.contains(itf)
                        ) {
                    itfFound = itf;
                    numberItfFound++;
                }
            }

            // No business interface found but there is only one inherited interface, use it.
            if (numberItfFound == 0 && inheritedInterfaces != null && inheritedInterfaces.size() == 1) {
                itfFound = inheritedInterfaces.get(0);
                numberItfFound = 1;
            }


            // No business interface found
            if (numberItfFound == 0) {
                // if this is a 2.1 bean, it could be normal
                if (sessionBean.getRemoteHome() != null || sessionBean.getLocalHome() != null) {
                    return;
                }

                logger.warn("No business interface found on bean class {0}.", sessionBean.getClassName());
            } else {

                if (numberItfFound > 1) {
                    throw new IllegalStateException("More than 1 itf on class '" + sessionBean.getClassName() + "'.");
                }

                // If bean class implements a single interface, that interface is
                // assumed to be the business
                // interface of the bean. This business interface will be a local
                // interface unless the
                // interface is designated as a remote business interface by use of
                // the Remote annotation
                // on the bean class or interface or by means of the deployment
                // descriptor.

                // Build a local interface if no @Remote annotation, else add interface in the existing object
                if (jRemote == null) {
                    JLocal addedJLocal = new JLocal();
                    addedJLocal.addInterface(itfFound);
                    sessionBean.setLocalInterfaces(addedJLocal);
                } else {
                    jRemote.addInterface(itfFound);
                    sessionBean.setRemoteInterfaces(jRemote);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.ow2.chameleon.testing.helpers.OSGiHelper

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.