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

📄 jahiatomcatwebappsdeployerbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  JahiaTomcatWebAppsDeployerBaseService////  NK      12.01.2001////package org.jahia.services.webapps_deployer;import java.io.*;import java.net.*;import java.text.*;import java.util.*;import org.jahia.exceptions.*;        	// JahiaExceptionimport org.jahia.utils.*;             	// JahiaConsoleimport org.jahia.utils.keygenerator.JahiaKeyGen; // JahiaKeyGenimport org.jahia.settings.*;          	// JahiaPrivateSettingsimport org.jahia.registries.*;        	// ServicesRegistryimport org.jahia.services.*;          	// JahiaServiceimport org.jahia.services.sites.*;			// JahiaSiteimport org.jahia.data.webapps.*;      	// JahiaWebAppsDefimport org.jahia.data.constants.JahiaConstants;import org.jahia.data.applications.*;   // ApplicationBeanimport org.jahia.utils.keygenerator.JahiaKeyGen;//import org.jahia.services.pages.*;    // JahiaPageDefinitionimport org.jahia.services.webapps_deployer.tomcat.*;  //Tomcat_Users_Xml, TomcatWebAppsDeployer/** * This Service Register new Application Definition, * deploy webApps packaged in a .war or .ear file. * * @author Khue ng * @version 1.0 */public class JahiaTomcatWebAppsDeployerBaseService extends JahiaWebAppsDeployerService {    private static final String CLASS_NAME = JahiaWebAppsDeployerService.class.getName();    private static JahiaTomcatWebAppsDeployerBaseService m_Instance = null;    /** The tomcat tomcat-users.xml file **/    private String m_TomcatUsersXmlFilePath;    /** The Tomcat User needed to use Tomcat Management Application API **/    /** The Tomcat user name **/    private static String m_TomcatUserName = "Jahia";    /** The Tomcat user password **/    private static String m_TomcatUserPassword = "";    /** The Tomcat user roles **/    private static String m_TomcatUserRoles = "manager";    /** the HostHttpPath needed to call Tomcat Manager Servlet Application servlet **/    private static String m_JahiaWebAppsDeployerBaseURL = "";    /** Tomcat initialization error **/    private boolean m_TomcatInitErr = false;    /**     * Constructor     */    protected JahiaTomcatWebAppsDeployerBaseService(){        JahiaConsole.println( "JahiaWebAppDeployerBaseService",                              "***** Starting the Jahia Tomcat WebApps Deployer Base Service *****" );    }    /**     * Use this method to get an instance of this class     *     */    public static synchronized JahiaTomcatWebAppsDeployerBaseService getInstance(){        if ( m_Instance == null ){            m_Instance = new JahiaTomcatWebAppsDeployerBaseService();        }        return m_Instance;    }    //-------------------------------------------------------------------------    /***     * Initialize with Tomcat configuration and disk paths     *     * @param JahiaPrivateSettings jSettings     */    public void init( JahiaPrivateSettings jSettings )    throws JahiaInitializationException    {        if (!isInitialized ()) {            super.init(jSettings);            m_JahiaWebAppsDeployerBaseURL = jSettings.getJahiaWebAppsDeployerBaseURL();            // add a user with the manager role to tomcat-users.xml            //System.out.println(" m_ServerHomeDiskPath is " + m_ServerHomeDiskPath );            m_TomcatUsersXmlFilePath = m_ServerHomeDiskPath + "conf" + File.separator + "tomcat-users.xml";            File tomcatUsersXmlFile = new File(m_TomcatUsersXmlFilePath);            if ( tomcatUsersXmlFile == null || !tomcatUsersXmlFile.isFile()                || !tomcatUsersXmlFile.canWrite() ){                String errMsg = tomcatUsersXmlFile.getAbsolutePath() + " file cannot be accessed or doesn't exist "  ;                JahiaConsole.println(CLASS_NAME+".init()", errMsg + "\n" );                //throw new JahiaInitializationException ( errMsg );                m_TomcatInitErr = true;            } else {                if ( !addManagerUser(m_TomcatUsersXmlFilePath) ){                    String errMsg = " cannot create the tomcat manager user for web apps"  ;                    JahiaConsole.println(CLASS_NAME+".init()", errMsg + "\n" );                    m_TomcatInitErr = true;                }            }            mIsServiceInitialized = true;        }    } // end init    //-------------------------------------------------------------------------    /**     * Hot Deploy a .ear or .war file.     * Hot Deploy a web component on the specifiy server, active them to     * be immediately accessible in Jahia     *     * If it's a .ear file, the context is the application context     * If it's a .war file, the context is the web application context     *     * @param (JahiaSite) the site     * @param (String) context , the context     * @param (String) filePath , the full path to the ear file     * @return (boolean) true if successfull     */    public boolean deploy(JahiaSite site, String context, String filePath) throws JahiaException {        if ( !canDeploy() ){            return false;        }        boolean success = false;        if ( filePath.endsWith(".ear") ){            success = handleEarFile(site,filePath);        } else if ( filePath.endsWith(".war") ){            success = deployWarFile(site,context, filePath);        } else {            File tmpFile = new File(filePath);            if ( tmpFile != null && tmpFile.isDirectory() ){                success = deployDirectory(site,context,filePath);            }        }        if ( success ){            deletePackage(site,filePath);            return true;        } else {            return false;        }    }    //-------------------------------------------------------------------------    /**     * Undeploy a web application. Delete the web component from disk.     *     * @param (ApplicationBean) the application bean object     * @return (boolean) true if successfull     */    public boolean undeploy(ApplicationBean app) throws JahiaException {        if (!canDeploy()){            return false;        }        if ( app != null ) {            // call tomcat undeploy url            undeployWebApp(app.getContext());            // try to delete physically the directory on disk            JahiaTools.deleteFile(new File(m_WebAppRootPath + app.getContext()));            // delete the jsp cache folder            /*            StringBuffer path = new StringBuffer( System.getProperties().getProperty("user.dir") );            path.append(File.separator);            path.append("work");            path.append(File.separator);            path.append("localhost");            path.append(app.getContext());            JahiaTools.deleteFile( new File( path.toString()) );            */            return true;        }        return false;    }    //-------------------------------------------------------------------------    /**     * Deploy a single .war web component file     *     * @param (JahiaSite) the site     * @param (String) webContext , the web context     * @param (String) filePath , the full path to the war file     */    protected boolean deployWarFile(JahiaSite site, String webContext, String filePath) throws JahiaException {        Vector webApps = new Vector();        StringBuffer webContextDiskPath = new StringBuffer(m_WebAppRootPath);        webContextDiskPath.append(File.separator);        webContextDiskPath.append(webContext);        webContextDiskPath.append("_");        webContextDiskPath.append(site.getSiteKey());        //StringBuffer webContextBuff = new StringBuffer(site.getSiteKey());        StringBuffer webContextBuff = new StringBuffer(webContext);        webContextBuff.append("_");        webContextBuff.append(site.getSiteKey());        webApps = handleWarFile(webContextDiskPath.toString(), filePath);        // Activate the Web App in Tomcat        activateWebApp(webContextBuff.toString(),webContextDiskPath.toString());        // register Web Apps in Jahia        File f = new File(filePath);        registerWebApps(site,webContextBuff.toString(),f.getName(),webApps);        // move the war to the context        File warFile = new File(filePath);        warFile.delete();        /*        webContextDiskPath.append(File.separator);        webContextDiskPath.append(warFile.getName());        File newPos = new File(webContextDiskPath.toString()+File.separator+m_WEB_INF);        if ( !warFile.renameTo(newPos) ){            warFile.delete();        }        */        return true;    }    //-------------------------------------------------------------------------    /**     * Deploy an unziped directory     *     * @param (JahiaSite) the site     * @param (String) webContext , the web context     * @param (String) filePath , the full path to the war file     */    protected synchronized boolean deployDirectory(JahiaSite site, String webContext, String filePath) throws JahiaException {        String webContextDiskPath = m_WebAppRootPath + webContext;        File tmpFile = new File(webContextDiskPath);        File curFile = new File(filePath);        boolean sameDir = false;        sameDir = tmpFile.equals(curFile);        //System.out.println(" to deploy webContext =" + webContext + ", path=" + filePath);        //System.out.println(" deploy Directory webContextDiskPath =" + webContextDiskPath );        if ( sameDir || !tmpFile.isDirectory() ){            JahiaWebAppsPackage aPackage = loadWebAppInfoFromDirectory(filePath);            if ( aPackage != null && (aPackage.getWebApps().size()>0) ){                File dir = new File(filePath);                if ( !sameDir ){                    if ( dir != null && dir.renameTo(tmpFile) ){                        return false;                    }                }                // Activate the Web App in Tomcat                activateWebApp(webContext,webContextDiskPath);                // register Web Apps in Jahia                registerWebApps(site,webContext,"",aPackage.getWebApps());                return true;            }        }        return false;    }    //-------------------------------------------------------------------------    /**     * A simple way to pass a vector of .ear of war files     * to be deployed     *     * @param (JahiaSite) the site     * @param (Vector) files, a vector of .ear or .war files     * @return (boolean) true if done correctly     */    public boolean deploy(JahiaSite site,Vector files) {        synchronized (files) {            int size = files.size();            File fileItem = null;

⌨️ 快捷键说明

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