List of usage examples for com.liferay.portal.plugin PluginPackageUtil registerPluginPackageInstallation
public static void registerPluginPackageInstallation(String preliminaryContext)
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected void localDeploy(ActionRequest actionRequest) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); String fileName = null;/*from w w w . j ava 2 s . c o m*/ String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext"); if (Validator.isNotNull(deploymentContext)) { fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war"; } else { fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file")); int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { deploymentContext = fileName.substring(0, pos); } } File file = uploadPortletRequest.getFile("file"); byte[] bytes = FileUtil.getBytes(file); if ((bytes == null) || (bytes.length == 0)) { SessionErrors.add(actionRequest, UploadException.class.getName()); return; } try { PluginPackageUtil.registerPluginPackageInstallation(deploymentContext); String source = file.toString(); String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR, PropsValues.AUTO_DEPLOY_DEPLOY_DIR); String destination = deployDir + StringPool.SLASH + fileName; FileUtil.copyFile(source, destination); SessionMessages.add(actionRequest, "pluginUploaded"); } finally { PluginPackageUtil.endPluginPackageInstallation(deploymentContext); } }
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected int remoteDeploy(String url, URL urlObj, ActionRequest actionRequest, boolean failOnError) throws Exception { int responseCode = HttpServletResponse.SC_OK; GetMethod getMethod = null;/*from w w w . j a va 2 s .c om*/ String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext"); try { HttpImpl httpImpl = (HttpImpl) HttpUtil.getHttp(); HostConfiguration hostConfiguration = httpImpl.getHostConfiguration(url); HttpClient httpClient = httpImpl.getClient(hostConfiguration); getMethod = new GetMethod(url); String fileName = null; if (Validator.isNotNull(deploymentContext)) { fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war"; } else { fileName = url.substring(url.lastIndexOf(CharPool.SLASH) + 1); int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { deploymentContext = fileName.substring(0, pos); } } PluginPackageUtil.registerPluginPackageInstallation(deploymentContext); responseCode = httpClient.executeMethod(hostConfiguration, getMethod); if (responseCode != HttpServletResponse.SC_OK) { if (failOnError) { SessionErrors.add(actionRequest, "errorConnectingToUrl", new Object[] { String.valueOf(responseCode) }); } return responseCode; } long contentLength = getMethod.getResponseContentLength(); String progressId = ParamUtil.getString(actionRequest, Constants.PROGRESS_ID); ProgressInputStream pis = new ProgressInputStream(actionRequest, getMethod.getResponseBodyAsStream(), contentLength, progressId); String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR, PropsValues.AUTO_DEPLOY_DEPLOY_DIR); String tmpFilePath = deployDir + StringPool.SLASH + _DOWNLOAD_DIR + StringPool.SLASH + fileName; File tmpFile = new File(tmpFilePath); if (!tmpFile.getParentFile().exists()) { tmpFile.getParentFile().mkdirs(); } FileOutputStream fos = new FileOutputStream(tmpFile); try { pis.readAll(fos); if (_log.isInfoEnabled()) { _log.info("Downloaded plugin from " + urlObj + " has " + pis.getTotalRead() + " bytes"); } } finally { pis.clearProgress(); } getMethod.releaseConnection(); if (pis.getTotalRead() > 0) { String destination = deployDir + StringPool.SLASH + fileName; File destinationFile = new File(destination); boolean moved = FileUtil.move(tmpFile, destinationFile); if (!moved) { FileUtil.copyFile(tmpFile, destinationFile); FileUtil.delete(tmpFile); } SessionMessages.add(actionRequest, "pluginDownloaded"); } else { if (failOnError) { SessionErrors.add(actionRequest, UploadException.class.getName()); } responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } catch (IOException ioe) { SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe); } finally { if (getMethod != null) { getMethod.releaseConnection(); } PluginPackageUtil.endPluginPackageInstallation(deploymentContext); } return responseCode; }