Package com.google.api.client.http

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


    payload.put("scope", Joiner.on(' ').join(serviceAccountScopes));
    try {
      String assertion = JsonWebSignature.signUsingRsaSha256(
          serviceAccountPrivateKey, getJsonFactory(), header, payload);
      TokenRequest request = new TokenRequest(
          getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()),
          "urn:ietf:params:oauth:grant-type:jwt-bearer");
      request.put("assertion", assertion);
      return request.execute();
    } catch (GeneralSecurityException exception) {
      IOException e = new IOException();
View Full Code Here


    return false;
  }

  static boolean runningOnComputeEngine(HttpTransport transport) {
    try {
      GenericUrl tokenUrl = new GenericUrl(METADATA_SERVER_URL);
      HttpRequest request = transport.createRequestFactory().buildGetRequest(tokenUrl);
      HttpResponse response = request.execute();
      HttpHeaders headers = response.getHeaders();
      if (headersContainValue(headers, "Metadata-Flavor", "Google")) {
        return true;
View Full Code Here

  private HttpResponse getFakeResponse(final int statusCode, final InputStream partContent,
      List<String> headerNames, List<String> headerValues)
      throws IOException {
    HttpRequest request = new FakeResponseHttpTransport(
        statusCode, partContent, headerNames, headerValues).createRequestFactory()
        .buildPostRequest(new GenericUrl("http://google.com/"), null);
    request.setLoggingEnabled(false);
    request.setThrowExceptionOnExecuteError(false);
    return request.execute();
  }
View Full Code Here

    }
    getHeadersBase();
  }

  private GenericUrl resolveUrl(String path) {
    return new GenericUrl(makeUrl(path));
  }
View Full Code Here

  private String requestPost(String urlStr, Map<String, String> postData, boolean useOAuth) {
    return request(urlStr, "POST", postData, useOAuth);
  }

  private String request(String urlStr, String requestMethod, Map<String, String> postData, boolean useOAuth) {
    GenericUrl url = new GenericUrl(urlStr);
    // Configure OAuth request params
    OAuthParameters params = new OAuthParameters();
    params.consumerKey = key;
    params.computeNonce();
    params.computeTimestamp();
View Full Code Here

  }

  private HttpRequest createRequest(String urlStr, Request fullQuery, String requestMethod,
      boolean useOAuth) throws GeneralSecurityException, IOException {
    Map<String, String> postData = fullQuery.getPostData();
    GenericUrl url = new GenericUrl(urlStr);
    if (debug) {
      fullQuery.printDebug();
      logger = Logger.getLogger(HttpTransport.class.getName());
      logger.removeHandler(debugHandler);
      logger.setLevel(Level.ALL);
View Full Code Here

  }

  private HttpRequest createRequest(String urlStr, Request fullQuery, String requestMethod,
      boolean useOAuth) throws GeneralSecurityException, IOException {
    Map<String, String> postData = fullQuery.getPostData();
    GenericUrl url = new GenericUrl(urlStr);
    if (debug) {
      fullQuery.printDebug();
      Logger logger = Logger.getLogger(HttpTransport.class.getName());
      logger.removeHandler(debugHandler);
      logger.setLevel(Level.ALL);
View Full Code Here

   *
   * @param authorizationCode authorization code.
   */
  public AuthorizationCodeTokenRequest newTokenRequest(String authorizationCode) {
    return new AuthorizationCodeTokenRequest(transport, jsonFactory,
        new GenericUrl(tokenServerEncodedUrl), authorizationCode).setClientAuthentication(
        clientAuthentication).setRequestInitializer(requestInitializer).setScopes(scopes);
  }
View Full Code Here

    HttpResponse initialResponse = executeUploadInitiation(initiationRequestUrl);
    if (!initialResponse.isSuccessStatusCode()) {
      // If the initiation request is not successful return it immediately.
      return initialResponse;
    }
    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() && isMediaLengthKnown()) {
      // If we know the media content length then wrap the stream into a Buffered input stream to
      // support the {@link InputStream#mark} and {@link InputStream#reset} methods required for
      // handling server errors.
      contentInputStream = new BufferedInputStream(contentInputStream);
    }

    HttpResponse response;
    // Upload the media content in chunks.
    while (true) {
      currentRequest = requestFactory.buildPutRequest(uploadUrl, null);
      setContentAndHeadersOnCurrentRequest();
      if (backOffPolicyEnabled) {
        // use exponential back-off on server error
        currentRequest.setBackOffPolicy(new MediaUploadExponentialBackOffPolicy(this));
      } else {
        // set mediaErrorHandler as I/O exception handler and as unsuccessful response handler for
        // calling to serverErrorCallback on an I/O exception or an abnormal HTTP response
        new MediaUploadErrorHandler(this, currentRequest);
      }

      if (isMediaLengthKnown()) {
        // TODO(rmistry): Support gzipping content for the case where media content length is
        // known (https://code.google.com/p/google-api-java-client/issues/detail?id=691).
      } else if (!disableGZipContent) {
        currentRequest.setEncoding(new GZipEncoding());
      }
      response = executeCurrentRequest(currentRequest);
      boolean returningResponse = false;
      try {
        if (response.isSuccessStatusCode()) {
          totalBytesServerReceived = getMediaContentLength();
          if (mediaContent.getCloseInputStream()) {
            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);
        }

        // we check the amount of bytes the server received so far, because the server may process
        // fewer bytes than the amount of bytes the client had sent
        long newBytesServerReceived = getNextByteIndex(response.getHeaders().getRange());
View Full Code Here

     * Google 内で有効状態が維持されます。  したがって、同一のユーザーが後でアプリに戻り、
     * ログイン、再同意して、アプリの使用を再開できます。
     * @throws IOException 要求の最中にネットワーク エラーが発生しました。
     */
    protected static void revokeToken(UserModel userModel) throws Exception {
      TRANSPORT.createRequestFactory().buildGetRequest(new GenericUrl(
          String.format("https://accounts.google.com/o/oauth2/revoke?token=%s",userModel.getAccessToken()))).execute();
    }
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.