Package org.eclipse.orion.server.core

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


      default:
        return false;
      }
    } catch (Exception e) {
      String msg = NLS.bind("Failed to process an operation on commits 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


    if (p.segment(0).equals(Clone.RESOURCE) && p.segment(1).equals("file")) { //$NON-NLS-1$
      // expected path /gitapi/config/clone/file/{path}
      File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
      if (gitDir == null)
        return statusHandler.handleRequest(request, response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No repository found under {0}", p.removeFirstSegments(1)),
                null));
      Repository db = null;
      try {
        db = FileRepositoryBuilder.create(gitDir);
        URI cloneLocation = BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.CONFIG);
        ConfigOption configOption = new ConfigOption(cloneLocation, db);
        OrionServlet.writeJSONResponse(request, response, configOption.toJSON(/* all */), JsonURIUnqualificationStrategy.ALL_NO_GIT);
        return true;
      } finally {
        if (db != null) {
          db.close();
        }
      }
    } else if (p.segment(1).equals(Clone.RESOURCE) && p.segment(2).equals("file")) { //$NON-NLS-1$
      // expected path /gitapi/config/{key}/clone/file/{path}
      File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
      if (gitDir == null)
        return statusHandler.handleRequest(request, response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No repository found under {0}", p.removeFirstSegments(2)),
                null));
      URI cloneLocation = BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.CONFIG_OPTION);
      Repository db = null;
      try {
        db = FileRepositoryBuilder.create(gitDir);
        ConfigOption configOption = new ConfigOption(cloneLocation, db, p.segment(0));
        if (!configOption.exists())
          return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND,
              "There is no config entry with key provided", null));
        OrionServlet.writeJSONResponse(request, response, configOption.toJSON(), JsonURIUnqualificationStrategy.ALL_NO_GIT);
        return true;
      } catch (IllegalArgumentException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), e));
      } finally {
        if (db != null) {
          db.close();
        }
      }
View Full Code Here

    if (p.segment(0).equals(Clone.RESOURCE) && p.segment(1).equals("file")) { //$NON-NLS-1$
      // expected path /gitapi/config/clone/file/{path}
      File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
      if (gitDir == null)
        return statusHandler.handleRequest(request, response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No repository found under {0}", p.removeFirstSegments(1)),
                null));
      URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.CONFIG);
      JSONObject toPost = OrionServlet.readJSONRequest(request);
      String key = toPost.optString(GitConstants.KEY_CONFIG_ENTRY_KEY, null);
      if (key == null || key.isEmpty())
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
            "Config entry key must be provided", null));
      String value = toPost.optString(GitConstants.KEY_CONFIG_ENTRY_VALUE, null);
      if (value == null || value.isEmpty())
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
            "Config entry value must be provided", null));
      Repository db = null;
      try {
        db = FileRepositoryBuilder.create(gitDir);
        ConfigOption configOption = new ConfigOption(cloneLocation, db, key);
        boolean present = configOption.exists();
        ArrayList<String> valList = new ArrayList<String>();
        if (present) {
          String[] val = configOption.getValue();
          valList.addAll(Arrays.asList(val));
        }
        valList.add(value);
        save(configOption, valList);

        JSONObject result = configOption.toJSON();
        OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
        response.setHeader(ProtocolConstants.HEADER_LOCATION, result.getString(ProtocolConstants.KEY_LOCATION));
        response.setStatus(HttpServletResponse.SC_CREATED);
        return true;
      } catch (IllegalArgumentException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), e));
      } finally {
        if (db != null) {
          db.close();
        }
      }
View Full Code Here

    if (p.segment(1).equals(Clone.RESOURCE) && p.segment(2).equals("file")) { //$NON-NLS-1$
      // expected path /gitapi/config/{key}/clone/file/{path}
      File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
      if (gitDir == null)
        return statusHandler.handleRequest(request, response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No repository found under {0}", p.removeFirstSegments(2)),
                null));
      Repository db = null;
      URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.CONFIG_OPTION);
      try {
        db = FileRepositoryBuilder.create(gitDir);
        ConfigOption configOption = new ConfigOption(cloneLocation, db, p.segment(0));

        JSONObject toPut = OrionServlet.readJSONRequest(request);
        JSONArray value = toPut.optJSONArray(GitConstants.KEY_CONFIG_ENTRY_VALUE);
        if (value == null || (value.length() == 1 && value.isNull(0)))
          return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
              "Config entry value must be provided", null));

        // PUT allows only to modify existing config entries
        if (!configOption.exists()) {
          response.setStatus(HttpServletResponse.SC_NOT_FOUND);
          return true;
        }

        ArrayList<String> valList = new ArrayList<String>();
        for (int i = 0; i < value.length(); i++) {
          valList.add(value.getString(i));
        }

        save(configOption, valList);

        JSONObject result = configOption.toJSON();
        OrionServlet.writeJSONResponse(request, response, result);
        response.setHeader(ProtocolConstants.HEADER_LOCATION, result.getString(ProtocolConstants.KEY_LOCATION));
        return true;
      } catch (IllegalArgumentException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), e));
      } finally {
        if (db != null) {
          db.close();
        }
      }
