Package org.ow2.util.ee.deploy.api.deployer

Examples of org.ow2.util.ee.deploy.api.deployer.DeployerException


        // Get URL of this EAR
        URL earURL = null;
        try {
            earURL = earDeployable.getArchive().getURL();
        } catch (ArchiveException e) {
            throw new DeployerException("Cannot get the URL for the deployable '" + earDeployable + "'.", e);
        }

        // Create a Root classloader for this EAR
        // Empty classloader
        URLClassLoader earClassLoader = (URLClassLoader) newInstance(this.jClassLoaderConstructor, earURL.toExternalForm(), new URL[0],
                Thread.currentThread().getContextClassLoader());

        // Get the URLs of EJB, WEB and Clients
        List<URL> urlsEJB = new ArrayList<URL>();
        for (EJBDeployable ejb : earDeployable.getEJBDeployables()) {
            try {
                urlsEJB.add(ejb.getArchive().getURL());
            } catch (ArchiveException e) {
                throw new DeployerException("Cannot get the URL for the archive '" + ejb.getArchive() + "'", e);
            }
        }
        List<URL> urlsWAR = new ArrayList<URL>();
        for (WARDeployable war : earDeployable.getWARDeployables()) {
            try {
                urlsWAR.add(war.getArchive().getURL());
            } catch (ArchiveException e) {
                throw new DeployerException("Cannot get the URL for the archive '" + war.getArchive() + "'", e);
            }
        }
        List<URL> urlsClient = new ArrayList<URL>();
        for (CARDeployable car : earDeployable.getCARDeployables()) {
            try {
                urlsClient.add(car.getArchive().getURL());
            } catch (ArchiveException e) {
                throw new DeployerException("Cannot get the URL for the archive '" + car.getArchive() + "'", e);
            }
        }

        // Set alt-dd
        invoke(this.ejbSetAltDD, null, earClassLoader, urlsEJB.toArray(new URL[urlsEJB.size()]), new URL[urlsEJB.size()]);
        invoke(this.webSetAltDD, null, earClassLoader, urlsWAR.toArray(new URL[urlsWAR.size()]), new URL[urlsWAR.size()]);
        invoke(this.clientSetAltDD, null, earClassLoader, urlsClient.toArray(new URL[urlsClient.size()]), new URL[urlsClient.size()]);

        // Deploy the RAR files of the EAR (if any)
        deployRARs(earDeployable, earURL, earClassLoader);

        // deploy EJB3s
        // Get EJBs of this EAR
        List<EJB3Deployable> ejb3s = earDeployable.getEJB3Deployables();
        List<EJBDeployable<?>> ejbs = earDeployable.getEJBDeployables();

        // Get libraries of this EAR
        List<LibDeployable> libs = earDeployable.getLibDeployables();

        // Create array of URLs with EJBs + Libraries
        List<URL> urls = new ArrayList<URL>();
        for (EJBDeployable<?> ejb : ejbs) {
            try {
                urls.add(ejb.getArchive().getURL());
            } catch (ArchiveException e) {
                throw new DeployerException("Cannot get the URL for the Archive '" + ejb.getArchive() + "'.", e);
            }
        }
        for (LibDeployable lib : libs) {
            try {
                urls.add(lib.getArchive().getURL());
            } catch (ArchiveException e) {
                throw new DeployerException("Cannot get the URL for the Archive '" + lib.getArchive() + "'.", e);

            }
        }

        // 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
        List<IArchive> libArchives = getLibArchives(earDeployable);


        // Reset context ID of EJBs
        addEjbContextIdToList(earDeployable, new ArrayList<String>(), true);

        // Create containers for each EJB3 deployable
        List<EZBContainer> containers = new ArrayList<EZBContainer>();
        for (EJBDeployable ejb : ejb3s) {
            containers.add(getEmbedded().createContainer(ejb));
        }

        // Create Resolver for EAR
        EZBApplicationJNDIResolver applicationJNDIResolver = new ApplicationJNDIResolver();

        // Create EasyBeans injection Holder
        InjectionHolder ejbInjectionHolder = new InjectionHolder();
        ejbInjectionHolder.setPersistenceUnitManager(persistenceUnitManager);
        ejbInjectionHolder.setJNDIResolver(applicationJNDIResolver);


        // Configure containers
        for (EZBContainer container : containers) {
            // Set the classloader that needs to be used
            container.setClassLoader(ejbClassLoader);

            // Set application name
            container.setApplicationName(earDeployable.getModuleName());

            // Add persistence context found
            container.setPersistenceUnitManager(persistenceUnitManager);

            // Add the metadata
            container.setExtraArchives(libArchives);

            // set parent JNDI Resolver
            EZBContainerJNDIResolver containerJNDIResolver = container.getConfiguration().getContainerJNDIResolver();
            containerJNDIResolver.setApplicationJNDIResolver(applicationJNDIResolver);

            // Add child on application JNDI Resolver
            applicationJNDIResolver.addContainerJNDIResolver(containerJNDIResolver);


            // Resolve container
            try {
                container.resolve();
            } catch (EZBContainerException e) {
                throw new DeployerException("Cannot resolve the container '" + container.getArchive() + "'.", e);
            }
        }

        // Start containers
        for (EZBContainer container : containers) {
            try {
                container.start();
            } catch (Exception e) {
                logger.error("Cannot start container {0}", container.getName(), e);
                // stop it
                try {
                    container.stop();
                    getEmbedded().removeContainer(container);
                } catch (Exception se) {
                    logger.error("Cannot stop failing container {0}", container.getName(), se);
                }
                // rethrow it
                throw new DeployerException("Container '" + container.getName() + "' has failed", e);
            }
        }

        // Deploy EJB 2.1
        deployEJB21s(earDeployable, earURL, earClassLoader, ejbClassLoader);
