Package org.eclipse.orion.server.core

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


          }

          return new GetOrgsCommand(this.userId, target).doIt();
        } catch (Exception e) {
          String msg = NLS.bind("Failed to handle request for {0}", path); //$NON-NLS-1$
          ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
          logger.error(msg, e);
          return status;
        }
      }
    };
View Full Code Here


        GetMethod getServiceInstancesMethod = new GetMethod(serviceInstancesURI.toString());
        getServiceInstancesMethod.setQueryString(pa);
        HttpUtil.configureHttpMethod(getServiceInstancesMethod, target);

        /* send request */
        ServerStatus jobStatus = HttpUtil.executeMethod(getServiceInstancesMethod);
        status.add(jobStatus);
        if (!jobStatus.isOK())
          return status;

        JSONObject resp = jobStatus.getJsonData();
        if (resp.has(CFProtocolConstants.V2_KEY_NEXT_URL) && !resp.isNull(CFProtocolConstants.V2_KEY_NEXT_URL))
          serviceInstancesURI = targetURI.resolve(resp.getString(CFProtocolConstants.V2_KEY_NEXT_URL));
        else
          serviceInstancesURI = null;

        JSONArray resources = resp.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);
        for (int i = 0; i < resources.length(); ++i) {
          JSONObject serviceObj = resources.getJSONObject(i);

          JSONObject serviceInstanceEntity = serviceObj.getJSONObject(CFProtocolConstants.V2_KEY_ENTITY);
          JSONObject serviceEntity = serviceInstanceEntity.getJSONObject(CFProtocolConstants.V2_KEY_SERVICE_PLAN)//
              .getJSONObject(CFProtocolConstants.V2_KEY_ENTITY);

          String serviceGuid = serviceEntity.getString(CFProtocolConstants.V2_KEY_SERVICE_GUID);
          GetServiceCommand getServiceCommand = new GetServiceCommand(target, serviceGuid);

          /* get detailed info about the service */
          jobStatus = (ServerStatus) getServiceCommand.doIt(); /* FIXME: unsafe type cast */
          status.add(jobStatus);
          if (!jobStatus.isOK())
            return status;

          JSONObject serviceResp = jobStatus.getJsonData();
          boolean isBindable = serviceResp.getJSONObject(CFProtocolConstants.V2_KEY_ENTITY).getBoolean(CFProtocolConstants.V2_KEY_BINDABLE);

          if (isBindable) {
            Service s = new Service(serviceInstanceEntity.getString(CFProtocolConstants.V2_KEY_NAME));
            services.put(s.toJSON());
          }
        }

      } while (serviceInstancesURI != null);

      response.put(ProtocolConstants.KEY_CHILDREN, services);
      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, response);

    } 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

    try {
      int code = CFActivator.getDefault().getHttpClient().executeMethod(method);

      if (code == 204) {
        /* no content response */
        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
      }

      String response = method.getResponseBodyAsString();
      JSONObject result;

      try {
        result = new MagicJSONObject(response);
      } catch (JSONException e) {
        result = new JSONObject();
        result.put("response", response);
      }

      if (code != 200 && code != 201) {
        String desctiption = result.optString("description");
        if (desctiption == null || desctiption.length() == 0) {
          desctiption = result.optString("response", "Could not connect to host. Error: " + code);
          if (desctiption.length() > 1000) {
            desctiption = "Could not connect to host. Error: " + code;
          }
        }
        return new ServerStatus(Status.ERROR, code, desctiption, result, null);
      }

      if (result.has("error_code")) {
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, result.optString("description"), result, null);
      }

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

    } finally {
      /* ensure connections are released back to the connection manager */
      method.releaseConnection();
    }
 
View Full Code Here

      errorJSON.put(CFProtocolConstants.V2_KEY_ERROR_DESCRIPTION, description);
    } catch (JSONException e) {
      // do nothing
    }

    return new ServerStatus(severity, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, description, errorJSON, null);
  }
View Full Code Here

          CreateRouteCommand createRouteCommand = new CreateRouteCommand(target, getDomainsCommand.getDomains().get(0), hostName);
          IStatus createRouteStatus = createRouteCommand.doIt();
          if (!createRouteStatus.isOK())
            return createRouteStatus;

          return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, createRouteCommand.getRoute().toJSON());
        } catch (Exception e) {
          String msg = NLS.bind("Failed to handle request for {0}", path); //$NON-NLS-1$
          ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
          logger.error(msg, e);
          return status;
        }
      }
    };
View Full Code Here

          }

          return new GetRoutesCommand(target, false).doIt();
        } catch (Exception e) {
          String msg = NLS.bind("Failed to handle request for {0}", path); //$NON-NLS-1$
          ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
          logger.error(msg, e);
          return status;
        }
      }
    };
View Full Code Here

              return getRoutesStatus;
            routes = getRoutesCommand.getRoutes();
          }

          if (routes == null || routes.size() == 0)
            return new ServerStatus(IStatus.OK, HttpServletResponse.SC_NOT_FOUND, "Host not found", null);

          JSONArray deletedRoutesJSON = new JSONArray();
          for (Iterator<Route> iterator2 = routes.iterator(); iterator2.hasNext();) {
            Route route = iterator2.next();

            DeleteRouteCommand deleteRouteCommand = new DeleteRouteCommand(target, route);
            IStatus deleteRouteStatus = deleteRouteCommand.doIt();
            if (!deleteRouteStatus.isOK())
              return deleteRouteStatus;

            deletedRoutesJSON.put(route.toJSON());
          }

          JSONObject result = new JSONObject();
          result.put("Routes", deletedRoutesJSON);
          return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
        } catch (Exception e) {
          String msg = NLS.bind("Failed to handle request for {0}", pathString); //$NON-NLS-1$
          ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
          logger.error(msg, e);
          return status;
        }
      }
    };
View Full Code Here

      URI domainsURI = targetURI.resolve(domainsURL);

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

      /* extract available domains */
      JSONObject domainsJSON = getDomainStatus.getJsonData();

      if (domainsJSON.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
        return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
      }

      JSONObject result = new JSONObject();
      domains = new ArrayList<Domain>();
      JSONArray resources = domainsJSON.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);
      for (int k = 0; k < resources.length(); ++k) {
        JSONObject domainJSON = resources.getJSONObject(k);
        Domain domain = new Domain();
        domain.setCFJSON(domainJSON);
        if (domainName == null || domainName.equals(domain.getDomainName())) {
          domains.add(domain);
          result.append("Domains", domain.toJSON());
        }
      }

      if (domains.isEmpty())
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Domain can not be found", null);

      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);
    }
  }
View Full Code Here

   * @param object Object from which other properties will be drawn
   * @return The created SiteConfiguration.
   */
  public static SiteInfo createFromJSON(UserInfo user, String name, String workspace, JSONObject object) throws CoreException {
    if (name == null || name.length() == 0)
      throw new CoreException(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Name is missing", null));
    else if (workspace == null || name.length() == 0)
      throw new CoreException(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Workspace is missing", null));

    SiteInfo site = SiteInfo.newSiteConfiguration(user, name, workspace);
    copyProperties(object, site, false);
    site.save(user);
    return site;
View Full Code Here

    if (mappings != null)
      target.setMappings(mappings);

    // Sanity check
    if (target.getName() == null || target.getName().length() == 0)
      throw new CoreException(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Name was not specified", null));
    if (target.getWorkspace() == null || target.getWorkspace().length() == 0)
      throw new CoreException(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Workspace was not specified", null));
  }
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.