Package org.eclipse.orion.server.core

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


          Tag tag = new Tag(cloneLocation, db, ref);
          OrionServlet.writeJSONResponse(request, response, tag.toJSON(), JsonURIUnqualificationStrategy.ALL_NO_GIT);
          return true;
        } else {
          String msg = NLS.bind("Tag not found: {0}", tagName);
          return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
        }
      } else {
        ListTagsJob job;
        String commits = request.getParameter(GitConstants.KEY_TAG_COMMITS);
        int commitsNumber = commits == null ? 0 : Integer.parseInt(commits);
        String nameFilter = request.getParameter("filter"); //$NON-NLS-1$
        String page = request.getParameter("page"); //$NON-NLS-1$
        if (page != null) {
          int pageNo = Integer.parseInt(page);
          int pageSize = request.getParameter("pageSize") == null ? PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize")); //$NON-NLS-1$ //$NON-NLS-2$
          job = new ListTagsJob(TaskJobHandler.getUserId(request), filePath, BaseToCloneConverter.getCloneLocation(getURI(request),
              BaseToCloneConverter.TAG_LIST), commitsNumber, pageNo, pageSize, request.getRequestURI(), nameFilter);
        } else {
          job = new ListTagsJob(TaskJobHandler.getUserId(request), filePath, BaseToCloneConverter.getCloneLocation(getURI(request),
              BaseToCloneConverter.TAG_LIST), commitsNumber, nameFilter);
        }
        return TaskJobHandler.handleTaskJob(request, response, job, statusHandler, JsonURIUnqualificationStrategy.ALL_NO_GIT);
      }
    } catch (Exception e) {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "An error occured when looking for a tag.", e));
    }
  }
View Full Code Here


      URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.TAG_LIST);
      Tag tag = new Tag(cloneLocation, db, ref);
      OrionServlet.writeJSONResponse(request, response, tag.toJSON(), JsonURIUnqualificationStrategy.ALL_NO_GIT);
      return true;
    } catch (Exception e) {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "An error occured when tagging.", e));
    } finally {
      walk.dispose();
    }
  }
View Full Code Here

    if (gitSegment != null) {
      try {
        git.tagDelete().setTags(gitSegment).call();
        return true;
      } catch (GitAPIException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "An error occured when removing a tag.", e));
      }
    } else {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
          "Tag deletion aborted: no tag name provided.", null));
    }
  }
View Full Code Here

        /* nothing to do */
        return status;

      /* get available domains */
      GetDomainsCommand getDomainsCommand = new GetDomainsCommand(target);
      ServerStatus jobStatus = (ServerStatus) getDomainsCommand.doIt(); /* FIXME: unsafe type cast */
      status.add(jobStatus);

      if (!jobStatus.isOK())
        return status;

      List<Domain> domains = getDomainsCommand.getDomains();
      if (domains == null || domains.size() == 0) {
        status.add(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Failed to find available domains in target", null));
        return status;
      }

      if (!appDomain.isEmpty()) {
        /* look if the domain is available */
        for (Iterator<Domain> iterator = domains.iterator(); iterator.hasNext();) {
          Domain domain = iterator.next();
          if (appDomain.equals(domain.getDomainName())) {
            this.domain = domain;
            break;
          }
        }

        /* client requested an unavailable domain, fail */
        if (domain == null) {
          String msg = NLS.bind("Failed to find domain {0} in target", appDomain);
          status.add(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
          return status;
        }
      } else {
        /* client has not requested a specific domain, get the first available */
        this.domain = domains.get(0);
      }

      /* find out whether the declared host can be reused */
      String routeGUID = null;
      FindRouteCommand findRouteCommand = new FindRouteCommand(target, getApplication(), domain.getGuid());
      jobStatus = (ServerStatus) findRouteCommand.doIt(); /* FIXME: unsafe type cast */
      status.add(jobStatus);

      if (jobStatus.isOK()) {
        /* extract route guid */
        route = jobStatus.getJsonData();
        routeGUID = route.getJSONObject(CFProtocolConstants.V2_KEY_METADATA).getString(CFProtocolConstants.V2_KEY_GUID);

        /* attach route to application */
        AttachRouteCommand attachRoute = new AttachRouteCommand(target, getApplication(), routeGUID);
        jobStatus = (ServerStatus) attachRoute.doIt(); /* FIXME: unsafe type cast */
        status.add(jobStatus);

        if (jobStatus.isOK())
          return status;

        /* the route is bound to another space */
        String msg = NLS.bind("The host {0} is already used in another space.", findRouteCommand.getAppHost());
        status.add(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_CONFLICT, msg, null));
        return status;
      }

      /* create a new route */
      CreateRouteCommand createRoute = new CreateRouteCommand(target, domain, getApplication());
      jobStatus = (ServerStatus) createRoute.doIt(); /* FIXME: unsafe type cast */
      status.add(jobStatus);

      if (!jobStatus.isOK())
        return status;

      /* extract route guid */
      route = jobStatus.getJsonData();
      routeGUID = route.getJSONObject(CFProtocolConstants.V2_KEY_METADATA).getString(CFProtocolConstants.V2_KEY_GUID);

      /* attach route to application */
      AttachRouteCommand attachRoute = new AttachRouteCommand(target, getApplication(), routeGUID);
      jobStatus = (ServerStatus) attachRoute.doIt(); /* FIXME: unsafe type cast */
      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

      noRoute = (noRouteNode != null) ? Boolean.parseBoolean(noRouteNode.getValue()) : false;

      return Status.OK_STATUS;

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

      for (String configN : configNames) {
        if (configN.equals(configName)) {
          Remote remote = new Remote(cloneLocation, db, configN);
          JSONObject result = remote.toJSON();
          if (!result.has(ProtocolConstants.KEY_CHILDREN)) {
            return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
          }
          JSONArray children = result.getJSONArray(ProtocolConstants.KEY_CHILDREN);
          JSONArray filteredChildren = new JSONArray();
          if (children.length() == 0 || (commitsSize == 0 && pageSize < 0)) {
            if (nameFilter != null && !nameFilter.equals("")) {
              for (int i = 0; i < children.length(); i++) {
                JSONObject test = (JSONObject) children.get(i);
                String name = (String) test.get("Name");
                if (name.toLowerCase().contains(nameFilter.toLowerCase())) {
                  filteredChildren.put(test);
                }
              }
              result.put(ProtocolConstants.KEY_CHILDREN, filteredChildren);
            }
            return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
          }

          int firstChild = pageSize > 0 ? pageSize * (pageNo - 1) : 0;
          int lastChild = pageSize > 0 ? firstChild + pageSize - 1 : children.length() - 1;
          lastChild = lastChild > children.length() - 1 ? children.length() - 1 : lastChild;
          if (pageNo > 1 && baseLocation != null) {
            String prev = baseLocation + "?page=" + (pageNo - 1) + "&pageSize=" + pageSize;
            if (commitsSize > 0) {
              prev += "&" + GitConstants.KEY_TAG_COMMITS + "=" + commitsSize;
            }
            result.put(ProtocolConstants.KEY_PREVIOUS_LOCATION, prev);
          }
          if (lastChild < children.length() - 1) {
            String next = baseLocation + "?page=" + (pageNo + 1) + "&pageSize=" + pageSize;
            if (commitsSize > 0) {
              next += "&" + GitConstants.KEY_TAG_COMMITS + "=" + commitsSize;
            }
            result.put(ProtocolConstants.KEY_NEXT_LOCATION, next);
          }

          JSONArray newChildren = new JSONArray();
          for (int i = firstChild; i <= lastChild; i++) {
            if (monitor.isCanceled()) {
              return new Status(IStatus.CANCEL, GitActivator.PI_GIT, "Cancelled");
            }
            JSONObject branch = children.getJSONObject(i);
            if (commitsSize == 0) {
              newChildren.put(branch);
            } else {
              LogCommand lc = git.log();
              String branchName = branch.getString(ProtocolConstants.KEY_ID);
              ObjectId toObjectId = db.resolve(branchName);
              Ref toRefId = db.getRef(branchName);
              if (toObjectId == null) {
                String msg = NLS.bind("No ref or commit found: {0}", branchName);
                return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null);
              }
              toObjectId = getCommitObjectId(db, toObjectId);

              // set the commit range
              lc.add(toObjectId);
              lc.setMaxCount(this.commitsSize);
              Iterable<RevCommit> commits = lc.call();
              Log log = new Log(cloneLocation, db, commits, null, null, toRefId);
              log.setPaging(1, commitsSize);
              branch.put(GitConstants.KEY_TAG_COMMIT, log.toJSON());
              newChildren.put(branch);
            }
          }

          result.put(ProtocolConstants.KEY_CHILDREN, newChildren);

          return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
        }
      }
      String msg = NLS.bind("Couldn't find remote : {0}", configName);
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null);
    } catch (Exception e) {
      String msg = NLS.bind("Couldn't get remote details : {0}", configName);
      return new Status(IStatus.ERROR, GitActivator.PI_GIT, msg, e);
    } finally {
      if (db != null) {
View Full Code Here

      GetMethod getDomainsMethod = new GetMethod(orgsURI.toString());
      HttpUtil.configureHttpMethod(getDomainsMethod, target);
      getDomainsMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

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

      /* extract available orgs */
      JSONObject orgs = status.getJsonData();

      if (orgs == null || orgs.optInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS, 0) < 1) {
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NO_CONTENT, "Server did not return any organizations.", null);
      }

      /* look if the domain is available */
      JSONObject result = new JSONObject();
      int resources = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).length();
      for (int k = 0; k < resources; ++k) {
        JSONObject orgJSON = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).getJSONObject(k);
        List<Space> spaces = new ArrayList<Space>();
        status = getSpaces(spaces, orgJSON);
        if (!status.isOK())
          return status;
        OrgWithSpaces orgWithSpaces = new OrgWithSpaces();
        orgWithSpaces.setCFJSON(orgJSON);
        orgWithSpaces.setSpaces(spaces);
        result.append("Orgs", orgWithSpaces.toJSON());
      }

      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
    } catch (ConnectTimeoutException e) {
      String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$
      logger.error(msg, e);
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_GATEWAY_TIMEOUT, msg, e);
    } catch (Exception e) {
      String msg = NLS.bind("An error occurred 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

    GetMethod getDomainsMethod = new GetMethod(spaceURI.toString());
    HttpUtil.configureHttpMethod(getDomainsMethod, target);
    getDomainsMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

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

    /* extract available spaces */
    JSONObject orgs = status.getJsonData();

    if (orgs.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
    }

    /* look if the domain is available */
    int resources = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).length();
    for (int k = 0; k < resources; ++k) {
      JSONObject spaceJSON = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).getJSONObject(k);
      spaces.add(new Space().setCFJSON(spaceJSON));
    }

    logger.debug("GetOrgsCommand: getting spaces using " + spaceURI + " took " + (System.currentTimeMillis() - time));

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

      //assume file does not exist
      fileInfo = new FileInfo(file.getName());
      ((FileInfo) fileInfo).setExists(false);
    }
    if (!request.getMethod().equals("PUT") && !fileInfo.exists()) //$NON-NLS-1$
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, 404, NLS.bind("File not found: {0}", EncodingUtils.encodeForHTML(request.getPathInfo())), null));
    if (fileInfo.isDirectory())
      return handleDirectory(request, response, file);
    return handleFile(request, response, file);
  }
View Full Code Here

      GetMethod getSpaceMethod = new GetMethod(spacesURI.toString());
      HttpUtil.configureHttpMethod(getSpaceMethod, getCloud());
      getSpaceMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

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

      space = new Space().setCFJSON(status.getJsonData());
      JSONObject result = space.toJSON();

      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
    } catch (ConnectTimeoutException e) {
      String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$
      logger.error(msg, e);
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_GATEWAY_TIMEOUT, msg, e);
    } catch (Exception e) {
      String msg = NLS.bind("An error occurred 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.