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

📄 tomcatwebappsdeployer.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  NK      06.02.2001////package org.jahia.services.webapps_deployer.tomcat;import java.io.*;import java.net.*;import java.util.*;import org.jahia.exceptions.*;import org.jahia.utils.JahiaTools;import org.jahia.utils.JahiaConsole;import org.jahia.data.constants.JahiaConstants;/** * Handle web app deployment and activation under tomcat * * Create a Url object handler used to call the Tomcat Management * Application servlet Url ( org.apache.catalina.servlets.ManagerServlet ). * We call this servlet to deploy webapps under tomcat * * @author Khue ng * @version 1.0 */public class TomcatWebAppsDeployer {    /** The Tomcat Version **/    private static String m_TomcatVersion = JahiaConstants.SERVER_TOMCAT;    /** The Tomcat user name **/    private static String m_TomcatUserName = "Jahia";    /** The Tomcat user password **/    private static String m_TomcatUserPassword = "Jahia";    /** the Server Host Http Path **/    private String m_JahiaWebAppsDeployerBaseURL = "";    /** the list url **/    private String m_ListUrlBase = "";    /** the deploy url **/    private String m_DeployUrlBase = "";    /** the undeploy url **/    private String m_UnDeployUrlBase = "";    /** the reload url **/    private String m_ReloadUrlBase = "";    /** the start url **/    private String m_StartUrlBase = "";    /** the stop url **/    private String m_StopUrlBase = "";    /** The Url Connection **/    private URLConnection m_Conn = null;    private URL m_ContextURL = null;    private static final String CLASS_NAME = "TomcatWebAppsDeployer";    /**     * Constructor     *     * @param (String) the host http     */    public TomcatWebAppsDeployer ( String tomcatVersion,                                   String m_WebAppsDeployerBaseURL,                                   String username,                                   String password                                 ){        m_TomcatVersion = tomcatVersion;        m_JahiaWebAppsDeployerBaseURL = m_WebAppsDeployerBaseURL ;        m_TomcatUserName = username;        m_TomcatUserPassword = password;        try {            m_ContextURL = new URL ( "http://localhost:8080" );        } catch (MalformedURLException mue) {            JahiaConsole.printe(CLASS_NAME + ".constructor", mue);        }        /*        JahiaConsole.println(CLASS_NAME + ".constructor",                             "TomcatWebAppsDeployer, using username=" +                             m_TomcatUserName + " and password=" +                             m_TomcatUserPassword);        */        //default        m_ListUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/list?" ;        m_DeployUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/deploy?" ;        m_UnDeployUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/undeploy?" ;        m_ReloadUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/reload?" ;        m_StartUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/start?" ;        m_StopUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/stop?" ;        if( !m_TomcatVersion.endsWith( JahiaConstants.SERVER_TOMCAT4_BETA1 ) ) { // the server is tomcatb1...            m_DeployUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/install?" ;            m_UnDeployUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/remove?" ;        }        m_DeployUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/install?" ;        m_UnDeployUrlBase = m_JahiaWebAppsDeployerBaseURL + "/manager/remove?" ;    }    //-------------------------------------------------------------------------    /**     * Call the list url , below is what we receive in text/plain     *     *  *	OK - Listed applications for virtual host localhost     *  *	/Bookcards:running:0     *  *	/TodoList:stopped:0     *  *	/examples2:running:0     *  *	/webdav:running:0     *  *	/jahia:running:1     *  *	/examples:running:0     *  *	/manager:running:0     *  *	/:running:0     *     * @return (Vector) return a vector of context retrieved from the response     *					null if fail.     */    public Vector getAppList() {        JahiaConsole.println(CLASS_NAME+".getAppList()"," url ="                            + m_ListUrlBase);        String outPut = null;        try{            outPut = readInputStream (	new URL(m_ContextURL, m_ListUrlBase),                                            m_TomcatUserName,                                            m_TomcatUserPassword );        } catch ( java.net.MalformedURLException mfu ){            JahiaConsole.println(CLASS_NAME+".getAppList()", mfu.getMessage() );            return null;        }        Vector vec = new Vector();        if ( outPut != null && outPut.startsWith("OK") ){            String[] tockens = JahiaTools.getTokens(outPut,"/");            for ( int i=1 ; i<(tockens.length-1) ; i++ ){                vec.add(tockens[i]);            }        } else {            vec = null;        }        return vec;    }    //-------------------------------------------------------------------------    /**     * Call the deploy url     *     * @param (String) path, the context path to associate to the web apps     * @param (String) war, the path to a war file to deploy or the path to     *                 the unpacked directory to asscotiate with a context     *     * ex: http://127.0.0.1:8080/manager/deploy?path=/AbsenceRequest&     *          war=jar:file:/d:/tomcat/webapps/jahia/war_webapps/AbsenceRequest.war!/     *     *     * @return (boolean) return true if deployed correctly     */    public boolean deploy(  String path,                            String war ) {        StringBuffer buff = new StringBuffer(1024);        buff.append(m_DeployUrlBase);        buff.append("path=" );        buff.append(path);        buff.append("&");        buff.append("war=");        buff.append( war );        String outPut = null;        URL deployURL = null;        try {            deployURL = new URL ( m_ContextURL, buff.toString() );            JahiaConsole.println(CLASS_NAME+".deploy()",                                 "deploying via URL=" +                                 deployURL.toString() + "...");            outPut = readInputStream (	deployURL ,                                        m_TomcatUserName,                                        m_TomcatUserPassword );        } catch ( java.net.MalformedURLException mfu ){            JahiaConsole.printe(CLASS_NAME+".deploy()", mfu );            return false;        }        if ( outPut != null ) {            if (outPut.toString().startsWith("OK") ){                JahiaConsole.println(CLASS_NAME+".deploy()",                                     "deployment via URL " +                                     deployURL.toString() + " successfull");                return true;            } else {                JahiaConsole.println(CLASS_NAME+".deploy()",                                     "deployment via URL " +                                     deployURL.toString() +                                     " not successful. Returned output=" +                                     outPut);            }        }        //JahiaConsole.println(CLASS_NAME+".deploy()"," Fail");        return false;    }    //-------------------------------------------------------------------------    /**     * Call the undeploy url     *     * @param (String) path, the context path to associate to the web apps     *     * ex: http://127.0.0.1:8080/manager/undeploy?path=/AbsenceRequest     *     * @return (boolean) return true if deployed correctly     */    public boolean undeploy( String path ) {        StringBuffer buff = new StringBuffer(1024);        buff.append(m_UnDeployUrlBase);        buff.append("path=" + path);        JahiaConsole.println(CLASS_NAME+".undeploy()"," url ="                            + buff.toString() );        String outPut = null;        try {            outPut = readInputStream (	new URL(m_ContextURL, buff.toString()),

⌨️ 快捷键说明

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