View Full Code Here


                // 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 {
                    this.deployMethodwarService.invoke(this.warService, ctx);
                } catch (IllegalArgumentException e) {
                    throw new DeployerException("Cannot deploy the WARs.'", e);
                } catch (IllegalAccessException e) {
                    throw new DeployerException("Cannot deploy the WARs.'", e);
                } catch (InvocationTargetException e) {
                    throw new DeployerException("Cannot deploy the WARs.'", e.getTargetException());
                }
            }
        }

    }
View Full Code Here

            } 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 {
                    this.deployMethodRarService.invoke(this.rarService, ctx);
                } catch (IllegalArgumentException e) {
                    throw new DeployerException("Cannot deploy the RARs.'", e);
                } catch (IllegalAccessException e) {
                    throw new DeployerException("Cannot deploy the RARs.'", e);
                } catch (InvocationTargetException e) {
                    throw new DeployerException("Cannot deploy the RARs.'", e.getTargetException());
                }
            }
        }

    }
View Full Code Here

                List<URL> urls = new ArrayList<URL>();
                for (EJB21Deployable ejb21Deployable : ejbs) {
                    try {
                        urls.add(ejb21Deployable.getArchive().getURL());
                    } catch (ArchiveException e) {
                        throw new DeployerException("Cannot get the URL for the archive '" + ejb21Deployable.getArchive()
                                + "'", e);
                    }
                }


                // Get classpath of the EJBs
                URL[] compilationURLs = null;

                // content of the ear loader (application wide resources)
                URL[] myApplicationJars = earClassLoader.getURLs();

                // content of the apps loader (system wide resources)
                URL[] appsJars = ((URLClassLoader) earClassLoader.getParent()).getURLs();

                // merge the 3 Set of URLs
                compilationURLs = new URL[myApplicationJars.length + appsJars.length + urls.size()];
                System.arraycopy(urls.toArray(new URL[urls.size()]), 0, compilationURLs, 0, urls.size());
                System.arraycopy(appsJars, 0, compilationURLs, urls.size(), appsJars.length);
                System.arraycopy(myApplicationJars, 0, compilationURLs, urls.size() + appsJars.length, myApplicationJars.length);

                // Call automatic GenIC on the URLs of the EJB 2.1
                if (this.checkGenICMethod != null) {
                    for (EJB21Deployable ejb : ejbs) {
                        URL ejbURL = null;
                        try {
                            ejbURL = ejb.getArchive().getURL();
                        } catch (ArchiveException e) {
                            throw new DeployerException("Cannot get the URL on the deployable '" + ejb + "'", e);
                        }
                        logger.debug("Calling GenIC on the EJB ''{0}'' with compilation URL ''{1}''.", ejbURL, Arrays
                                .asList(compilationURLs));
                        invoke(this.checkGenICMethod, this.ejb21Service, ejbURL.getFile(), compilationURLs);
                    }
                }


                // Deploy EJB 2.1 on JOnAS service
                Context ctx = new ContextImpl(earURL.toExternalForm());
                try {
                    ctx.rebind("earUrl", earURL);
                    ctx.rebind("earRootUrl", earURL);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the EAR URL parameter '" + earURL + "'", e);
                }

                try {
                    ctx.rebind("jarURLs", 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);
                }

                // Bind the EJB classloader
                try {
                    ctx.rebind("ejbClassLoader", ejbClassLoader);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the ejbClassLoader parameter '" + ejbClassLoader + "'", e);
                }

                // Role names
                try {
                    ctx.rebind("roleNames", new String[0]);
                } catch (NamingException e) {
                    throw new DeployerException("Cannot add the altDDs parameter.'", e);
                }

                try {
                    this.deployMethodejb21Service.invoke(this.ejb21Service, ctx);
                } catch (IllegalArgumentException e) {
                    throw new DeployerException("Cannot deploy the EJB 2.1'", e);
                } catch (IllegalAccessException e) {
                    throw new DeployerException("Cannot deploy the EJB 2.1'", e);
                } catch (InvocationTargetException e) {
                    throw new DeployerException("Cannot deploy the EJB 2.1'", e.getTargetException());
                }
            }
        }

    }
