コード例 #1
0
  public IResponse handleGet(String[] queryPath, Properties params) {
    IResponse response;
    if (queryPath.length == 0) {
      response = listBundles();
    } else if (queryPath.length == 1) {
      try {
        Bundle bundle = findBundle(queryPath[0]);
        Properties props = createBundleProperties(bundle);

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        props.store(buffer, null);

        response =
            new DefaultResponse(IResponse.HTTP_OK, IResponse.MIME_PLAINTEXT, buffer.toString());
      } catch (NumberFormatException e) {
        response = DefaultResponse.createBadRequestError(e.getMessage());
      } catch (IllegalArgumentException e) {
        response =
            new DefaultResponse(
                IResponse.HTTP_NOTFOUND, IResponse.MIME_PLAINTEXT, "No such bundle");
      } catch (IOException e) {
        response = DefaultResponse.createInternalError(e);
      }
    } else {
      response =
          new DefaultResponse(
              IResponse.HTTP_NOTIMPLEMENTED, IResponse.MIME_PLAINTEXT, "Not implemented.");
    }
    return response;
  }
コード例 #2
0
  public IResponse handlePost(
      String[] queryPath, Properties params, Properties uploads, InputStream content) {
    IResponse response;
    if (queryPath.length == 0) {
      try {
        String startProp = params.getProperty("start");
        boolean start = "true".equals(startProp) || "on".equals(startProp);

        List errors = installBundles(uploads, start);
        if (errors.isEmpty()) response = listBundles();
        else response = listErrors(IResponse.HTTP_INTERNALERROR, errors);
      } catch (IllegalArgumentException e) {
        response =
            new DefaultResponse(
                IResponse.HTTP_BADREQUEST, IResponse.MIME_PLAINTEXT, e.getMessage());
      }
    } else {
      try {
        Bundle bundle = findBundle(queryPath[0]);
        if (queryPath.length == 1 && uploads != null && !uploads.isEmpty()) {
          updateBundle(bundle, uploads);
        } else if (queryPath.length == 2 && "start".equals(queryPath[1])) {
          bundle.start();
        } else if (queryPath.length == 2 && "stop".equals(queryPath[1])) {
          bundle.stop();
        } else if (queryPath.length == 2 && "update".equals(queryPath[1])) {
          bundle.update();
        }
        response = listBundles();
      } catch (NumberFormatException e) {
        response =
            new DefaultResponse(
                IResponse.HTTP_BADREQUEST, IResponse.MIME_PLAINTEXT, e.getMessage());
      } catch (FileNotFoundException e) {
        response = DefaultResponse.createInternalError(e);
      } catch (BundleException e) {
        response = DefaultResponse.createInternalError(e);
      } catch (IllegalArgumentException e) {
        response = DefaultResponse.createBadRequestError(e.getMessage());
      }
    }

    return response;
  }
コード例 #3
0
  public IResponse handlePut(
      String[] queryPath, Properties params, Properties uploads, InputStream content) {
    IResponse response;

    if (queryPath.length == 0) {
      response =
          new DefaultResponse(
              IResponse.HTTP_BADREQUEST, IResponse.MIME_PLAINTEXT, "Invalid request");
    } else {
      try {
        Bundle bundle = findBundle(queryPath[0]);
        try {
          if (queryPath.length == 1 && content != null) {
            // Update from supplied content
            bundle.update(content);
            response = listBundles();
          } else if (queryPath.length == 2 && "update".equals(queryPath[1])) {
            // Update from persistent location
            bundle.update();
            response = listBundles();
          } else if (queryPath.length == 2 && "start".equals(queryPath[1])) {
            bundle.start();
            response = listBundles();
          } else if (queryPath.length == 2 && "stop".equals(queryPath[1])) {
            bundle.stop();
            response = listBundles();
          } else {
            response =
                new DefaultResponse(
                    IResponse.HTTP_BADREQUEST, IResponse.MIME_PLAINTEXT, "Invalid request");
          }
        } catch (BundleException e) {
          response = DefaultResponse.createInternalError(e);
          response =
              new DefaultResponse(
                  IResponse.HTTP_INTERNALERROR, IResponse.MIME_PLAINTEXT, e.getMessage());
        }
      } catch (NumberFormatException e) {
        response =
            new DefaultResponse(
                IResponse.HTTP_BADREQUEST, IResponse.MIME_PLAINTEXT, e.getMessage());
      } catch (IllegalArgumentException e) {
        response =
            new DefaultResponse(
                IResponse.HTTP_NOTFOUND,
                IResponse.MIME_PLAINTEXT,
                "No such bundle " + queryPath[0]);
      }
    }

    return response;
  }