Search in sources :

Example 6 with ApiException

use of org.eclipse.che.api.core.ApiException in project che by eclipse.

the class WorkspaceHolder method updateProject.

/**
     * Updates project on WS-master side.
     *
     * @param project
     *         project to update
     * @throws ServerException
     */
protected void updateProject(ProjectConfig project) throws ServerException {
    final UriBuilder builder = UriBuilder.fromUri(apiEndpoint).path(WorkspaceService.class).path(WorkspaceService.class, "updateProject");
    if (userToken != null)
        builder.queryParam("token", userToken);
    final String href = builder.build(new String[] { workspaceId, project.getPath() }, false).toString();
    try {
        httpJsonRequestFactory.fromUrl(href).usePutMethod().setBody(asDto(project)).request();
    } catch (IOException | ApiException e) {
        throw new ServerException(e.getMessage());
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) WorkspaceService(org.eclipse.che.api.workspace.server.WorkspaceService) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) ApiException(org.eclipse.che.api.core.ApiException)

Example 7 with ApiException

use of org.eclipse.che.api.core.ApiException in project che by eclipse.

the class WorkspaceHolder method addProject.

/**
     * Add project on WS-master side.
     *
     * @param project
     *         project to add
     * @throws ServerException
     */
protected void addProject(ProjectConfig project) throws ServerException {
    final UriBuilder builder = UriBuilder.fromUri(apiEndpoint).path(WorkspaceService.class).path(WorkspaceService.class, "addProject");
    if (userToken != null)
        builder.queryParam("token", userToken);
    final String href = builder.build(workspaceId).toString();
    try {
        httpJsonRequestFactory.fromUrl(href).usePostMethod().setBody(asDto(project)).request();
    } catch (IOException | ApiException e) {
        throw new ServerException(e.getMessage());
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) WorkspaceService(org.eclipse.che.api.workspace.server.WorkspaceService) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) ApiException(org.eclipse.che.api.core.ApiException)

Example 8 with ApiException

use of org.eclipse.che.api.core.ApiException in project che by eclipse.

the class WorkspaceHolder method workspaceDto.

/**
     * @return WorkspaceDto
     * @throws ServerException
     */
private WorkspaceDto workspaceDto() throws ServerException {
    final UriBuilder builder = UriBuilder.fromUri(apiEndpoint).path(WorkspaceService.class).path(WorkspaceService.class, "getByKey");
    if (userToken != null)
        builder.queryParam("token", userToken);
    final String href = builder.build(workspaceId).toString();
    try {
        return httpJsonRequestFactory.fromUrl(href).useGetMethod().request().asDto(WorkspaceDto.class);
    } catch (IOException | ApiException e) {
        throw new ServerException(e);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) WorkspaceService(org.eclipse.che.api.workspace.server.WorkspaceService) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) ApiException(org.eclipse.che.api.core.ApiException)

Example 9 with ApiException

use of org.eclipse.che.api.core.ApiException in project che by eclipse.

the class WorkspaceHolder method removeProject.

protected void removeProject(ProjectConfig project) throws ServerException {
    final UriBuilder builder = UriBuilder.fromUri(apiEndpoint).path(WorkspaceService.class).path(WorkspaceService.class, "deleteProject");
    if (userToken != null)
        builder.queryParam("token", userToken);
    final String href = builder.build(new String[] { workspaceId, project.getPath() }, false).toString();
    try {
        httpJsonRequestFactory.fromUrl(href).useDeleteMethod().request();
    } catch (IOException | ApiException e) {
        throw new ServerException(e.getMessage());
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) WorkspaceService(org.eclipse.che.api.workspace.server.WorkspaceService) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) ApiException(org.eclipse.che.api.core.ApiException)

Example 10 with ApiException

use of org.eclipse.che.api.core.ApiException in project che by eclipse.

the class WsAgentHealthCheckerImpl method check.

@Override
public WsAgentHealthStateDto check(Machine machine) throws ServerException {
    Server wsAgent = getWsAgent(machine);
    final WsAgentHealthStateDto agentHealthStateDto = newDto(WsAgentHealthStateDto.class);
    if (wsAgent == null) {
        return agentHealthStateDto.withCode(NOT_FOUND.getStatusCode()).withReason("Workspace Agent not available");
    }
    try {
        final HttpJsonRequest pingRequest = createPingRequest(machine);
        final HttpJsonResponse response = pingRequest.request();
        return agentHealthStateDto.withCode(response.getResponseCode());
    } catch (ApiException | IOException e) {
        return agentHealthStateDto.withCode(SERVICE_UNAVAILABLE.getStatusCode()).withReason(e.getMessage());
    }
}
Also used : Server(org.eclipse.che.api.core.model.machine.Server) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) IOException(java.io.IOException) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) HttpJsonResponse(org.eclipse.che.api.core.rest.HttpJsonResponse) ApiException(org.eclipse.che.api.core.ApiException)

Aggregations

IOException (java.io.IOException)10 ApiException (org.eclipse.che.api.core.ApiException)10 ServerException (org.eclipse.che.api.core.ServerException)7 UriBuilder (javax.ws.rs.core.UriBuilder)4 WorkspaceService (org.eclipse.che.api.workspace.server.WorkspaceService)4 File (java.io.File)3 Predicate (com.google.common.base.Predicate)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)2 Iterables (com.google.common.collect.Iterables)2 Files (com.google.common.io.Files)2 MediaType (com.google.common.net.MediaType)2 Singleton (com.google.inject.Singleton)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections.singletonList (java.util.Collections.singletonList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2