View Full Code Here

     * @param deployable the deployable that needs to be deployed
     * @throws DeployerException if this deployable is not supported.
     */
    private void checkSupportedDeployable(final IDeployable deployable) throws DeployerException {
        if (!(deployable instanceof EARDeployable || deployable instanceof EJBDeployable)) {
            throw new DeployerException("The deployable '" + deployable + "' is not supported by this deployer");
        }
    }
View Full Code Here

                        toBeLinkedPC.linkConfiguration(linkedPC);
                    }
                }
            }
        } catch (PolicyContextException pce) {
            throw new DeployerException("Cannot retrieve a policy configuration", pce);
        }

    }
View Full Code Here

        if (ejbDeployables != null) {
            for (EJBDeployable ejbDeployable : ejbDeployables) {
                try {
                    urls.add(ejbDeployable.getArchive().getURL());
                } catch (ArchiveException e) {
                    throw new DeployerException("Cannot get URL on the deployable '" + ejbDeployable + "'.", e);
                }
            }
        }

        URL[] jarUrls = urls.toArray(new URL[urls.size()]);

        // Get contextID of EJB
        for (int u = 0; u < jarUrls.length; u++) {
            String ctxId = jarUrls[u].getPath();
            // reset the policy configuration associated to this context ID.
            if (resetPolicyConfiguration) {
                try {
                    getPolicyConfigurationFactory().getPolicyConfiguration(ctxId, true);
                } catch (PolicyContextException pce) {
                    throw new DeployerException("Cannot retrieve a policy configuration", pce);
                }
            }
            contextIDs.add(ctxId);
        }
    }
View Full Code Here

            for (WARDeployable warDeployable : warDeployables) {
                URL warURL = null;
                try {
                    warURL = warDeployable.getArchive().getURL();
                } catch (ArchiveException e) {
                    throw new DeployerException("Cannot get URL on the deployable '" + warDeployable + "'.", e);
                }

                // build context ID of war
                String ctxId = warURL.getFile() + warDeployable.getContextRoot();
                // reset the policy configuration associated to this context ID.
                if (resetPolicyConfiguration) {
                    try {
                        getPolicyConfigurationFactory().getPolicyConfiguration(ctxId, true);
                    } catch (PolicyContextException pce) {
                        throw new DeployerException("Cannot retrieve a policy configuration", pce);
                    }
                }
                contextIDs.add(ctxId);
            }
        }
View Full Code Here

    private PolicyConfigurationFactory getPolicyConfigurationFactory() throws DeployerException {
        PolicyConfigurationFactory pcFactory = null;
        try {
            pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
        } catch (Exception cnfe) {
            throw new DeployerException("Cannot retrieve current policy configuration factory", cnfe);
        }
        return pcFactory;
    }
View Full Code Here

                ctxId = (String) itCtxId.next();
                PolicyConfiguration pc = getPolicyConfigurationFactory().getPolicyConfiguration(ctxId, false);
                pc.commit();
            }
        } catch (PolicyContextException pce) {
            throw new DeployerException("Cannot commit policy configuration with Id '" + ctxId + "'", pce);
        }

        // refresh policy
        Policy.getPolicy().refresh();
    }
View Full Code Here

TOP

Related Classes of org.ow2.util.ee.deploy.api.deployer.DeployerException

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.