View Full Code Here

    if (p.segment(1).equals(Clone.RESOURCE) && p.segment(2).equals("file")) { //$NON-NLS-1$
      // expected path /gitapi/config/{key}/clone/file/{path}
      File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
      if (gitDir == null)
        return statusHandler.handleRequest(request, response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No repository found under {0}", p.removeFirstSegments(2)),
                null));
      Repository db = null;
      URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.CONFIG_OPTION);
      try {
        db = FileRepositoryBuilder.create(gitDir);
        ConfigOption configOption = new ConfigOption(cloneLocation, db, GitUtils.decode(p.segment(0)));
        if (configOption.exists()) {
          String query = request.getParameter("index"); //$NON-NLS-1$
          if (query != null) {
            List<String> existing = new ArrayList<String>(Arrays.asList(configOption.getValue()));
            existing.remove(Integer.parseInt(query));
            save(configOption, existing);
          } else {
            delete(configOption);
          }
          response.setStatus(HttpServletResponse.SC_OK);
        } else {
          response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
        return true;
      } catch (IllegalArgumentException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), e));
      } finally {
        if (db != null) {
          db.close();
        }
      }
View Full Code Here

        URI crashedInstancesURI = targetURI.resolve(crashedInstancesUrl);

        GetMethod getCrashedInstancesMethod = new GetMethod(crashedInstancesURI.toString());
        HttpUtil.configureHttpMethod(getCrashedInstancesMethod, target);

        ServerStatus getStatus = HttpUtil.executeMethod(getCrashedInstancesMethod);
        if (!getStatus.isOK()) {
          return getStatus;
        }

        String response = getStatus.getJsonData().getString("response");
        JSONArray crashedInstances = new JSONArray(response);
        if (crashedInstances.length() > 0) {
          JSONObject crashedInstance = crashedInstances.getJSONObject(crashedInstances.length() - 1);
          computedInstanceNo = crashedInstance.getString("instance");
        }
      }

      String instanceLogsAppUrl = appUrl + "/instances/" + computedInstanceNo + "/files/logs";
      if (logName != null) {
        instanceLogsAppUrl += ("/" + logName);
      }

      URI instanceLogsAppURI = targetURI.resolve(instanceLogsAppUrl);

      GetMethod getInstanceLogMethod = new GetMethod(instanceLogsAppURI.toString());
      HttpUtil.configureHttpMethod(getInstanceLogMethod, target);

      ServerStatus getInstanceLogStatus = HttpUtil.executeMethod(getInstanceLogMethod);
      if (!getInstanceLogStatus.isOK()) {
        return getInstanceLogStatus;
      }

      String response = getInstanceLogStatus.getJsonData().optString("response");

      JSONObject jsonResp = new JSONObject();
      Log log = new Log(appName, logName);
      log.setContents(response);
      log.setLocation(new URI(baseRequestLocation));
      jsonResp.put(instanceNo, log.toJSON());

      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, jsonResp);
    } 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

    try {

      /* stop the application */
      StopAppCommand stopApp = new StopAppCommand(target, application);
      ServerStatus jobStatus = (ServerStatus) stopApp.doIt();
      status.add(jobStatus);
      if (!jobStatus.isOK())
        return status;

      /* start again */
      StartAppCommand startApp = new StartAppCommand(target, application);
      jobStatus = (ServerStatus) startApp.doIt();
      status.add(jobStatus);
      if (!jobStatus.isOK())
        return status;

      return status;

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

      GetMethod findRouteMethod = new GetMethod(routesURI.toString());
      HttpUtil.configureHttpMethod(findRouteMethod, target);
      findRouteMethod.setQueryString("inline-relations-depth=1&q=host:" + appHost + ";domain_guid:" + domainGUID); //$NON-NLS-1$ //$NON-NLS-2$

      ServerStatus status = HttpUtil.executeMethod(findRouteMethod);
      if (!status.isOK())
        return status;

      JSONObject response = status.getJsonData();
      if (response.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1)
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Route not found", null);

      /* retrieve the GUID */
      JSONArray resources = response.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);
      JSONObject route = resources.getJSONObject(0);

      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, route);

    } 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

      appHost = (hostNode != null) ? hostNode.getValue() : ManifestUtils.slugify(appName);

      if (appHost != null)
        return Status.OK_STATUS;

      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Route not found", null);

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

    String pathInfo = req.getPathInfo();
    IPath path = pathInfo == null ? Path.ROOT : new Path(pathInfo);

    // prevent path canonicalization hacks
    if (pathInfo != null && !pathInfo.equals(path.toString())) {
      handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, NLS.bind("Forbidden: {0}", pathInfo), null));
      return;
    }
    //don't allow anyone to mess with metadata
    if (path.segmentCount() > 0 && ".metadata".equals(path.segment(0))) { //$NON-NLS-1$
      handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, NLS.bind("Forbidden: {0}", pathInfo), null));
      return;
    }
    IFileStore file = getFileStore(req, path);
    IFileStore testLink = file;
    while (testLink != null) {
      IFileInfo info = testLink.fetchInfo();
      if (info.getAttribute(EFS.ATTRIBUTE_SYMLINK)) {
        if (file == testLink) {
          handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, NLS.bind("Forbidden: {0}", EncodingUtils.encodeForHTML(pathInfo.toString())), null));
        } else {
          handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("File not found: {0}", EncodingUtils.encodeForHTML(pathInfo.toString())), null));
        }
        return;
      }
      testLink = testLink.getParent();
    }

    if (file == null) {
      handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("File not found: {0}", EncodingUtils.encodeForHTML(pathInfo.toString())), null));
      return;
    }
    if (fileSerializer.handleRequest(req, resp, file))
      return;
    // finally invoke super to return an error for requests we don't know how to handle
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.