Package com.google.api.client.http

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


        .setPrincipal(serviceAccountUser);
    payload.put("scope", serviceAccountScopes);
    try {
      String assertion =
          RsaSHA256Signer.sign(serviceAccountPrivateKey, getJsonFactory(), header, payload);
      TokenRequest request = new TokenRequest(getTransport(), getJsonFactory(), new GenericUrl(
          getTokenServerEncodedUrl()), "assertion");
      request.put("assertion_type", "http://oauth.net/grant_type/jwt/1.0/bearer");
      request.put("assertion", assertion);
      return request.execute();
    } catch (GeneralSecurityException exception) {
View Full Code Here


      return response;
    }

    // Make initial request to get the unique upload URL.
    HttpResponse initialResponse = executeUploadInitiation(initiationRequestUrl);
    GenericUrl uploadUrl;
    try {
      uploadUrl = new GenericUrl(initialResponse.getHeaders().getLocation());
    } finally {
      initialResponse.disconnect();
    }

    // Convert media content into a byte stream to upload in chunks.
    contentInputStream = mediaContent.getInputStream();
    if (!contentInputStream.markSupported()) {
      contentInputStream = new BufferedInputStream(contentInputStream);
    }

    HttpResponse response;
    // Upload the media content in chunks.
    while (true) {
      currentRequest = requestFactory.buildPutRequest(uploadUrl, null);
      new MethodOverride().intercept(currentRequest); // needed for PUT
      setContentAndHeadersOnCurrentRequest(bytesUploaded);
      if (backOffPolicyEnabled) {
        // Set MediaExponentialBackOffPolicy as the BackOffPolicy of the HTTP Request which will
        // callback to this instance if there is a server error.
        currentRequest.setBackOffPolicy(new MediaUploadExponentialBackOffPolicy(this));
      }
      currentRequest.setThrowExceptionOnExecuteError(false);
      currentRequest.setRetryOnExecuteIOException(true);
      response = currentRequest.execute();
      boolean returningResponse = false;
      try {
        if (response.isSuccessStatusCode()) {
          bytesUploaded = mediaContentLength;
          contentInputStream.close();
          updateStateAndNotifyListener(UploadState.MEDIA_COMPLETE);
          returningResponse = true;
          return response;
        }

        if (response.getStatusCode() != 308) {
          returningResponse = true;
          return response;
        }

        // Check to see if the upload URL has changed on the server.
        String updatedUploadUrl = response.getHeaders().getLocation();
        if (updatedUploadUrl != null) {
          uploadUrl = new GenericUrl(updatedUploadUrl);
        }
        bytesUploaded = getNextByteIndex(response.getHeaders().getRange());
        updateStateAndNotifyListener(UploadState.MEDIA_IN_PROGRESS);
      } finally {
        if (!returningResponse) {
View Full Code Here

      long bytesWritten = getNextByteIndex(response.getHeaders().getRange());

      // Check to see if the upload URL has changed on the server.
      String updatedUploadUrl = response.getHeaders().getLocation();
      if (updatedUploadUrl != null) {
        currentRequest.setUrl(new GenericUrl(updatedUploadUrl));
      }

      // The current position of the input stream is likely incorrect because the upload was
      // interrupted. Reset the position and skip ahead to the correct spot.
      contentInputStream.reset();
View Full Code Here

    try {
      publicKeys = new ArrayList<PublicKey>();
      // HTTP request to public endpoint
      CertificateFactory factory = CertificateFactory.getInstance("X509");
      HttpResponse certsResponse = transport.createRequestFactory().buildGetRequest(
        new GenericUrl("https://www.googleapis.com/oauth2/v1/certs")).execute();
      // parse Cache-Control max-age parameter
      for (String arg : certsResponse.getHeaders().getCacheControl().split(",")) {
        Matcher m = MAX_AGE_PATTERN.matcher(arg);
        if (m.matches()) {
          expirationTimeMilliseconds = clock.currentTimeMillis() + Long.valueOf(m.group(1)) * 1000;
 
View Full Code Here

   * @deprecated (scheduled to removed in 1.8) Use
   *             {@link Builder#Builder(HttpTransport, JsonFactory, HttpRequestInitializer)}.
   */
   @Deprecated
   public static Builder builder(HttpTransport transport, JsonFactory jsonFactory) {
     return new Builder(transport, jsonFactory, new GenericUrl(DEFAULT_BASE_URL));
   }
View Full Code Here

   */
  protected TokenResponse executeRefreshToken() throws IOException {
    if (refreshToken == null) {
      return null;
    }
    return new RefreshTokenRequest(transport, jsonFactory, new GenericUrl(tokenServerEncodedUrl),
        refreshToken).setClientAuthentication(clientAuthentication)
        .setRequestInitializer(requestInitializer).execute();
  }
View Full Code Here

     * the return type, but nothing else.
     * </p>
     */
    public Builder setTokenServerEncodedUrl(String tokenServerEncodedUrl) {
      this.tokenServerUrl =
          tokenServerEncodedUrl == null ? null : new GenericUrl(tokenServerEncodedUrl);
      return this;
    }
View Full Code Here

    }

    // Send request to google without any exception handling.
    private void revokeTokenImpl(GoogleTokenResponse tokenData) throws IOException {
        TRANSPORT.createRequestFactory()
                .buildGetRequest(new GenericUrl("https://accounts.google.com/o/oauth2/revoke?token=" + tokenData.getAccessToken())).execute();
        if (log.isTraceEnabled()) {
            log.trace("Revoked token " + tokenData);
        }
    }
View Full Code Here

  public static void fetchCloudStorageUris(String bucketName,
      String startKey, String endKey, HttpRequestFactory requestFactory,
      List<String> urisToProcess, boolean readSchemas) throws IOException {
    String bucketUri = "http://commondatastorage.googleapis.com/" + bucketName;
    HttpRequest request = requestFactory.buildGetRequest(
        new GenericUrl(bucketUri + "?marker=" + startKey));
    HttpResponse response = request.execute();

    try {
      Document responseDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(response.getContent());
      XPath xPath = XPathFactory.newInstance().newXPath();
View Full Code Here

        request.getHeaders().get(MethodOverride.HEADER));
  }

  public void testInterceptMaxLength() throws IOException {
    HttpTransport transport = new MockHttpTransport();
    GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
    url.set("a", "foo");
    HttpRequest request =
        transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
    new MethodOverride().intercept(request);
    assertEquals(HttpMethods.GET, request.getRequestMethod());
    assertNull(request.getHeaders().get(MethodOverride.HEADER));
    assertNull(request.getContent());
    char[] arr = new char[MethodOverride.MAX_URL_LENGTH];
    Arrays.fill(arr, 'x');
    url.set("a", new String(arr));
    request.setUrl(url);
    new MethodOverride().intercept(request);
    assertEquals(HttpMethods.POST, request.getRequestMethod());
    assertEquals(HttpMethods.GET, request.getHeaders().get(MethodOverride.HEADER));
    assertEquals(HttpTesting.SIMPLE_GENERIC_URL, request.getUrl());
View Full Code Here

TOP

Related Classes of com.google.api.client.http.GenericUrl

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.