Exemplo n.º 1
0
  @Ignore
  @Test
  public void test005_uploadUsingOutputStream() throws IOException {
    System.out.println("--- --- --- test005_uploadUsingOutputStream() --- --- ---");

    File localFile1 = new File("/Users/yayang/Downloads/test_source2/log_01.txt");
    File localFile2 = new File("/Users/yayang/Downloads/test_source2/xsd-sourcedoc-2.10.0.zip");

    FileRef fileRef1 = FileRef.newInstance(fs, "/log_01.txt");
    FileRef fileRef2 = FileRef.newInstance(fs, "/xsd-sourcedoc-2.10.0.zip");

    OutputStream output1 = null;
    try {
      output1 = new FileRefOutputStream(fileRef1);
      FileUtil.copyFileToOutputStream(localFile1, output1);
      System.out.println(
          "Local file '"
              + localFile1.getAbsolutePath()
              + "' is uploaded to path '"
              + fileRef1.getPath()
              + "'? "
              + fileRef1.exists());

    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.closeQuietly(output1, true);
    }

    FileRefOutputStream output2 = null;
    try {
      output2 = new FileRefOutputStream(fileRef2);
      FileUtil.copyFileToOutputStream(localFile2, output2);
      System.out.println(
          "Local file '"
              + localFile2.getAbsolutePath()
              + "' is uploaded to path '"
              + fileRef2.getPath()
              + "'? "
              + fileRef2.exists());

    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.closeQuietly(output2, true);
    }

    System.out.println();
  }
Exemplo n.º 2
0
  /**
   * Get apps.
   *
   * <p>URL (GET):
   * {scheme}://{host}:{port}/{contextRoot}/appstore/apps?namespace={namespace}&categoryid={categoryid}
   *
   * @param namespace
   * @param categoryId
   * @return
   * @throws ClientException
   */
  public List<AppManifestDTO> getApps(String namespace, String categoryId) throws ClientException {
    List<AppManifestDTO> apps = null;
    Response response = null;
    try {
      WebTarget target = getRootPath().path("appstore/apps");
      if (categoryId != null) {
        target.queryParam("namespace", namespace);
      }
      if (categoryId != null) {
        target.queryParam("categoryId", categoryId);
      }
      Builder builder = target.request(MediaType.APPLICATION_JSON);
      response = updateHeaders(builder).get();
      checkResponse(response);

      apps = response.readEntity(new GenericType<List<AppManifestDTO>>() {});
    } catch (ClientException e) {
      handleException(e);
    } finally {
      IOUtil.closeQuietly(response, true);
    }
    if (apps == null) {
      apps = Collections.emptyList();
    }
    return apps;
  }
Exemplo n.º 3
0
  /**
   * Get an app.
   *
   * <p>URL (GET): {scheme}://{host}:{port}/{contextRoot}/appstore/apps/{appid}
   *
   * @param appId
   * @return
   * @throws ClientException
   */
  public boolean appExists(String appId) throws ClientException {
    Response response = null;
    try {
      Builder builder =
          getRootPath()
              .path("appstore/apps")
              .path(appId)
              .path("exists")
              .request(MediaType.APPLICATION_JSON);
      response = updateHeaders(builder).get();
      checkResponse(response);

      String responseString = response.readEntity(String.class);

      ObjectMapper mapper = createObjectMapper(false);
      Map<?, ?> result = mapper.readValue(responseString, Map.class);
      if (result != null && result.containsKey("exists")) { // $NON-NLS-1$
        Object value = result.get("exists"); // $NON-NLS-1$
        if (value instanceof Boolean) {
          return (boolean) value;
        }
      }

    } catch (ClientException | IOException e) {
      handleException(e);
    } finally {
      IOUtil.closeQuietly(response, true);
    }
    return false;
  }
Exemplo n.º 4
0
  /**
   * Download app file.
   *
   * <p>URL (GET): {scheme}://{host}:{port}/{contextRoot}/appstore/apps/{appid}/content
   *
   * @param appId
   * @param output
   * @return
   * @throws ClientException
   */
  public boolean downloadApp(String appId, OutputStream output) throws ClientException {
    InputStream input = null;
    try {
      WebTarget target = getRootPath().path("appstore/apps").path(appId).path("content");
      Builder builder =
          target.request(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM);
      Response response = updateHeaders(builder).get();
      checkResponse(response);

      input = response.readEntity(InputStream.class);

      if (input != null) {
        IOUtil.copy(input, output);
      }
    } catch (ClientException | IOException e) {
      handleException(e);
    } finally {
      IOUtil.closeQuietly(input, true);
    }
    return true;
  }
Exemplo n.º 5
0
  /**
   * Delete an app.
   *
   * <p>URL (DEL): {scheme}://{host}:{port}/{contextRoot}/appstore/apps/{appid}
   *
   * @param appId
   * @return
   * @throws ClientException
   */
  public StatusDTO deleteApp(String appId) throws ClientException {
    StatusDTO status = null;
    Response response = null;
    try {
      Builder builder =
          getRootPath().path("appstore/apps").path(appId).request(MediaType.APPLICATION_JSON);
      response = updateHeaders(builder).delete();
      checkResponse(response);

      status = response.readEntity(StatusDTO.class);
    } catch (ClientException e) {
      handleException(e);
    } finally {
      IOUtil.closeQuietly(response, true);
    }
    return status;
  }
