Search in sources :

Example 6 with APIException

use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.

the class RemoteServerBehavior method publishModuleDelta.

protected int publishModuleDelta(IModule[] module, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    IProject moduleProject = module[0].getProject();
    IModuleResourceDelta[] delta = getPublishedResourceDelta(module);
    if (shouldPublishModuleFull(delta)) {
        return publishModuleFull(module, CHANGED, monitor);
    }
    final String appName = ComponentUtilities.getServerContextRoot(moduleProject);
    // $NON-NLS-1$ //$NON-NLS-2$
    monitor.subTask("Creating partial " + moduleProject.getName() + " update archive...");
    final ILiferayProject liferayProject = LiferayCore.create(moduleProject);
    final IRemoteServerPublisher publisher = liferayProject.adapt(IRemoteServerPublisher.class);
    if (publisher == null) {
        setModuleStatus(module, null);
        throw new CoreException(LiferayServerCore.error(Msgs.publishingModuleProject));
    }
    final IPath warPath = publisher.publishModuleDelta(appName + ".war", delta, "liferay", true);
    monitor.worked(25);
    if (monitor != null && monitor.isCanceled()) {
        return IServer.PUBLISH_STATE_UNKNOWN;
    }
    monitor.subTask(Msgs.gettingLiferayConnection);
    IServerManagerConnection connection = getServerManagerConnection();
    monitor.subTask(NLS.bind(Msgs.updatingModuleProject, moduleProject.getName()));
    Object error = null;
    try {
        error = connection.updateApplication(appName, warPath.toOSString(), monitor);
    } catch (APIException e) {
        error = e.getMessage();
    }
    monitor.worked(90);
    if (error != null) {
        throw new CoreException(LiferayServerCore.error(error.toString()));
    }
    monitor.done();
    return IServer.PUBLISH_STATE_NONE;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) APIException(com.liferay.ide.core.remote.APIException) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) IProject(org.eclipse.core.resources.IProject)

Example 7 with APIException

use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.

the class RemoteServerBehavior method removeModule.

protected int removeModule(IModule[] module, IProgressMonitor monitor) throws CoreException {
    if (module == null) {
        throw new CoreException(LiferayServerCore.error(// $NON-NLS-1$
        "Cannot publish module with length " + (module != null ? module.length : 0)));
    }
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    IModule publishModule = module[0];
    IProject moduleProject = publishModule.getProject();
    if (moduleProject == null) {
        // just return this is a dead module
        setModuleStatus(module, null);
        return IServer.PUBLISH_STATE_UNKNOWN;
    }
    /*
         * First look to see if this module (ear plugin) is actually installed on liferay, and if it is then uninstall
         * it
         */
    monitor.beginTask(NLS.bind(Msgs.undeployingModuleProject, moduleProject.getName()), 100);
    final String appName = ComponentUtilities.getServerContextRoot(moduleProject);
    setModuleStatus(module, LiferayServerCore.info(Msgs.uninstalling));
    monitor.subTask(Msgs.gettingRemoteConnection);
    IServerManagerConnection remoteConnection = getServerManagerConnection();
    // 25%
    monitor.worked(25);
    // File scriptFile = getScriptFile( "publish/uninstallApplicationScript.groovy" );
    monitor.subTask(NLS.bind(Msgs.uninstallingModuleProject, moduleProject.getName()));
    Object error = null;
    try {
        error = remoteConnection.uninstallApplication(appName, monitor);
    } catch (APIException e) {
        error = e.getMessage();
    }
    // 100%
    monitor.worked(75);
    if (error != null) {
        throw new CoreException(LiferayServerCore.error(error.toString()));
    }
    setModuleStatus(module, null);
    return IServer.PUBLISH_STATE_NONE;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IModule(org.eclipse.wst.server.core.IModule) APIException(com.liferay.ide.core.remote.APIException) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject)

Example 8 with APIException

use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.

the class ServerManagerConnection method updateApplication.

