Package org.apache.geronimo.deployment

Examples of org.apache.geronimo.deployment.DeploymentException


        // extract the ejbJar file into a standalone packed jar file and add the contents to the output
        JarFile moduleFile = module.getModuleFile();
        try {
            earContext.addIncludeAsPackedJar(URI.create(module.getTargetPath()), moduleFile);
        } catch (IOException e) {
            throw new DeploymentException("Unable to copy app client module jar into configuration: " + moduleFile.getName());
        }
        ((AppClientModule) module).setEarFile(earFile);
    }
View Full Code Here


        String mainClasss = null;
        String classPath = null;
        try {
            Manifest manifest = moduleFile.getManifest();
            if (manifest == null) {
                throw new DeploymentException("App client module jar does not contain a manifest: " + moduleFile.getName());
            }
            mainClasss = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
            if (mainClasss == null) {
                throw new DeploymentException("App client module jar does not have Main-Class defined in the manifest: " + moduleFile.getName());
            }
            classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
            if (module.isStandAlone() && classPath != null) {
                throw new DeploymentException("Manifest class path entry is not allowed in a standalone jar (J2EE 1.4 Section 8.2)");
            }
        } catch (IOException e) {
            throw new DeploymentException("Could not get manifest from app client module: " + moduleFile.getName());
        }

        // generate the object name for the app client
        ObjectName appClientModuleName = null;
        try {
            appClientModuleName = NameFactory.getModuleName(null, null, null, appClientModule.getName(), NameFactory.APP_CLIENT_MODULE, earJ2eeContext);
        } catch (MalformedObjectNameException e) {
            throw new DeploymentException("Could not construct module name", e);
        }

        // create a gbean for the app client module and add it to the ear
        ReadOnlyContext componentContext;
        GBeanMBean appClientModuleGBean = new GBeanMBean(J2EEAppClientModuleImpl.GBEAN_INFO, earClassLoader);
        try {
            appClientModuleGBean.setReferencePatterns("J2EEServer", Collections.singleton(earContext.getServerObjectName()));
            if (!earContext.getJ2EEApplicationName().equals("null")) {
                appClientModuleGBean.setReferencePatterns("J2EEApplication", Collections.singleton(earContext.getApplicationObjectName()));
            }
            appClientModuleGBean.setAttribute("deploymentDescriptor", null);

            componentContext = buildComponentContext(earContext, appClientModule, appClient, geronimoAppClient, earClassLoader);
            appClientModuleGBean.setAttribute("componentContext", componentContext);
        } catch (Exception e) {
            throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
        }
        earContext.addGBean(appClientModuleName, appClientModuleGBean);

        // create another child configuration within the config store for the client application
        EARContext appClientDeploymentContext = null;
        File appClientConfiguration = null;
        try {
            try {
                appClientConfiguration = store.createNewConfigurationDir();

                // construct the app client deployment context... this is the same class used by the ear context
                try {

                    URI clientConfigId = URI.create(geronimoAppClient.getClientConfigId());
                    URI clientParentId;
                    if (geronimoAppClient.isSetClientParentId()) {
                        clientParentId = URI.create(geronimoAppClient.getClientParentId());
                    } else {
                        clientParentId = defaultClientParentId;
                    }
                    appClientDeploymentContext = new EARContext(appClientConfiguration,
                            clientConfigId,
                            ConfigurationModuleType.APP_CLIENT,
                            clientParentId,
                            kernel,
                            clientDomainName,
                            clientServerName,
                            clientApplicationName,
                            transactionContextManagerObjectName,
                            connectionTrackerObjectName,
                            null,
                            null,
                            RefContext.derivedClientRefContext(earContext.getRefContext(), ejbReferenceBuilder, resourceReferenceBuilder));
                } catch (Exception e) {
                    throw new DeploymentException("Could not create a deployment context for the app client", e);
                }

                // extract the client Jar file into a standalone packed jar file and add the contents to the output
                URI moduleBase = new URI(appClientModule.getTargetPath());
                try {
                    appClientDeploymentContext.addIncludeAsPackedJar(moduleBase, moduleFile);
                } catch (IOException e) {
                    throw new DeploymentException("Unable to copy app client module jar into configuration: " + moduleFile.getName());
                }

                // add the includes
                GerDependencyType[] includes = geronimoAppClient.getIncludeArray();
                for (int i = 0; i < includes.length; i++) {
                    GerDependencyType include = includes[i];
                    URI uri = getDependencyURI(include);
                    String name = uri.toString();
                    int idx = name.lastIndexOf('/');
                    if (idx != -1) {
                        name = name.substring(idx + 1);
                    }
                    URI path;
                    try {
                        path = new URI(name);
                    } catch (URISyntaxException e) {
                        throw new DeploymentException("Unable to generate path for include: " + uri, e);
                    }
                    try {
                        URL url = repository.getURL(uri);
                        appClientDeploymentContext.addInclude(path, url);
                    } catch (IOException e) {
                        throw new DeploymentException("Unable to add include: " + uri, e);
                    }
                }

                // add the dependencies
                GerDependencyType[] dependencies = geronimoAppClient.getDependencyArray();
                for (int i = 0; i < dependencies.length; i++) {
                    appClientDeploymentContext.addDependency(getDependencyURI(dependencies[i]));
                }

                // add manifest class path entries to the app client context
                addManifestClassPath(appClientDeploymentContext, appClientModule.getEarFile(), moduleFile, moduleBase);

                // get the classloader
                ClassLoader appClientClassLoader = appClientDeploymentContext.getClassLoader(repository);

                // pop in all the gbeans declared in the geronimo app client file
                if (geronimoAppClient != null) {
                    GerGbeanType[] gbeans = geronimoAppClient.getGbeanArray();
                    for (int i = 0; i < gbeans.length; i++) {
                        GBeanHelper.addGbean(new AppClientGBeanAdapter(gbeans[i]), appClientClassLoader, appClientDeploymentContext);
                    }
                    //deploy the resource adapters specified in the geronimo-application.xml
                    Collection resourceModules = new ArrayList();
                    try {
                        GerResourceType[] resources = geronimoAppClient.getResourceArray();
                        for (int i = 0; i < resources.length; i++) {
                            GerResourceType resource = resources[i];
                            String path;
                            JarFile connectorFile;
                            if (resource.isSetExternalRar()) {
                                path = resource.getExternalRar();
                                URI pathURI = new URI(path);
                                if (!repository.hasURI(pathURI)) {
                                    throw new DeploymentException("Missing rar in repository: " + path);
                                }
                                URL pathURL = repository.getURL(pathURI);
                                connectorFile = new JarFile(pathURL.getFile());
                            } else {
                                path = resource.getInternalRar();
                                connectorFile = new NestedJarFile(appClientModule.getEarFile(), path);
                            }
                            XmlObject connectorPlan = resource.getConnector();
                            Module connectorModule = connectorModuleBuilder.createModule(connectorPlan, connectorFile, path, null, null);
                            resourceModules.add(connectorModule);
                            connectorModuleBuilder.installModule(connectorFile, appClientDeploymentContext, connectorModule);
                        }
                        ClassLoader cl = appClientDeploymentContext.getClassLoader(repository);
                        for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) {
                            Module connectorModule = (Module) iterator.next();
                            connectorModuleBuilder.initContext(appClientDeploymentContext, connectorModule, cl);
                        }

                        for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) {
                            Module connectorModule = (Module) iterator.next();
                            connectorModuleBuilder.addGBeans(appClientDeploymentContext, connectorModule, cl);
                        }
                    } finally {
                        for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) {
                            Module connectorModule = (Module) iterator.next();
                            connectorModule.close();
                        }
                    }
                }

                // add the app client static jndi provider
                ObjectName jndiContextName = ObjectName.getInstance("geronimo.client:type=StaticJndiContext");
                GBeanMBean jndiContextGBean = new GBeanMBean("org.apache.geronimo.client.StaticJndiContextPlugin", appClientClassLoader);
                try {

                    componentContext = buildComponentContext(appClientDeploymentContext, appClientModule, appClient, geronimoAppClient, earClassLoader);
                    jndiContextGBean.setAttribute("context", componentContext);
                } catch (Exception e) {
                    throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
                }
                appClientDeploymentContext.addGBean(jndiContextName, jndiContextGBean);

                // finally add the app client container
                ObjectName appClienContainerName = ObjectName.getInstance("geronimo.client:type=ClientContainer");
                GBeanMBean appClienContainerGBean = new GBeanMBean("org.apache.geronimo.client.AppClientContainer", appClientClassLoader);
                try {
                    appClienContainerGBean.setAttribute("mainClassName", mainClasss);
                    appClienContainerGBean.setAttribute("appClientModuleName", appClientModuleName);
                    appClienContainerGBean.setReferencePattern("JNDIContext", new ObjectName("geronimo.client:type=StaticJndiContext"));
                    appClienContainerGBean.setReferencePattern("TransactionContextManager", new ObjectName("geronimo.client:type=TransactionContextManager"));
                } catch (Exception e) {
                    throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
                }
                appClientDeploymentContext.addGBean(appClienContainerName, appClienContainerGBean);
            } finally {
                if (appClientDeploymentContext != null) {
                    try {
                        appClientDeploymentContext.close();
                    } catch (IOException e) {
                    }
                }
            }

            try {
                return store.install(appClientConfiguration).toString();
            } catch (Exception e) {
                throw new DeploymentException(e);
            }
        } catch (Throwable e) {
            DeploymentUtil.recursiveDelete(appClientConfiguration);
            if (e instanceof Error) {
                throw (Error) e;
            } else if (e instanceof DeploymentException) {
                throw (DeploymentException) e;
            } else if (e instanceof Exception) {
                throw new DeploymentException(e);
            }
            throw new Error(e);
        }
    }