Exemplo n.º 6
0
  /**
   * Get an app.
   *
   * <p>URL (GET): {scheme}://{host}:{port}/{contextRoot}/appstore/apps/{appid}
   *
   * @param appId
   * @return
   * @throws ClientException
   */
  public AppManifestDTO getApp(String appId) throws ClientException {
    AppManifestDTO app = null;
    Response response = null;
    try {
      Builder builder =
          getRootPath().path("appstore/apps").path(appId).request(MediaType.APPLICATION_JSON);
      response = updateHeaders(builder).get();
      checkResponse(response);

      app = response.readEntity(AppManifestDTO.class);
    } catch (ClientException e) {
      handleException(e);
    } finally {
      IOUtil.closeQuietly(response, true);
    }
    return app;
  }
Exemplo n.º 7
0
  /**
   * Update an app.
   *
   * <p>URL (PUT): {scheme}://{host}:{port}/{contextRoot}/appstore/apps (Body parameter:
   * AppManifestDTO)
   *
   * @param updateAppRequestDTO Body parameter for updating the app.
   * @return Update status
   * @throws ClientException
   */
  public StatusDTO updateApp(AppManifestDTO updateAppRequestDTO) throws ClientException {
    StatusDTO status = null;
    Response response = null;
    try {
      Builder builder = getRootPath().path("apps").request(MediaType.APPLICATION_JSON);
      response =
          updateHeaders(builder)
              .put(Entity.json(new GenericEntity<AppManifestDTO>(updateAppRequestDTO) {}));
      checkResponse(response);

      status = response.readEntity(StatusDTO.class);
    } catch (ClientException e) {
      handleException(e);
    } finally {
      IOUtil.closeQuietly(response, true);
    }
    return status;
  }
Exemplo n.º 8
0
  /**
   * Get apps.
   *
   * <p>URL (PST): {scheme}://{host}:{port}/{contextRoot}/appstore/apps/query (Body parameter:
   * AppQueryDTO)
   *
   * @param queryDTO
   * @return
   * @throws ClientException
   */
  public List<AppManifestDTO> getApps(AppQueryDTO queryDTO) throws ClientException {
    List<AppManifestDTO> apps = null;
    Response response = null;
    try {
      Builder builder =
          getRootPath().path("appstore/apps/query").request(MediaType.APPLICATION_JSON);
      response =
          updateHeaders(builder).post(Entity.json(new GenericEntity<AppQueryDTO>(queryDTO) {}));
      checkResponse(response);

      apps = response.readEntity(new GenericType<List<AppManifestDTO>>() {});

    } catch (ClientException e) {
      handleException(e);
    } finally {
      IOUtil.closeQuietly(response, true);
    }
    if (apps == null) {
      apps = Collections.emptyList();
    }
    return apps;
  }
Exemplo n.º 9
0
  @Ignore
  @Test
  public void test009_downloadUsingInputStream() throws IOException {
    System.out.println("--- --- --- test009_downloadUsingInputStream() --- --- ---");

    File localDir = new File("/Users/yayang/Downloads/test_target2/");
    File localFile1 = new File(localDir, "invoke.timeout(B).zip");
    File localFile2 = new File(localDir, "japanese_issue(B).zip");
    File localFile3 = new File(localDir, "log_01(B).txt");
    File localFile4 = new File(localDir, "xsd-sourcedoc-2.10.0(B).zip");

    FileRef fileRef1 = FileRef.newInstance(fs, "/invoke.timeout.zip");
    FileRef fileRef2 = FileRef.newInstance(fs, "/japanese_issue.zip");
    FileRef fileRef3 = FileRef.newInstance(fs, "/log_01.txt");
    FileRef fileRef4 = FileRef.newInstance(fs, "/xsd-sourcedoc-2.10.0.zip");

    InputStream input1 = null;
    try {
      input1 = new FileRefInputStream(fileRef1);
      FileUtil.copyInputStreamToFile(input1, localFile1);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.closeQuietly(input1, true);
    }

    InputStream input2 = null;
    try {
      input2 = new FileRefInputStream(fileRef2);
      FileUtil.copyInputStreamToFile(input2, localFile2);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.closeQuietly(input2, true);
    }

    InputStream input3 = null;
    try {
      input3 = new FileRefInputStream(fileRef3);
      FileUtil.copyInputStreamToFile(input3, localFile3);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.closeQuietly(input3, true);
    }

    InputStream input4 = null;
    try {
      input4 = new FileRefInputStream(fileRef4);
      FileUtil.copyInputStreamToFile(input4, localFile4);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      IOUtil.closeQuietly(input4, true);
    }

    System.out.println(
        "Path '"
            + fileRef1.getPath()
            + " is downloaded to '"
            + localFile1.getAbsolutePath()
            + "'? "
            + localFile1.exists());
    System.out.println(
        "Path '"
            + fileRef2.getPath()
            + " is downloaded to '"
            + localFile2.getAbsolutePath()
            + "'? "
            + localFile2.exists());
    System.out.println(
        "Path '"
            + fileRef3.getPath()
            + " is downloaded to '"
            + localFile3.getAbsolutePath()
            + "'? "
            + localFile3.exists());
    System.out.println(
        "Path '"
            + fileRef4.getPath()
            + " is downloaded to '"
            + localFile4.getAbsolutePath()
            + "'? "
            + localFile4.exists());

    System.out.println();
  }