void AppServerEnumeration::CreateJBossInstance()

in source/code/providers/support/appserver/appserverenumeration.cpp [139:255]


    void AppServerEnumeration::CreateJBossInstance(vector<SCXCoreLib::SCXHandle<AppServerInstance> > *ASInstances, vector<string> params)
    {
        bool gotInstPath=false;
        wstring instDir;
        string config;
        string configFromDashC;
        string configFromJBossProperty;
        string configFromJBossDomainProperty;
        string configFromJBossStandaloneProperty;
        string ports;
        wstring deployment = L"";
        
        // We have a 'JBoss' instance, now get the base directory from the 'classpath' commandline argument
        string arg = ParseOutCommandLineArg(params, "-classpath",true,true);
        if ( arg.length() > 0 )
        {
           instDir = GetJBossPathFromClassPath(StrFromUTF8(arg));
           if(instDir.length() > 0)
           {
               gotInstPath=true;
           }
        }
        
        // If we still do not have a JBoss instance check if JBoss AS 7 / Wildfly 8 Server
        // This property exists for both Standalone versions and Domain versions of JBoss/Wildfly
        if(!gotInstPath)
        {
            string arg2 = ParseOutCommandLineArg(params,"-Djboss.home.dir",true,true);
            instDir = StrFromUTF8(arg2);
            if(instDir.length() > 0)
            {
                gotInstPath = true;
            }
        }
        configFromDashC = ParseOutCommandLineArg(params, "-c",false,true);
        configFromJBossProperty = ParseOutCommandLineArg(params, "-Djboss.server.name",true,false);
        
        // These properties are specific for JBoss 7 and Wildfly
        // The Logging property is optional when running in domain mode, thus the server data directory is used
        configFromJBossDomainProperty = ParseOutCommandLineArg(params, "-Djboss.server.data.dir", true, false);
        configFromJBossStandaloneProperty = ParseOutCommandLineArg(params, "-Dlogging.configuration",true,false);
        
        // Give priority to JBoss 7 and wildfly as they can have non default config.
        // If config from -c is checked first It would lead to incorrect install path for JBoss 7 and wildfly.
        if ( configFromJBossDomainProperty.length() != 0 )
        {
            // Sample domain value: /root/wildfly-8.1.0.CR2/domain/servers/server-one/data
            config = configFromJBossDomainProperty;
        }
        else if ( configFromJBossStandaloneProperty.length() != 0 )
        {
            // Sample standalone value: /root/wildfly-8.1.0.CR2/standalone/configuration/logging.properties

            /* Following is the preference for getting configuration directory:
               jboss.server.config.dir
               jboss.server.base.dir + /configuration
               jboss.home.dir + /standalone/configuration 
            */
            string confDir = ParseOutCommandLineArg(params, "-Djboss.server.config.dir",true,false);
            string baseDir = ParseOutCommandLineArg(params, "-Djboss.server.base.dir",true,false);
            string homeDir = ParseOutCommandLineArg(params, "-Djboss.home.dir",true,false);

            if(confDir.size() > 0)
            {
                confDir.append("/");
                config = confDir;
            }
            else if(baseDir.size() > 0)
            {
                baseDir.append("/configuration/");
                config = baseDir;
            }
            else
            {
                homeDir.append("/standalone/configuration/");
                config = homeDir;
            }
            // JBoss standalone can have non default config file (standalone-full.xml, standalone-ha.xml etc.)
            // If -c argument is also present then ports should be read from that file
            if ( configFromDashC.length() != 0 )
            {
                // -c gives relative path of config file wrt configuration directory. 
                config.append(configFromDashC);
            }
            ports = ParseOutCommandLineArg(params, "-Djboss.socket.binding.port-offset",true,false); 
            deployment = L"standalone";
        }
        else if ( configFromDashC.length() != 0 )
        {
            config = configFromDashC;
        }
        else if ( configFromJBossProperty.length() != 0 )
        {
            config = configFromJBossProperty;
        }
        else
        {
            config = "default";
        }
        
        if(ports.empty())
        {
            ports =  ParseOutCommandLineArg(params, "-Djboss.service.binding.set",true,false);
        }
        
        if(gotInstPath)
        {
            SCXCoreLib::SCXHandle<JBossAppServerInstancePALDependencies> deps = SCXCoreLib::SCXHandle<JBossAppServerInstancePALDependencies>(new JBossAppServerInstancePALDependencies());
            SCXCoreLib::SCXHandle<JBossAppServerInstance> inst ( 
                new JBossAppServerInstance(instDir,StrFromUTF8(config),StrFromUTF8(ports),deps,deployment) );
            inst->Update();

            SCX_LOGTRACE(m_log, L"Found a running app server process");
            inst->SetIsRunning(true);
            ASInstances->push_back(inst);
        }
    }