List of usage examples for com.liferay.portal.kernel.util Constants PROGRESS_ID
String PROGRESS_ID
To view the source code for com.liferay.portal.kernel.util Constants PROGRESS_ID.
Click Source Link
From source file:com.liferay.marketplace.appmanager.portlet.AppManagerPortlet.java
License:Open Source License
protected int doInstallRemoteApp(String url, UploadPortletRequest uploadPortletRequest, ActionRequest actionRequest, boolean failOnError) throws Exception { int responseCode = HttpServletResponse.SC_OK; String deploymentContext = ParamUtil.getString(uploadPortletRequest, "deploymentContext"); try {/* w w w. java 2 s . com*/ String fileName = null; if (Validator.isNotNull(deploymentContext)) { fileName = 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); } } Http.Options options = new Http.Options(); options.setFollowRedirects(false); options.setLocation(url); options.setPortletRequest(actionRequest); options.setPost(false); String progressId = ParamUtil.getString(uploadPortletRequest, Constants.PROGRESS_ID); options.setProgressId(progressId); byte[] bytes = HttpUtil.URLtoByteArray(options); Http.Response response = options.getResponse(); responseCode = response.getResponseCode(); if ((responseCode == HttpServletResponse.SC_OK) && (bytes.length > 0)) { String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); String destination = deployDir + StringPool.SLASH + fileName; File destinationFile = new File(destination); FileUtil.write(destinationFile, bytes); 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); } return responseCode; }
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;//w ww. j ava 2 s . c o m 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; }