📄 tomcatwebappsdeployer.java
字号:
m_TomcatUserName, m_TomcatUserPassword ); } catch ( java.net.MalformedURLException mfu ){ JahiaConsole.println(CLASS_NAME+".unDeploy()", mfu.getMessage() ); return false; } if ( outPut != null && outPut.toString().startsWith("OK") ){ JahiaConsole.println(CLASS_NAME+".undeploy()"," successfull"); return true; } JahiaConsole.println(CLASS_NAME+".undeploy()"," Fail"); return false; } //------------------------------------------------------------------------- /** * Call the stop url * * @param (String) path, the context path to associate to the web apps * * ex: http://127.0.0.1:8080/manager/stop?path=/AbsenceRequest * * @return (boolean) return true if stopped correctly */ public boolean stop( String path ) { StringBuffer buff = new StringBuffer(1024); buff.append(m_StopUrlBase); buff.append("path=" + path); JahiaConsole.println(CLASS_NAME+".stop()"," url =" + buff.toString() ); String outPut = null; try { outPut = readInputStream ( new URL(m_ContextURL, buff.toString()), m_TomcatUserName, m_TomcatUserPassword ); } catch ( java.net.MalformedURLException mfu ){ JahiaConsole.println(CLASS_NAME+".unDeploy()", mfu.getMessage() ); return false; } if ( outPut != null && outPut.toString().startsWith("OK") ){ JahiaConsole.println(CLASS_NAME+".stop()"," successfull"); return true; } JahiaConsole.println(CLASS_NAME+".stop()"," Fail"); return false; } //------------------------------------------------------------------------- /** * Call the start url * * @param (String) path, the context path to associate to the web apps * * ex: http://127.0.0.1:8080/manager/start?path=/AbsenceRequest * * @return (boolean) return true if started correctly */ public boolean start( String path ) { StringBuffer buff = new StringBuffer(1024); buff.append(m_StartUrlBase); buff.append("path=" + path); JahiaConsole.println(CLASS_NAME+".start()"," url =" + buff.toString() ); String outPut = null; try { outPut = readInputStream ( new URL(m_ContextURL, buff.toString()), m_TomcatUserName, m_TomcatUserPassword ); } catch ( java.net.MalformedURLException mfu ){ JahiaConsole.println(CLASS_NAME+".start", mfu.getMessage() ); return false; } if ( outPut != null && outPut.toString().startsWith("OK") ){ JahiaConsole.println(CLASS_NAME+".start()"," successfull"); return true; } JahiaConsole.println(CLASS_NAME+".start()"," Fail"); return false; } //------------------------------------------------------------------------- /** * Call the reload url * * @param (String) path, the context path to associate to the web apps * * ex: http://127.0.0.1:8080/manager/reload?path=/AbsenceRequest * * @return (boolean) return true if reloaded correctly */ public boolean reload( String path ) { StringBuffer buff = new StringBuffer(1024); buff.append(m_ReloadUrlBase); buff.append("path=" + path); JahiaConsole.println(CLASS_NAME+".reload()"," url =" + buff.toString() ); String outPut = null; try { outPut = readInputStream ( new URL(m_ContextURL, buff.toString()), m_TomcatUserName, m_TomcatUserPassword ); } catch ( java.net.MalformedURLException mfu ){ JahiaConsole.println(CLASS_NAME+".start()", mfu.getMessage() ); return false; } if ( outPut != null && outPut.toString().startsWith("OK") ){ JahiaConsole.println(CLASS_NAME+".reload()"," successfull"); return true; } JahiaConsole.println(CLASS_NAME+".reload()"," Fail"); return false; } //------------------------------------------------------------------------- /** * Read input stream from url * * @param (String) url, the url * @param (String) username, the username * @param (String) password, the password * @return (String) the response in text/plain */ public String readInputStream ( URL url, String username, String password ) { StringBuffer outPut = new StringBuffer(1024); String line = null; try { BufferedReader in = new BufferedReader( new InputStreamReader(openURLForInput(url, username, password))); while ((line = in.readLine()) != null) { outPut.append(line); } } catch (IOException e) { JahiaConsole.println(CLASS_NAME+".readInputStream()", e.getMessage() ); return null; } return outPut.toString(); } //------------------------------------------------------------------------- /** * Open an url connection * * @param (String) url, the url * @param (String) username, the username * @param (String) password, the password * @return (InputStream) */ public InputStream openURLForInput ( URL url, String username, String password ) throws IOException { m_Conn = url.openConnection(); m_Conn.setDoInput(true); m_Conn.setRequestProperty ( "Authorization", userNamePasswordBase64(username,password) ); m_Conn.connect(); return m_Conn.getInputStream(); } //------------------------------------------------------------------------- /** * generate a base 64 encode user name and password string * * @param (String) username, the username * @param (String) password, the password * @return (String) the base 64 encode user name and password */ public String userNamePasswordBase64(String username, String password) { return "Basic " + base64Encode (username + ":" + password); } private final static char base64Array [] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; //------------------------------------------------------------------------- private static String base64Encode (String string) { String encodedString = ""; byte bytes [] = string.getBytes (); int i = 0; int pad = 0; while (i < bytes.length) { byte b1 = bytes [i++]; byte b2; byte b3; if (i >= bytes.length) { b2 = 0; b3 = 0; pad = 2; } else { b2 = bytes [i++]; if (i >= bytes.length) { b3 = 0; pad = 1; } else b3 = bytes [i++]; } byte c1 = (byte)(b1 >> 2); byte c2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4)); byte c3 = (byte)(((b2 & 0xf) << 2) | (b3 >> 6)); byte c4 = (byte)(b3 & 0x3f); encodedString += base64Array [c1]; encodedString += base64Array [c2]; switch (pad) { case 0: encodedString += base64Array [c3]; encodedString += base64Array [c4]; break; case 1: encodedString += base64Array [c3]; encodedString += "="; break; case 2: encodedString += "=="; break; } } return encodedString; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -