📄 jahiatomcatwebappsdeployerbaseservice.java
字号:
for ( int i=0 ; i<size ; i++ ){ fileItem = (File)files.get(i); if ( fileItem != null && fileItem.isFile() ){ /* JahiaConsole.println("JahiaTomcatWebAppsDeployerBaseService::deployWebApps", " JahiaTomcatWebAppsDeployerBaseService found new webApp: " + fileItem.getName() ); */ try { JahiaWebAppsPackage pack = null; if ( site.getWebAppsAutoDeployMode() && canDeploy() ){ if ( fileItem.getName().endsWith(".ear") || fileItem.getName().endsWith(".war") ){ pack = loadWebAppInfo(fileItem.getAbsolutePath()); if ( pack != null ){ if (! deploy(site,pack.getContextRoot(),fileItem.getAbsolutePath()) ){ fileItem.delete(); return false; } } else { try { File newFile = new File(fileItem.getAbsolutePath()+"_error"); //newFile.createNewFile(); fileItem.renameTo(newFile); } catch ( Throwable t ){ JahiaConsole.println("JahiaTomcatWebAppsDeployerBaseService.deploy()", "Error renaming error file " + fileItem.toString() + " to " + fileItem.getAbsolutePath() + "_error"); JahiaConsole.printe("JahiaTomcatWebAppsDeployerBaseService.deploy()", t); } } } } else { addNewFile(site,fileItem.getAbsolutePath()); } } catch ( JahiaException e ) { String errMsg = "Failed deploying Application file " + fileItem.getName(); JahiaConsole.printe( "JahiaTomcatWebAppsDeployerBaseService.deploy()", e); fileItem.delete(); } } } } return true; } //------------------------------------------------------------------------- /** * Handle Ear application File Deployment * * @param (JahiaSite) the site * @param (String) filePath , the full path to the ear file * @return (boolean) true if success full */ protected boolean handleEarFile(JahiaSite site, String filePath) throws JahiaException { //JahiaConsole.println("JahiaTomcatWebAppsDeployerBaseService.handleEarFile","started"); // Create a Ear Handler JahiaEarFileHandler earh = null; try { earh = new JahiaEarFileHandler(filePath); // 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 for ( int i=0 ; i<size ; i++ ){ webComp = (Web_Component)webComponents.get(i); webURI = webComp.getWebURI(); if ( webURI != null && (webURI.length()>0) ){ //JahiaConsole.println("JahiaTomcatWebAppsDeployerBaseService.handleEarFile","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); if ( !deployWarFile(site,JahiaTools.removeFileExtension(warFile.getName(),".war"), warFile.getAbsolutePath() ) ){ return false; } } } } catch ( JahiaException e ) { String errMsg = "Failed handling webApps file " ; JahiaConsole.println("JahiaTomcatWebAppsDeployerBaseService::deployWarFile()", errMsg + "\n" + e.toString()); throw new JahiaException ( "JahiaTomcatWebAppsDeployerBaseService::deployEarFile()", "JahiaTomcatWebAppsDeployerBaseService" + 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("JahiaTomcatWebAppsDeployerBaseService::deployWarFile()", errMsg + "\n" ); throw new JahiaException ( "JahiaTomcatWebAppsDeployerBaseService::deployWarFile()", "JahiaTomcatWebAppsDeployerBaseService" + 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("JahiaTomcatWebAppsDeployerBaseService::deployWarFile()", errMsg + "\n" + e.toString()); throw new JahiaException ( "JahiaTomcatWebAppsDeployerBaseService::deployWarFile()", "JahiaTomcatWebAppsDeployerBaseService" + errMsg , JahiaException.SERVICE_ERROR, JahiaException.ERROR, e); } finally { // Important to close the JarFile object !!!! // cannot delete it otherwise if ( wah != null ){ wah.closeArchiveFile(); } } return webApps; } //------------------------------------------------------------------------- /** * Active Web Application in Tomcat * * @param (String) webContext , The Context for the webApps * @param (String) webAppDiskPath , The absolute disk path to the unpacked web app * @param (boolean) return true if success full */ protected boolean activateWebApp( String context, String webAppDiskPath ) throws JahiaException { TomcatWebAppsDeployer deployer = new TomcatWebAppsDeployer( m_ServerType, m_JahiaWebAppsDeployerBaseURL, m_TomcatUserName, m_TomcatUserPassword ); File tmpFile = new File(webAppDiskPath); String fileUrl = null; try { fileUrl = tmpFile.toURL().toString(); } catch( java.net.MalformedURLException ue ){ JahiaConsole.printe("JahiaTomcatWebAppsDeployerBaseService.activateWebApp", ue); return false; } return deployer.deploy("/" + context, fileUrl ); } //------------------------------------------------------------------------- /** * Undeploy a Web Application in Tomcat * * @param (String) webContext , The Context for the webApps * @param (boolean) return true if success full */ protected boolean undeployWebApp( String context ) throws JahiaException { TomcatWebAppsDeployer deployer = new TomcatWebAppsDeployer( m_ServerType, m_JahiaWebAppsDeployerBaseURL, m_TomcatUserName, m_TomcatUserPassword ); /* boolean doStop = ( m_ServerType.endsWith(JahiaConstants.SERVER_TOMCAT4_BETA2) || m_ServerType.endsWith(JahiaConstants.SERVER_TOMCAT4_BETA3) || m_ServerType.endsWith(JahiaConstants.SERVER_TOMCAT4_BETA6) ); */ boolean doStop = ( !m_ServerType.endsWith(JahiaConstants.SERVER_TOMCAT4_BETA1) ); if ( context.startsWith("/") ){ if ( doStop ){ deployer.stop(context); } return deployer.undeploy(context); } else { if ( doStop ){ deployer.stop("/" + context); } return deployer.undeploy("/" + context); } } //------------------------------------------------------------------------- /** * Create the web context * * @param (String) webContext , the web context * @return (String) webContextPath, the full web context path */ protected String createWebContext(String webContext){ StringBuffer strBuf = new StringBuffer(1024); strBuf.append(m_WebAppRootPath); strBuf.append(webContext); // full path to the application context root folder String webContextPath = strBuf.toString(); File f = new File(webContextPath); if ( !f.isDirectory() && !f.mkdirs() ){ return null; } return webContextPath; } //------------------------------------------------------------------------- /** * Add a User with the manager role to tomcat-users.xml * * @param (String) the full path to the tomcat-usesr.xml file * @return (boolean) true if successfull */ protected boolean addManagerUser( String docPath ){ try { String password = null; m_TomcatUserPassword = JahiaKeyGen.getKey(15); Tomcat_Users_Xml doc = new Tomcat_Users_Xml(docPath); password = doc.getUserPassword(m_TomcatUserName,m_TomcatUserRoles); if ( password == null ){ doc.addUser(m_TomcatUserName,m_TomcatUserPassword,m_TomcatUserRoles); doc.write(); } else if ( password.equals("") ){ doc.updateUser(m_TomcatUserName,m_TomcatUserPassword,m_TomcatUserRoles); doc.write(); } else { m_TomcatUserPassword = password; } } catch ( JahiaException e ){ return false; } return true; } //------------------------------------------------------------------------- /** * Return true if the tomcat-users.xml has been correctly loaded. * If not, deployment functionality are not available and always return false * @return (boolean) true if successfull */ public boolean canDeploy(){ return (!m_TomcatInitErr); }} // end JahiaTomcatWebAppsDeployerService
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -