private ServerStatus getSpaces(List<Space> spaces, JSONObject orgJSON) throws Exception {
    URI targetURI = URIUtil.toURI(target.getUrl());
    URI spaceURI = targetURI.resolve(orgJSON.getJSONObject("entity").getString("spaces_url"));

    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));
    }

    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
  }
  @Override
  protected ServerStatus _doIt() {
    try {
      /* get available orgs */
      URI targetURI = URIUtil.toURI(target.getUrl());
      URI orgsURI = targetURI.resolve("/v2/organizations");

      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.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
        return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, 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 (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);
    }
  }
  @Override
  protected ServerStatus _doIt() {
    try {

      /* unmap route from application */
      URI targetURI = URIUtil.toURI(target.getUrl());
      DeleteMethod unmapRouteMethod =
          new DeleteMethod(
              targetURI
                  .resolve("/v2/apps/" + app.getGuid() + "/routes/" + route.getGuid())
                  .toString()); //$NON-NLS-1$//$NON-NLS-2$
      ServerStatus confStatus = HttpUtil.configureHttpMethod(unmapRouteMethod, target.getCloud());
      if (!confStatus.isOK()) return confStatus;

      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);
    }
  }
  @Override
  protected ServerStatus _doIt() {
    MultiServerStatus status = new MultiServerStatus();

    try {
      URI targetURI = URIUtil.toURI(target.getUrl());

      // get app details
      // TODO: it should be passed along with App object
      String appsUrl =
          target
              .getSpace()
              .getCFJSON()
              .getJSONObject("entity")
              .getString("apps_url"); // $NON-NLS-1$//$NON-NLS-2$
      URI appsURI = targetURI.resolve(appsUrl);
      GetMethod getAppsMethod = new GetMethod(appsURI.toString());
      ServerStatus confStatus = HttpUtil.configureHttpMethod(getAppsMethod, target.getCloud());
      if (!confStatus.isOK()) return confStatus;

      getAppsMethod.setQueryString(
          "q=name:" + appName + "&inline-relations-depth=1"); // $NON-NLS-1$ //$NON-NLS-2$

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

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

      // get app routes
      String routesUrl = apps.getJSONObject(0).getJSONObject("entity").getString("routes_url");
      URI routesURI = targetURI.resolve(routesUrl);
      GetMethod getRoutesMethod = new GetMethod(routesURI.toString());
      confStatus = HttpUtil.configureHttpMethod(getRoutesMethod, target.getCloud());
      if (!confStatus.isOK()) return confStatus;

      ServerStatus routesStatus = HttpUtil.executeMethod(getRoutesMethod);
      status.add(routesStatus);
      if (!status.isOK()) return status;

      jsonData = routesStatus.getJsonData();
      if (!jsonData.has("resources")
          || jsonData.getJSONArray("resources").length() == 0) // $NON-NLS-1$//$NON-NLS-2$
      return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, "No routes for the app", null);
      JSONArray routes = jsonData.getJSONArray("resources");

      for (int i = 0; i < routes.length(); ++i) {
        JSONObject route = routes.getJSONObject(i);

        // delete route
        String routeUrl =
            route
                .getJSONObject(CFProtocolConstants.V2_KEY_METADATA)
                .getString(CFProtocolConstants.V2_KEY_URL);
        URI routeURI = targetURI.resolve(routeUrl); // $NON-NLS-1$
        DeleteMethod deleteRouteMethod = new DeleteMethod(routeURI.toString());
        confStatus = HttpUtil.configureHttpMethod(deleteRouteMethod, target.getCloud());
        if (!confStatus.isOK()) return confStatus;

        ServerStatus deleteStatus = HttpUtil.executeMethod(deleteRouteMethod);
        status.add(deleteStatus);
        if (!status.isOK()) return status;
      }

      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);
    }
  }