Example usage for com.liferay.portal.kernel.util PropsKeys AUTO_DEPLOY_DEPLOY_DIR

List of usage examples for com.liferay.portal.kernel.util PropsKeys AUTO_DEPLOY_DEPLOY_DIR

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PropsKeys AUTO_DEPLOY_DEPLOY_DIR.

Prototype

String AUTO_DEPLOY_DEPLOY_DIR

To view the source code for com.liferay.portal.kernel.util PropsKeys AUTO_DEPLOY_DEPLOY_DIR.

Click Source Link

Usage

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

public void installLocalApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

    String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file"));

    File file = uploadPortletRequest.getFile("file");

    byte[] bytes = FileUtil.getBytes(file);

    if (ArrayUtil.isEmpty(bytes)) {
        SessionErrors.add(actionRequest, UploadException.class.getName());
    } else if (!fileName.endsWith(".jar") && !fileName.endsWith(".lpkg") && !fileName.endsWith(".war")) {

        throw new FileExtensionException();
    } else {//w w w  .j a v  a  2  s  . c o  m
        String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR);

        FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName);

        SessionMessages.add(actionRequest, "pluginUploaded");
    }

    sendRedirect(actionRequest, actionResponse);
}

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

protected int doInstallRemoteApp(String url, ActionRequest actionRequest, boolean failOnError)
        throws Exception {

    int responseCode = HttpServletResponse.SC_OK;

    try {//from   w  w w  . j  av  a2 s.c o  m
        String fileName = null;

        Http.Options options = new Http.Options();

        options.setFollowRedirects(false);
        options.setLocation(url);
        options.setPost(false);

        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.marketplace.appmanager.portlet.AppManagerPortlet.java

License:Open Source License

public void installApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    String installMethod = ParamUtil.getString(uploadPortletRequest, "installMethod");

    if (installMethod.equals("local")) {
        String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file"));

        File file = uploadPortletRequest.getFile("file");

        byte[] bytes = FileUtil.getBytes(file);

        if (ArrayUtil.isEmpty(bytes)) {
            SessionErrors.add(actionRequest, UploadException.class.getName());
        } else {/*from   ww w .  j  av  a2  s  . c o m*/
            String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR);

            FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName);

            SessionMessages.add(actionRequest, "pluginUploaded");
        }
    } else {
        try {
            String url = ParamUtil.getString(uploadPortletRequest, "url");

            URL urlObj = new URL(url);

            String host = urlObj.getHost();

            if (host.endsWith("sf.net") || host.endsWith("sourceforge.net")) {

                doInstallSourceForgeApp(urlObj.getPath(), uploadPortletRequest, actionRequest);
            } else {
                doInstallRemoteApp(url, uploadPortletRequest, actionRequest, true);
            }
        } catch (MalformedURLException murle) {
            SessionErrors.add(actionRequest, "invalidUrl", murle);
        }
    }

    String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");

    actionResponse.sendRedirect(redirect);
}

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.  ja va  2s.  c o  m
        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 void deployConfiguration(ActionRequest actionRequest) throws Exception {

    boolean enabled = ParamUtil.getBoolean(actionRequest, "enabled");
    String deployDir = ParamUtil.getString(actionRequest, "deployDir");
    String destDir = ParamUtil.getString(actionRequest, "destDir");
    long interval = ParamUtil.getLong(actionRequest, "interval");
    int blacklistThreshold = ParamUtil.getInteger(actionRequest, "blacklistThreshold");
    boolean unpackWar = ParamUtil.getBoolean(actionRequest, "unpackWar");
    boolean customPortletXml = ParamUtil.getBoolean(actionRequest, "customPortletXml");
    String jbossPrefix = ParamUtil.getString(actionRequest, "jbossPrefix");
    String tomcatConfDir = ParamUtil.getString(actionRequest, "tomcatConfDir");
    String tomcatLibDir = ParamUtil.getString(actionRequest, "tomcatLibDir");
    String pluginRepositoriesTrusted = ParamUtil.getString(actionRequest, "pluginRepositoriesTrusted");
    String pluginRepositoriesUntrusted = ParamUtil.getString(actionRequest, "pluginRepositoriesUntrusted");
    boolean pluginNotificationsEnabled = ParamUtil.getBoolean(actionRequest, "pluginNotificationsEnabled");
    String pluginPackagesIgnored = ParamUtil.getString(actionRequest, "pluginPackagesIgnored");

    PortletPreferences preferences = PrefsPropsUtil.getPreferences();

    preferences.setValue(PropsKeys.AUTO_DEPLOY_ENABLED, String.valueOf(enabled));
    preferences.setValue(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR, deployDir);
    preferences.setValue(PropsKeys.AUTO_DEPLOY_DEST_DIR, destDir);
    preferences.setValue(PropsKeys.AUTO_DEPLOY_INTERVAL, String.valueOf(interval));
    preferences.setValue(PropsKeys.AUTO_DEPLOY_BLACKLIST_THRESHOLD, String.valueOf(blacklistThreshold));
    preferences.setValue(PropsKeys.AUTO_DEPLOY_UNPACK_WAR, String.valueOf(unpackWar));
    preferences.setValue(PropsKeys.AUTO_DEPLOY_CUSTOM_PORTLET_XML, String.valueOf(customPortletXml));
    preferences.setValue(PropsKeys.AUTO_DEPLOY_JBOSS_PREFIX, jbossPrefix);
    preferences.setValue(PropsKeys.AUTO_DEPLOY_TOMCAT_CONF_DIR, tomcatConfDir);
    preferences.setValue(PropsKeys.AUTO_DEPLOY_TOMCAT_LIB_DIR, tomcatLibDir);
    preferences.setValue(PropsKeys.PLUGIN_REPOSITORIES_TRUSTED, pluginRepositoriesTrusted);
    preferences.setValue(PropsKeys.PLUGIN_REPOSITORIES_UNTRUSTED, pluginRepositoriesUntrusted);
    preferences.setValue(PropsKeys.PLUGIN_NOTIFICATIONS_ENABLED, String.valueOf(pluginNotificationsEnabled));
    preferences.setValue(PropsKeys.PLUGIN_NOTIFICATIONS_PACKAGES_IGNORED, pluginPackagesIgnored);

    preferences.store();/*w  ww  . ja  v  a 2s .  co m*/

    reloadRepositories(actionRequest);

    if (_log.isInfoEnabled()) {
        _log.info("Unregistering auto deploy directories");
    }

    AutoDeployUtil.unregisterDir("defaultAutoDeployDir");

    if (enabled) {
        if (_log.isInfoEnabled()) {
            _log.info("Registering auto deploy directories");
        }

        List<AutoDeployListener> autoDeployListeners = GlobalStartupAction.getAutoDeployListeners();

        AutoDeployDir autoDeployDir = new AutoDeployDir("defaultAutoDeployDir", new File(deployDir),
                new File(destDir), interval, blacklistThreshold, autoDeployListeners);

        AutoDeployUtil.registerDir(autoDeployDir);
    } else {
        if (_log.isInfoEnabled()) {
            _log.info("Not registering auto deploy directories");
        }
    }
}

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  www .  ja  v a2  s .com*/

    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  av  a 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;
}