View Full Code Here

    public void addManifestClassPath(DeploymentContext deploymentContext, JarFile earFile, JarFile jarFile, URI jarFileLocation) throws DeploymentException {
        Manifest manifest = null;
        try {
            manifest = jarFile.getManifest();
        } catch (IOException e) {
            throw new DeploymentException("Could not read manifest: " + jarFileLocation);
        }

        if (manifest == null) {
            return;
        }
        String manifestClassPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
        if (manifestClassPath == null) {
            return;
        }

        for (StringTokenizer tokenizer = new StringTokenizer(manifestClassPath, " "); tokenizer.hasMoreTokens();) {
            String path = tokenizer.nextToken();

            URI pathUri;
            try {
                pathUri = new URI(path);
            } catch (URISyntaxException e) {
                throw new DeploymentException("Invalid manifest classpath entry: jarFile=" + jarFileLocation + ", path=" + path);
            }

            if (!pathUri.getPath().endsWith(".jar")) {
                throw new DeploymentException("Manifest class path entries must end with the .jar extension (J2EE 1.4 Section 8.2): jarFile=" + jarFileLocation + ", path=" + path);
            }
            if (pathUri.isAbsolute()) {
                throw new DeploymentException("Manifest class path entries must be relative (J2EE 1.4 Section 8.2): jarFile=" + jarFileLocation + ", path=" + path);
            }

            // determine the target file
            URI classPathJarLocation = jarFileLocation.resolve(pathUri);
            File classPathFile = deploymentContext.getTargetFile(classPathJarLocation);

            // we only recuse if the path entry is not already in the output context
            // this will work for all current cases, but may not work in the future
            if (!classPathFile.exists()) {
                // check if the path exists in the earFile
                ZipEntry entry = earFile.getEntry(classPathJarLocation.getPath());
                if (entry == null) {
                    throw new DeploymentException("Cound not find manifest class path entry: jarFile=" + jarFileLocation + ", path=" + path);
                }

                try {
                    // copy the file into the output context
                    deploymentContext.addFile(classPathJarLocation, earFile, entry);
                } catch (IOException e) {
                    throw new DeploymentException("Cound not copy manifest class path entry into configuration: jarFile=" + jarFileLocation + ", path=" + path, e);
                }

                JarFile classPathJarFile = null;
                try {
                    classPathJarFile = new JarFile(classPathFile);
                } catch (IOException e) {
                    throw new DeploymentException("Manifest class path entries must be a valid jar file (J2EE 1.4 Section 8.2): jarFile=" + jarFileLocation + ", path=" + path, e);
                }


                // add the client jars of this class path jar
                addManifestClassPath(deploymentContext, earFile, classPathJarFile, classPathJarLocation);
View Full Code Here

        URI uri;
        if (dep.isSetUri()) {
            try {
                uri = new URI(dep.getUri());
            } catch (URISyntaxException e) {
                throw new DeploymentException("Invalid dependency URI " + dep.getUri(), e);
            }
        } else {
            // @todo support more than just jars
            String id = dep.getGroupId() + "/jars/" + dep.getArtifactId() + '-' + dep.getVersion() + ".jar";
            try {
                uri = new URI(id);
            } catch (URISyntaxException e) {
                throw new DeploymentException("Unable to construct URI for groupId=" + dep.getGroupId() + ", artifactId=" + dep.getArtifactId() + ", version=" + dep.getVersion(), e);
            }
        }
        return uri;
    }
View Full Code Here

            ConfigurationDocument configurationDoc = ConfigurationDocument.Factory.parse(planFile);
            return configurationDoc.getConfiguration();
        } catch (XmlException e) {
            return null;
        } catch (Exception e) {
            throw new DeploymentException(e);
        }
    }