public Object updateApplication(String appName, String absolutePath, IProgressMonitor monitor) throws APIException {
    try {
        final File file = new File(absolutePath);
        final FileBody fileBody = new FileBody(file);
        final MultipartEntity entity = new MultipartEntity();
        entity.addPart(file.getName(), fileBody);
        final HttpPut httpPut = new HttpPut();
        httpPut.setEntity(entity);
        Object response = httpJSONAPI(httpPut, getUpdateURI(appName));
        if (response instanceof JSONObject) {
            JSONObject json = (JSONObject) response;
            if (isSuccess(json)) {
                // $NON-NLS-1$
                System.out.println("updateApplication: success.\n\n");
            } else {
                if (isError(json)) {
                    // $NON-NLS-1$
                    return json.getString("error");
                } else {
                    // $NON-NLS-1$
                    return "updateApplication error " + getDeployURI(appName);
                }
            }
        }
        httpPut.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
    return null;
}
Also used : FileBody(org.apache.http.entity.mime.content.FileBody) JSONObject(org.json.JSONObject) MultipartEntity(org.apache.http.entity.mime.MultipartEntity) JSONObject(org.json.JSONObject) File(java.io.File) HttpPut(org.apache.http.client.methods.HttpPut) APIException(com.liferay.ide.core.remote.APIException) JSONException(org.json.JSONException)

Example 9 with APIException

use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.

the class ServerManagerConnection method isLiferayPluginStarted.

public boolean isLiferayPluginStarted(String appName) throws APIException {
    final Object response = getJSONAPI(getPluginURI(appName));
    if (response instanceof JSONObject) {
        JSONObject json = (JSONObject) response;
        try {
            if (isSuccess(json)) {
                JSONObject jsonOutput = getJSONOutput(json);
                boolean installed = jsonOutput.getBoolean("started");
                if (installed) {
                    return true;
                }
            }
        } catch (Exception e) {
            throw new APIException(getPluginURI(appName), e);
        }
    }
    return false;
}
Also used : APIException(com.liferay.ide.core.remote.APIException) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) APIException(com.liferay.ide.core.remote.APIException) JSONException(org.json.JSONException)

Example 10 with APIException

use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.

the class ServerManagerConnection method installApplication.

public Object installApplication(String absolutePath, String appName, IProgressMonitor submon) throws APIException {
    try {
        FileBody fileBody = new FileBody(new File(absolutePath));
        MultipartEntity entity = new MultipartEntity();
        // $NON-NLS-1$
        entity.addPart("deployWar", fileBody);
        HttpPost httpPost = new HttpPost();
        httpPost.setEntity(entity);
        Object response = httpJSONAPI(httpPost, getDeployURI(appName));
        if (response instanceof JSONObject) {
            JSONObject json = (JSONObject) response;
            if (isSuccess(json)) {
                // $NON-NLS-1$
                System.out.println("installApplication: Sucess.\n\n");
            } else {
                if (isError(json)) {
                    // $NON-NLS-1$
                    return json.getString("error");
                } else {
                    // $NON-NLS-1$
                    return "installApplication error " + getDeployURI(appName);
                }
            }
        }
        httpPost.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) FileBody(org.apache.http.entity.mime.content.FileBody) JSONObject(org.json.JSONObject) MultipartEntity(org.apache.http.entity.mime.MultipartEntity) JSONObject(org.json.JSONObject) File(java.io.File) APIException(com.liferay.ide.core.remote.APIException) JSONException(org.json.JSONException)

Aggregations

APIException (com.liferay.ide.core.remote.APIException)14 JSONObject (org.json.JSONObject)11 JSONArray (org.json.JSONArray)5 JSONException (org.json.JSONException)4 File (java.io.File)2 MultipartEntity (org.apache.http.entity.mime.MultipartEntity)2 FileBody (org.apache.http.entity.mime.content.FileBody)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 FMDebugTarget (com.liferay.ide.portal.core.debug.fm.FMDebugTarget)1 IServerManagerConnection (com.liferay.ide.server.remote.IServerManagerConnection)1 ArrayList (java.util.ArrayList)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpPut (org.apache.http.client.methods.HttpPut)1 IPath (org.eclipse.core.runtime.IPath)1 IDebugTarget (org.eclipse.debug.core.model.IDebugTarget)1 IModule (org.eclipse.wst.server.core.IModule)1 IServer (org.eclipse.wst.server.core.IServer)1