Package co.cask.cdap.common.http

Examples of co.cask.cdap.common.http.HttpResponse


   * @throws IOException if a network error occurred
   * @throws BadRequestException if the provided stream ID was invalid
   */
  public void create(String newStreamId) throws IOException, BadRequestException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("streams/%s", newStreamId));
    HttpResponse response = restClient.execute(HttpMethod.PUT, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_BAD_REQUEST);
    if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException("Bad request: " + response.getResponseBodyAsString());
    }
  }
View Full Code Here


   * @throws IOException if a network error occurred
   * @throws StreamNotFoundException if the stream with the specified name was not found
   */
  public void truncate(String streamId) throws IOException, StreamNotFoundException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("streams/%s/truncate", streamId));
    HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new StreamNotFoundException(streamId);
    }
  }
View Full Code Here

  public void setTTL(String streamId, long ttlInSeconds) throws IOException, StreamNotFoundException,
    UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("streams/%s/config", streamId));
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(ImmutableMap.of("ttl", ttlInSeconds))).build();

    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new StreamNotFoundException(streamId);
    }
  }
View Full Code Here

   * @return list of {@link StreamRecord}s
   * @throws IOException if a network error occurred
   */
  public List<StreamRecord> list() throws IOException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL("streams");
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
    return ObjectResponse.fromJsonBody(response, new TypeToken<List<StreamRecord>>() { }).getResponseObject();
  }
View Full Code Here

   */
  private void writeEvent(URL url, String streamId, String event) throws IOException,
                                                                         StreamNotFoundException,
                                                                         UnAuthorizedAccessTokenException {
    HttpRequest request = HttpRequest.post(url).withBody(event).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new StreamNotFoundException(streamId);
    }
  }
View Full Code Here

   */
  public QueryHandle execute(String query) throws IOException, BadRequestException, UnAuthorizedAccessTokenException {
    URL url = config.resolveURL("data/explore/queries");
    HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(ImmutableMap.of("query", query))).build();

    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST);
    if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException("The query is not well-formed or contains an error, " +
                                      "such as a nonexistent table name: " + query);
    }

    return ObjectResponse.fromJsonBody(response, QueryHandle.class).getResponseObject();
View Full Code Here

   * @throws QueryNotFoundException if the query with the specified handle was not found
   */
  public QueryStatus getStatus(QueryHandle queryHandle) throws IOException, QueryNotFoundException,
    UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("data/explore/queries/%s/status", queryHandle.getHandle()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new QueryNotFoundException(queryHandle.getHandle());
    }

    return ObjectResponse.fromJsonBody(response, QueryStatus.class).getResponseObject();
  }
View Full Code Here

   */
  public List<ColumnDesc> getSchema(QueryHandle queryHandle)
    throws IOException, QueryNotFoundException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("data/explore/queries/%s/schema", queryHandle.getHandle()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new QueryNotFoundException(queryHandle.getHandle());
    }

    return ObjectResponse.fromJsonBody(response, new TypeToken<List<ColumnDesc>>() { })
      .getResponseObject();
View Full Code Here

    throws IOException, QueryNotFoundException, UnAuthorizedAccessTokenException {

    URL url = config.resolveURL(String.format("data/explore/queries/%s/next", queryHandle.getHandle()));
    HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(ImmutableMap.of("size", batchSize))).build();

    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new QueryNotFoundException(queryHandle.getHandle());
    }

    return ObjectResponse.fromJsonBody(response, new TypeToken<List<QueryResult>>() { }).getResponseObject();
  }
View Full Code Here

   * @throws BadRequestException if the query could not be deleted at the moment
   */
  public void delete(QueryHandle queryHandle) throws IOException, QueryNotFoundException, BadRequestException,
    UnAuthorizedAccessTokenException {
    URL url = config.resolveURL(String.format("data/explore/queries/%s", queryHandle.getHandle()));
    HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(),
                                               HttpURLConnection.HTTP_NOT_FOUND,
                                               HttpURLConnection.HTTP_BAD_REQUEST);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new QueryNotFoundException(queryHandle.getHandle());
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
      throw new BadRequestException("The query '" + queryHandle + "' was not in a state that could be closed;" +
                                      " either wait until it is finished, or cancel it");
    }
  }
View Full Code Here

TOP

Related Classes of co.cask.cdap.common.http.HttpResponse

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.