⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiaorionwebappsdeployerbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        File earFile = new File(filePath);        File tmpFile = new File(m_WebAppRootPath + earFile.getName());        if ( tmpFile != null && tmpFile.isFile() ){            tmpFile.delete();        }        if ( !earFile.renameTo(tmpFile) ) {            earFile.delete();            String errMsg = "Failed moving the ear file in the deployed context root"  ;            JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.deployEarFile", errMsg );            throw new JahiaException ( "JahiaOrionWebAppsDeployerBaseService.deployEarFile",                                    "JahiaOrionWebAppsDeployerBaseService" + errMsg ,                                    JahiaException.SERVICE_ERROR, JahiaException.ERROR);        }        filePath = tmpFile.getAbsolutePath();        // Create a Ear Handler        JahiaEarFileHandler earh = null;        try {            earh = new JahiaEarFileHandler(filePath);            // full path to the application context root folder            String appContextPath = createApplicationContext(appContext);            if ( appContextPath == null ){                String errMsg = "Failed creating the application context root dir"  ;                JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.deployEarFile", errMsg );                throw new JahiaException ( "JahiaOrionWebAppsDeployerBaseService.deployEarFile",                                       "JahiaOrionWebAppsDeployerBaseService" + errMsg ,                                       JahiaException.SERVICE_ERROR, JahiaException.ERROR);            }            // Get WebComponents ( list of war files )            Vector webComponents = earh.getWebComponents();            int size = webComponents.size();            if ( size<=0 ) {                return false;            }            // Deploy web components ( war files )            Web_Component webComp   = null;            String webURI           = null;     // name of the war file            String webAppContext    ="";            for ( int i=0 ; i<size ; i++ ){                webComp = (Web_Component)webComponents.get(i);                webURI = webComp.getWebURI();                if ( webURI != null && (webURI.length()>0) ){                    JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.deployEarFile","start extracting entry " + webURI);                    // extract the war file                    earh.extractEntry(webURI,m_TempFolderDiskPath);                    // get the extracted war file                    File warFile = new File(m_TempFolderDiskPath + File.separator + webURI);                    // deploy the war file in the webApp contextRoot                    webAppContext = JahiaTools.removeFileExtension(warFile.getName(),".war");                    String webAppPath = appContextPath + File.separator + webAppContext;                    Vector webApps = handleWarFile(webAppPath, warFile.getAbsolutePath());                    warFile.delete();                    /*                    //move the war file in the Application Context Root                    File destFile = new File(appContextPath + File.separator + warFile.getName());                    JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService.deployEarFile"," dest file " + destFile.getAbsolutePath() );                    if ( destFile != null && destFile.isFile() ){                        destFile.delete();                    }                    warFile.renameTo(destFile);                    */                    // Activate the webapps in Orion                    activateWebApps(appContext,appContext,webApps);                    // register web applications in Jahia                    registerWebApps(site,appContext,earFile.getName(),webApps);                }            }            //extract the ear file in the Application Context Folder            earh.unzip(appContextPath);            earh.closeArchiveFile();            // notify Orion to deploy the application            Server_Xml doc = new Server_Xml(m_ServerXmlFilePath );            Application_Element appEl = new Application_Element(  appContext,                                                                  ".." + File.separator + "applications" + File.separator + tmpFile.getName(),                                                                  "", // deploy dir, ignored by default                                                                  "", // parent, ignored default                                                                  "" // autostart, ignored by default                                                                );            if ( doc.appendApplication(appEl) ){                doc.write();            }        } catch ( JahiaException e ) {            String errMsg = "Failed handling webApps file " ;            JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService::deployWarFile()", errMsg + "\n" + e.toString());            throw new JahiaException ( "JahiaOrionWebAppsDeployerBaseService::deployWarFile()",                                    "JahiaOrionWebAppsDeployerBaseService" + errMsg ,                                    JahiaException.SERVICE_ERROR, JahiaException.ERROR);        } finally {            // Important to close the JarFile object !!!!            // cannot delete it otherwise            if ( earh != null ){                earh.closeArchiveFile();            }        }        return true;    }    /**     * extract Web Component file in the web app context and     * return the list of Web App Definition objects     *     * @param (String) webAppContext , the full path to the Web App Context Root     * @param (String) filePath , the full path to the war file     * @return (Vector) the list of Web App Definitions     */    protected Vector handleWarFile(String webAppContext, String filePath) throws JahiaException {        // Create a WebApp War Handler        JahiaWebAppsWarHandler wah = null;        Vector webApps = new Vector();        try {            wah = new JahiaWebAppsWarHandler(filePath);            webApps = wah.getWebAppsPackage().getWebApps();            int size = webApps.size();            if ( size>0 ) {                // create the dir                File f= new File(webAppContext);                if ( !f.isDirectory() && !f.mkdirs() ){                    String errMsg = "Failed creating the war context root dir " + f.getAbsolutePath() ;                    JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService::deployWarFile()", errMsg + "\n" );                    throw new JahiaException ( "JahiaOrionWebAppsDeployerBaseService::deployWarFile()",                                            "JahiaOrionWebAppsDeployerBaseService" + errMsg ,                                            JahiaException.SERVICE_ERROR, JahiaException.ERROR);                }                // Remove the Meta-Inf folder                removeMetaInfFolder(f.getAbsolutePath());                // extract the war file in the Web App Context Root                wah.unzip(webAppContext);            }        } catch ( JahiaException e ) {            String errMsg = "Failed handling webApps file " ;            JahiaConsole.println("JahiaOrionWebAppsDeployerBaseService::deployWarFile()", errMsg + "\n" + e.toString());            throw new JahiaException ( "JahiaOrionWebAppsDeployerBaseService::deployWarFile()",                                    "JahiaOrionWebAppsDeployerBaseService" + errMsg ,                                    JahiaException.SERVICE_ERROR, JahiaException.ERROR);        } finally {            // Important to close the JarFile object !!!!            // cannot delete it otherwise            if ( wah != null ){                wah.closeArchiveFile();            }        }        return webApps;    }    /**     * Active Web Application in Orion     *     * @param (String) application , The name of the (enterprise-)application the web-apps exist in     * @param (String) appContext , The Root Context for the webApps     */    protected void activateWebApps( String application,                                   String appContext,                                   Vector webApps)                                   throws JahiaException {        Default_Web_Site_Xml doc   = new Default_Web_Site_Xml(                                        m_DefaultWebSiteFilePath );        Web_App_Element appEl = null;        int size = webApps.size();        int counter = 0;        for ( int i=0 ; i<size ; i++ ) {            JahiaWebAppDef webAppDef = (JahiaWebAppDef)webApps.get(i);            appEl = new Web_App_Element(                                       application,                                       "/" + appContext,                                       webAppDef.getContextRoot(),                                       "",                         // load-on-startup                                       "",                         // shared                                       ""                          // max-inactivity-time                                    );            if (doc.addWebApp(appEl)){                counter+=1;            }        }        if ( counter>0 ){            doc.write();        }    }    /**     * Create the Application context     *     * @param (String) appContext , the application context     * @return (String) appContextPath, the full application context path     */    protected String createApplicationContext(String appContext){        StringBuffer strBuf = new StringBuffer(1024);        strBuf.append(m_WebAppRootPath);        strBuf.append(appContext);        // full path to the application context root folder        String appContextPath = strBuf.toString();        //Create the Application Context Root        File f = new File(appContextPath);        if ( !f.isDirectory() && !f.mkdirs() ){            return null;        }        return appContextPath;    }    //-------------------------------------------------------------------------    /**     * Return true if configuration files are available     * @return (boolean) true if successfull     */    public boolean canDeploy(){        return (!m_OrionInitErr);    }} // end JahiaOrionWebAppsDeployerService

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -