Package org.eclipse.orion.server.core

Examples of org.eclipse.orion.server.core.ServerStatus


      URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.BLAME);

      Path Filepath = new Path(requestInfo.filePath.toString());
      if (Filepath.hasTrailingSeparator()) {
        String msg = NLS.bind("Cannot get blame Information on a folder: {0}", requestInfo.filePath.toString());
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
      }

      Blame blame = new Blame(cloneLocation, requestInfo.db);

      String gitSegment = requestInfo.gitSegment;
      if (!gitSegment.equalsIgnoreCase("HEAD") && !gitSegment.equalsIgnoreCase("master")) {
        ObjectId id = ObjectId.fromString(requestInfo.gitSegment);
        blame.setStartCommit(id);
      }

      String path = requestInfo.relativePath;
      blame.setFilePath(path);
      blame.setBlameLocation(getURI(request));
      doBlame(blame, requestInfo.db);
      OrionServlet.writeJSONResponse(request, response, blame.toJSON(), JsonURIUnqualificationStrategy.ALL_NO_GIT);
      return true;
    } catch (Exception e) {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Error generating blame response", e));
    }
  }
View Full Code Here


      URI appsURI = targetURI.resolve(appsUrl);
      GetMethod getAppsMethod = new GetMethod(appsURI.toString());
      HttpUtil.configureHttpMethod(getAppsMethod, target);
      getAppsMethod.setQueryString("q=name:" + appName + "&inline-relations-depth=1"); //$NON-NLS-1$ //$NON-NLS-2$

      ServerStatus appsStatus = HttpUtil.executeMethod(getAppsMethod);
      if (!appsStatus.isOK())
        return appsStatus;

      JSONObject apps = appsStatus.getJsonData();
      if (!apps.has("resources") || apps.getJSONArray("resources").length() == 0) //$NON-NLS-1$//$NON-NLS-2$
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Application not found", null);

      appMetadata = apps.getJSONArray("resources").getJSONObject(0).getJSONObject("metadata"); //$NON-NLS-1$ //$NON-NLS-2$
      appEntity = apps.getJSONArray("resources").getJSONObject(0).getJSONObject("entity"); //$NON-NLS-1$ //$NON-NLS-2$

      if (application.getGuid() == null) {

        String summaryAppUrl = appMetadata.getString("url") + "/summary"; //$NON-NLS-1$ //$NON-NLS-2$
        URI summaryAppURI = targetURI.resolve(summaryAppUrl);

        GetMethod getSummaryMethod = new GetMethod(summaryAppURI.toString());
        HttpUtil.configureHttpMethod(getSummaryMethod, target);

        ServerStatus getStatus = HttpUtil.executeMethod(getSummaryMethod);
        if (!getStatus.isOK())
          return getStatus;

        JSONObject summaryJSON = getStatus.getJsonData();

        /* set known application GUID */
        application.setGuid(summaryJSON.getString(CFProtocolConstants.V2_KEY_GUID));
      }

      /* gather application service bindings */
      ArrayList<String> serviceInstances = new ArrayList<String>();
      JSONArray appServiceBindings = appEntity.getJSONArray("service_bindings"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
      for (int i = 0; i < appServiceBindings.length(); ++i) {
        JSONObject binding = appServiceBindings.getJSONObject(i).getJSONObject("entity"); //$NON-NLS-1$
        serviceInstances.add(binding.getString("service_instance_url")); //$NON-NLS-1$
      }

      /* delete the application */
      URI appURI = targetURI.resolve("/v2/apps/" + application.getGuid()); //$NON-NLS-1$

      DeleteMethod deleteAppMethod = new DeleteMethod(appURI.toString());
      HttpUtil.configureHttpMethod(deleteAppMethod, target);
      deleteAppMethod.setQueryString("recursive=true"); //$NON-NLS-1$

      ServerStatus status = HttpUtil.executeMethod(deleteAppMethod);
      return status;

    } catch (Exception e) {
      String msg = NLS.bind("An error occured when performing operation {0}", commandName);
      logger.error(msg, e);
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
  }
