Package com.google.api.client.http

Examples of com.google.api.client.http.HttpResponse


    } else {
      //Obviously the null content (proved) is not accecptable to Douban's API. Therefore, this empty obj is added for fooling Douban around, they don't care what's inside it anyway.
      content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, new DoubanUserObj());
    }
    HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
    HttpResponse response = httpRequest(method, needAccessToken);
    return response.getStatusCode();
  }
View Full Code Here


          throw ErrorHandler.accessTokenNotSet();
        }
        HttpHeaders headers = method.getHeaders();
        headers.setAuthorization("Bearer " + this.accessToken);
      }
      HttpResponse res = method.execute();
      return res;
    } catch (HttpResponseException ex) {
      throw ErrorHandler.handleHttpResponseError(ex);
    }
  }
View Full Code Here

    }

    HttpRequest request;
    try {
      request = netHttpTransport.createRequestFactory().buildGetRequest(new GenericUrl(uri));
      HttpResponse response = request.execute();
      if (response.getStatusCode() != HttpStatusCodes.STATUS_CODE_OK) {
        throw new RuntimeException("Invalid request: " + uri);
      }

      InputStream inputStream = response.getContent();
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      int count;
      byte[] buffer = new byte[8192];
      while ((count = inputStream.read(buffer)) > 0) {
        bos.write(buffer, 0, count);
      }
      bos.close();
     
      final HttpHeaders headers = response.getHeaders();
      final String lastModified = headers.getLastModified();
      final Long size = headers.getContentLength() == null ? 0 : headers.getContentLength();
      final Date date = lastModified == null ? new Date(0) : dateFormat.get().parse(lastModified);

View Full Code Here

    HttpRequest request;
    try {
      destination.getParentFile().mkdirs();
      request = netHttpTransport.createRequestFactory().buildGetRequest(new GenericUrl(uri));
      HttpResponse response = request.execute();
      if (response.getStatusCode() != HttpStatusCodes.STATUS_CODE_OK) {
        throw new RuntimeException("Invalid request: " + uri);
      }
      final HttpHeaders headers = response.getHeaders();
      final String lastModified = headers.getLastModified();
      final Long size = headers.getContentLength() == null ? 0 : headers.getContentLength();
      final Date date = lastModified == null ? new Date(0) : dateFormat.get().parse(lastModified);
     
      if (!overwrite && destination.exists() && destination.lastModified() >= date.getTime() && destination.length() == size) {
        logger.info("File on disk is same or newer : " + destination);
        return;
      }

      InputStream inputStream = response.getContent();
      ReadableByteChannel rbc = Channels.newChannel(inputStream);
      FileOutputStream fos = new FileOutputStream(destination);
      fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
      fos.close();
     
View Full Code Here

      for (final String assertingRequest : assertingRequests) {

         String requestUrl = String.format("%s%s", STUBS_URL, assertingRequest);
         HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
         HttpResponse response = request.execute();
         String responseContent = response.parseAsString().trim();

         assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
         assertThat("{\"status\": \"ASN found!\"}").isEqualTo(responseContent);
      }
   }
View Full Code Here

      for (final String assertingRequest : assertingRequests) {

         String requestUrl = String.format("%s%s", STUBS_URL, assertingRequest);
         HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
         HttpResponse response = request.execute();
         String responseContent = response.parseAsString().trim();

         assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
         assertThat("{\"status\": \"The regex works!\"}").isEqualTo(responseContent);
      }
   }
View Full Code Here

      for (final String assertingRequest : assertingRequests) {

         String requestUrl = String.format("%s%s", STUBS_URL, assertingRequest);
         HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
         HttpResponse response = request.execute();
         String responseContent = response.parseAsString().trim();

         assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
         assertThat("{\"status\": \"The regex works!\"}").isEqualTo(responseContent);
      }
   }
View Full Code Here

      for (final String assertingRequest : assertingRequests) {

         String requestUrl = String.format("%s%s", STUBS_URL, assertingRequest);
         HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
         HttpResponse response = request.execute();
         String responseContent = response.parseAsString().trim();

         final String errorMessage = String.format("(404) Nothing found for GET request at URI %s", assertingRequest);
         assertThat(responseContent).contains(errorMessage);
         assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
      }
   }
View Full Code Here

   @Test
   public void should_MakeSuccessfulRequest_WhenQueryParamsAreAnArrayWithEscapedSingleQuoteElements() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/entity.find.single.quote?type_name=user&client_id=id&client_secret=secret&attributes=[%27id%27,%27uuid%27,%27created%27,%27lastUpdated%27,%27displayName%27,%27email%27,%27givenName%27,%27familyName%27]");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpResponse response = request.execute();
      final String responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat("{\"status\": \"hello world with single quote\"}").isEqualTo(responseContent);
   }
View Full Code Here

   @Test
   public void should_MakeSuccessfulRequest_WhenUrlAndQueryParamsAreRegexified() throws Exception {
      final String requestUrl = String.format("%s%s", STUBS_URL, "/feeds/paymentz?start-index=12&max-records=500");
      final HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

      final HttpResponse response = request.execute();
      final String responseContent = response.parseAsString().trim();

      assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
      assertThat("Got response").isEqualTo(responseContent);
   }
View Full Code Here

TOP

Related Classes of com.google.api.client.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.