Package org.apache.geronimo.j2ee.deployment

Examples of org.apache.geronimo.j2ee.deployment.AppClientModule


    }

    public void initContext(EARContext earContext, Module clientModule, ClassLoader cl) throws DeploymentException {
        namingBuilders.buildEnvironment(clientModule.getSpecDD(), clientModule.getVendorDD(), ((AppClientModule)clientModule).getEnvironment());

        AppClientModule appClientModule = ((AppClientModule) clientModule);
        for (ConnectorModule connectorModule : appClientModule.getResourceModules()) {
            getConnectorModuleBuilder().initContext(appClientModule.getEarContext(), connectorModule, cl);
        }
        for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
            mbe.initContext(earContext, clientModule, cl);
        }
    }
View Full Code Here


        }
    }

    public void addGBeans(EARContext earContext, Module module, ClassLoader earClassLoader, Collection repositories) throws DeploymentException {

        AppClientModule appClientModule = (AppClientModule) module;
        JarFile moduleFile = module.getModuleFile();

        ApplicationClientType appClient = (ApplicationClientType) appClientModule.getSpecDD();
        GerApplicationClientType geronimoAppClient = (GerApplicationClientType) appClientModule.getVendorDD();

        // generate the object name for the app client
        AbstractName appClientModuleName = appClientModule.getModuleName();

        // create a gbean for the app client module and add it to the ear
        GBeanData appClientModuleGBeanData = new GBeanData(appClientModuleName, J2EEAppClientModuleImpl.GBEAN_INFO);
        try {
            appClientModuleGBeanData.setReferencePattern("J2EEServer", earContext.getServerName());
            if (!module.isStandAlone()) {
                appClientModuleGBeanData.setReferencePattern("J2EEApplication", earContext.getModuleName());
            }

        } catch (Exception e) {
            throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
        }
        try {
            earContext.addGBean(appClientModuleGBeanData);
        } catch (GBeanAlreadyExistsException e) {
            throw new DeploymentException("Could not add application client module gbean to configuration", e);
        }

        EARContext appClientDeploymentContext = appClientModule.getEarContext();
        //Share the ejb info with the ear.
        //TODO this might be too much, but I don't want to impose a dependency on geronimo-openejb to get
        //EjbModuleBuilder.EarData.class
        Map<Object, Object> generalData = earContext.getGeneralData();
        for (Map.Entry<Object, Object> entry : generalData.entrySet()) {
            Object key = entry.getKey();
            if (key instanceof Class && ((Class)key).getName().equals("org.apache.geronimo.openejb.deployment.EjbModuleBuilder$EarData")) {
                appClientDeploymentContext.getGeneralData().put(key, entry.getValue());
                break;
            }
        }

        // Create a Module ID Builder defaulting to similar settings to use for any children we create
        ModuleIDBuilder idBuilder = new ModuleIDBuilder();
        idBuilder.setDefaultGroup(appClientModule.getEnvironment().getConfigId().getGroupId());
        idBuilder.setDefaultVersion(appClientModule.getEnvironment().getConfigId().getVersion());
        try {
            try {

                //register the message destinations in the app client ear context.
                namingBuilders.initContext(appClient, geronimoAppClient, appClientModule);
                // 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 manifest class path entries to the app client context
                addManifestClassPath(appClientDeploymentContext, appClientModule.getEarFile(), moduleFile, moduleBase);

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

                // pop in all the gbeans declared in the geronimo app client file
                if (geronimoAppClient != null) {
                    serviceBuilder.build(geronimoAppClient, appClientDeploymentContext, appClientDeploymentContext);
                    //deploy the resource adapters specified in the geronimo-application.xml

                    for (ConnectorModule connectorModule : appClientModule.getResourceModules()) {
                        getConnectorModuleBuilder().addGBeans(appClientDeploymentContext, connectorModule, appClientClassLoader, repositories);
                    }
                }

                //Holder may be loaded in the "client" module classloader here, whereas
                //NamingBuilder.INJECTION_KEY.get(buildingContext) returns a Holder loaded in the j2ee-server classloader.
                Object holder;
                // add the app client static jndi provider
                //TODO track resource ref shared and app managed security
                AbstractName jndiContextName = earContext.getNaming().createChildName(appClientDeploymentContext.getModuleName(), "StaticJndiContext", "StaticJndiContext");
                GBeanData jndiContextGBeanData = new GBeanData(jndiContextName, StaticJndiContextPlugin.GBEAN_INFO);
                try {
                    Map<NamingBuilder.Key, Object> buildingContext = new HashMap<NamingBuilder.Key, Object>();
                    buildingContext.put(NamingBuilder.GBEAN_NAME_KEY, jndiContextName);
                    Configuration localConfiguration = appClientDeploymentContext.getConfiguration();
                    Configuration remoteConfiguration = earContext.getConfiguration();

                    if (!appClient.getMetadataComplete()) {
                        // Create a classfinder and populate it for the naming builder(s). The absence of a
                        // classFinder in the module will convey whether metadata-complete is set
                        // (or not)
                        appClientModule.setClassFinder(createAppClientClassFinder(appClient, appClientModule));
                    }

                    namingBuilders.buildNaming(appClient, geronimoAppClient, appClientModule, buildingContext);

                    if (!appClient.getMetadataComplete()) {
                        appClient.setMetadataComplete(true);
                        module.setOriginalSpecDD(module.getSpecDD().toString());
                    }

                    appClientModuleGBeanData.setAttribute("deploymentDescriptor", appClientModule.getOriginalSpecDD());
                    holder = NamingBuilder.INJECTION_KEY.get(buildingContext);
                    jndiContextGBeanData.setAttribute("context", NamingBuilder.JNDI_KEY.get(buildingContext));
                } catch (DeploymentException e) {
                    throw e;
                } catch (Exception e) {
                    throw new DeploymentException("Unable to construct jndi context for AppClientModule GBean "+
                        appClientModule.getName(), e);
                }
                appClientDeploymentContext.addGBean(jndiContextGBeanData);

                // finally add the app client container
                AbstractName appClientContainerName = appClientDeploymentContext.getModuleName();
                GBeanData appClientContainerGBeanData = new GBeanData(appClientContainerName, AppClientContainer.GBEAN_INFO);
                try {
                    appClientContainerGBeanData.setAttribute("mainClassName", appClientModule.getMainClassName());
                    appClientContainerGBeanData.setAttribute("appClientModuleName", appClientModuleName);
                    String callbackHandlerClassName = null;
                    if (appClient.isSetCallbackHandler()) {
                        callbackHandlerClassName = appClient.getCallbackHandler().getStringValue().trim();
                    }
View Full Code Here

            }
        } else {
            parentId = defaultServerParentId;
        }

        return new AppClientModule(standAlone, configId, parentId, moduleFile, targetPath, appClient, gerAppClient, specDD);
    }
View Full Code Here

    }

    public void addGBeans(EARContext earContext, Module module, ClassLoader earClassLoader) throws DeploymentException {
        J2eeContext earJ2eeContext = earContext.getJ2eeContext();

        AppClientModule appClientModule = (AppClientModule) module;

        ApplicationClientType appClient = (ApplicationClientType) appClientModule.getSpecDD();
        GerApplicationClientType geronimoAppClient = (GerApplicationClientType) appClientModule.getVendorDD();

        // get the app client main class
        JarFile moduleFile = module.getModuleFile();
        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());
            }
            String 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 {
            //TODO consider constructing a module context
            appClientModuleName = NameFactory.getModuleName(null, null, null, NameFactory.APP_CLIENT_MODULE, appClientModule.getName(), 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
        Map componentContext;
        GBeanData appClientModuleGBeanData = new GBeanData(appClientModuleName, J2EEAppClientModuleImpl.GBEAN_INFO);
        try {
            appClientModuleGBeanData.setReferencePatterns("J2EEServer", Collections.singleton(earContext.getServerObjectName()));
            if (!earContext.getJ2EEApplicationName().equals("null")) {
                appClientModuleGBeanData.setReferencePatterns("J2EEApplication", Collections.singleton(earContext.getApplicationObjectName()));
            }
            appClientModuleGBeanData.setAttribute("deploymentDescriptor", appClientModule.getOriginalSpecDD());

        } catch (Exception e) {
            throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
        }
        earContext.addGBean(appClientModuleGBeanData);

        // create another child configuration within the config store for the client application
        EARContext appClientDeploymentContext = null;
        File appClientDir = null;
        ConfigurationData appClientConfigurationData = null;
        try {
            try {
                appClientDir = 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(appClientDir,
                            clientConfigId,
                            ConfigurationModuleType.APP_CLIENT,
                            clientParentId,
                            kernel,
                            clientApplicationName,
                            transactionContextManagerObjectName,
                            connectionTrackerObjectName,
                            null,
                            null,
                            corbaGBeanObjectName,
                            RefContext.derivedClientRefContext(earContext.getRefContext(), ejbReferenceBuilder, resourceReferenceBuilder, serviceReferenceBuilder));
                } 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
                DependencyType[] includes = geronimoAppClient.getIncludeArray();
                ServiceConfigBuilder.addIncludes(appClientDeploymentContext, includes, repository);

                // add the dependencies
                DependencyType[] dependencies = geronimoAppClient.getDependencyArray();
                ServiceConfigBuilder.addDependencies(appClientDeploymentContext, dependencies, repository);

                // 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) {
                    GbeanType[] gbeans = geronimoAppClient.getGbeanArray();
                    ServiceConfigBuilder.addGBeans(gbeans, appClientClassLoader, appClientDeploymentContext.getJ2eeContext(), 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 = null;
                                try {
                                    pathURI = new URI(path);
                                } catch (URISyntaxException e) {
                                    throw new DeploymentException("Bad path to external rar", e);
                                }
                                if (!repository.hasURI(pathURI)) {
                                    throw new DeploymentException("Missing rar in repository: " + path);
                                }
                                URL pathURL = null;
                                try {
                                    pathURL = repository.getURL(pathURI);
                                } catch (MalformedURLException e) {
                                    throw new DeploymentException("Could not locate external rar in repository", e);
                                }
                                try {
                                    connectorFile = new JarFile(pathURL.getFile());
                                } catch (IOException e) {
                                    throw new DeploymentException("Could not access rar contents", e);
                                }
                            } else {
                                path = resource.getInternalRar();
                                try {
                                    connectorFile = new NestedJarFile(appClientModule.getEarFile(), path);
                                } catch (IOException e) {
                                    throw new DeploymentException("Could not locate connector inside ear", e);
                                }
                            }
                            XmlObject connectorPlan = resource.getConnector();
View Full Code Here

TOP

Related Classes of org.apache.geronimo.j2ee.deployment.AppClientModule

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.