View Full Code Here

        ConfigurationType configType = (ConfigurationType) plan;
        URI configID;
        try {
            configID = new URI(configType.getConfigId());
        } catch (URISyntaxException e) {
            throw new DeploymentException("Invalid configId " + configType.getConfigId(), e);
        }
        URI parentID;
        if (configType.isSetParentId()) {
            if (configType.getParentId().equals("")) {
                parentID = null;
            } else {
                try {
                    parentID = new URI(configType.getParentId());
                } catch (URISyntaxException e) {
                    throw new DeploymentException("Invalid parentId " + configType.getParentId(), e);
                }
            }
        } else {
            parentID = defaultParentId;
        }

        DeploymentContext context = null;
        try {
            context = new DeploymentContext(outfile, configID, ConfigurationModuleType.SERVICE, parentID, kernel);
        } catch (MalformedObjectNameException e) {
            throw new DeploymentException(e);
        }
        addIncludes(context, configType);
        addDependencies(context, configType.getDependencyArray());
        ClassLoader cl = context.getClassLoader(repository);
        GbeanType[] gbeans = configType.getGbeanArray();
View Full Code Here

            }
            URI path;
            try {
                path = new URI(name);
            } catch (URISyntaxException e) {
                throw new DeploymentException("Unable to generate path for include: " + uri, e);
            }
            try {
                URL url = repository.getURL(uri);
                context.addInclude(path, url);
            } catch (IOException e) {
                throw new DeploymentException("Unable to add include: " + uri, e);
            }
        }
    }