View Full Code Here

      }
    }
    Writer fileWriter = new OutputStreamWriter(file.openOutputStream(EFS.NONE, null), "UTF-8");
    IOUtilities.pipe(new StringReader(newContents), fileWriter, false, true);
    if (failed) {
      statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_ACCEPTABLE, "Bad File Diffs. Please paste this content in a bug report: \u00A0\u00A0   " + changes.toString(), null));
      return;
    }

    // return metadata with the new Etag
    handleGetMetadata(request, response, file);
View Full Code Here

          default :
            return false;
        }
      }
    } catch (JSONException e) {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Syntax error in request", e));
    } catch (Exception e) {
      if (!handleAuthFailure(request, response, e))
        throw new ServletException(NLS.bind("Error retrieving file: {0}", file), e);
    }
    return false;
View Full Code Here

    Repository db = null;
    try {
      Path path = new Path(gitPathInfo);
      if (!path.hasTrailingSeparator()) {
        String msg = NLS.bind("Cannot get status on a file: {0}", gitPathInfo);
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
      }
      if (!AuthorizationService.checkRights(request.getRemoteUser(), "/" + path.toString(), request.getMethod())) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return true;
      }
      Set<Entry<IPath, File>> set = GitUtils.getGitDirs(path, Traverse.GO_UP).entrySet();
      File gitDir = set.iterator().next().getValue();
      if (gitDir == null)
        return false; // TODO: or an error response code, 405?
      db = FileRepositoryBuilder.create(gitDir);
      Git git = new Git(db);
      org.eclipse.jgit.api.Status gitStatus = git.status().call();

      URI baseLocation = getURI(request);
      String relativePath = GitUtils.getRelativePath(path, set.iterator().next().getKey());
      IPath basePath = new Path(relativePath);
      Status status = new Status(baseLocation, db, gitStatus, basePath);
      OrionServlet.writeJSONResponse(request, response, status.toJSON(), JsonURIUnqualificationStrategy.ALL_NO_GIT);
      return true;

    } catch (Exception e) {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Error generating status response", e));
    } finally {
      if (db != null) {
        // close the git repository
        db.close();
View Full Code Here

      appName = app.get(CFProtocolConstants.V2_KEY_NAME).getValue();
      return Status.OK_STATUS;

    } catch (InvalidAccessException e) {
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), null);
    }
  }
View Full Code Here

        int code = CFActivator.getDefault().getHttpClient().executeMethod(postMethod);
        response = postMethod.getResponseBodyAsString();
        if (code != HttpServletResponse.SC_OK) {
          try {
            result = new JSONObject(response);
            return new ServerStatus(Status.ERROR, code, "", result, null);
          } catch (Exception e) {
            result = null;
            return new ServerStatus(Status.ERROR, code, "Unexpected error", null);
          }
        }
      } finally {
        postMethod.releaseConnection();
      }

      this.cloud.setAccessToken(new JSONObject(response));
    } catch (Exception e) {
      String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
      logger.error(msg, e);
      return new Status(IStatus.ERROR, CFActivator.PI_CF, msg, e);
    }

    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
  }
View Full Code Here

        return false;
      }

    } catch (Exception e) {
      String msg = NLS.bind("Failed to handle /git/remote request for {0}", path); //$NON-NLS-1$
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
    }
  }
View Full Code Here

          db.close();
        }
      }
      JSONObject errorData = new JSONObject();
      errorData.put(GitConstants.KEY_CLONE, cloneLocation);
      return statusHandler.handleRequest(request, response, new ServerStatus(new Status(IStatus.ERROR, GitActivator.PI_GIT, "No remote branch found: "
          + p.uptoSegment(2).removeTrailingSeparator()), HttpServletResponse.SC_NOT_FOUND, errorData));
    }
    return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
        "Bad request, \"/git/remote/{remote}/{branch}/file/{path}\" expected", null));
  }
View Full Code Here

      return HttpUtil.executeMethod(unmapRouteMethod);

    } catch (Exception e) {
      String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
      logger.error(msg, e);
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.core.ServerStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.