View Full Code Here

            URL url;
            try {
                url = repository.getURL(dependencyURI);
            } catch (MalformedURLException e) {
                throw new DeploymentException("Unable to get URL for dependency " + dependencyURI, e);
            }
            ClassLoader depCL = new URLClassLoader(new URL[]{url}, ClassLoader.getSystemClassLoader());
            InputStream is = depCL.getResourceAsStream("META-INF/geronimo-service.xml");
            if (is != null) {
                // it has a geronimo-service.xml file
                ServiceDocument serviceDoc = null;
                try {
                    serviceDoc = ServiceDocument.Factory.parse(is);
                } catch (org.apache.xmlbeans.XmlException e) {
                    throw new DeploymentException("Invalid geronimo-service.xml file in " + url, e);
                } catch (IOException e) {
                    throw new DeploymentException("Unable to parse geronimo-service.xml file in " + url, e);
                }
                DependencyType[] dependencyDeps = serviceDoc.getService().getDependencyArray();
                if (dependencyDeps != null) {
                    addDependencies(context, dependencyDeps);
                }
View Full Code Here

        URI uri;
        if (dep.isSetUri()) {
            try {
                uri = new URI(dep.getUri());
            } catch (URISyntaxException e) {
                throw new DeploymentException("Invalid dependency URI " + dep.getUri(), e);
            }
        } else {
            // @todo support more than just jars
            String id = dep.getGroupId() + "/jars/" + dep.getArtifactId() + '-' + dep.getVersion() + ".jar";
            try {
                uri = new URI(id);
            } catch (URISyntaxException e) {
                throw new DeploymentException("Unable to construct URI for groupId=" + dep.getGroupId() + ", artifactId=" + dep.getArtifactId() + ", version=" + dep.getVersion(), e);
            }
        }
        return uri;
    }
View Full Code Here

    public GBeanBuilder(String name, ClassLoader classLoader, String className) throws DeploymentException {
        ObjectName objectName;
        try {
            objectName = new ObjectName(name);
        } catch (MalformedObjectNameException e) {
            throw new DeploymentException("Invalid ObjectName: " + name, e);
        }

        this.classLoader = classLoader;

        try {
            gbean = new GBeanData(objectName, GBeanInfo.getGBeanInfo(className, classLoader));
        } catch (Exception e) {
            throw new DeploymentException("Unable to create GBean from class " + className, e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.deployment.DeploymentException

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.