Package com.google.api.client.http

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


   * @since 1.7
   */
  @SuppressWarnings("deprecation")
  protected HttpRequest buildHttpRequest(HttpMethod method, GenericUrl url, Object body)
      throws IOException {
    HttpRequest httpRequest = requestFactory.buildRequest(method, url, null);
    JsonObjectParser parser = getJsonObjectParser();

    if (parser != null) {
      httpRequest.setParser(parser);
    } else {
      httpRequest.addParser(getJsonHttpParser());
    }
    if (getApplicationName() != null) {
      httpRequest.getHeaders().setUserAgent(getApplicationName());
    }
    if (body != null) {
      httpRequest.setContent(createSerializer(body));
    }
    return httpRequest;
  }
View Full Code Here


   * @throws IOException if the request fails
   * @since 1.7
   */
  protected HttpResponse executeUnparsed(HttpMethod method, GenericUrl url, Object body)
      throws IOException {
    HttpRequest request = buildHttpRequest(method, url, body);
    return executeUnparsed(request);
  }
View Full Code Here

   * specific behavior is required.
   *
   * @return newly created {@link HttpRequest}
   */
  public HttpRequest buildHttpRequest() throws IOException {
    HttpRequest request = client.buildHttpRequest(method, buildHttpRequestUrl(), content);
    // Add specified headers (if any) to the headers in the request.
    request.getHeaders().putAll(getRequestHeaders());
    return request;
  }
View Full Code Here

   *
   * @return the {@link HttpResponse}
   * @throws IOException if the request fails
   */
  public HttpResponse executeUnparsed() throws IOException {
    HttpRequest request = buildHttpRequest();
    request.setEnableGZipContent(enableGZipContent);
    HttpResponse response = client.executeUnparsed(request);
    lastResponseHeaders = response.getHeaders();
    return response;
  }
View Full Code Here

  /** Create a fake HTTP response object populated with the partContent and the statusCode. */
  @Deprecated
  private HttpResponse getFakeResponse(final int statusCode, final String 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

  }

  private HttpRequest internalExecute(Object data) {
    JsonHttpContent content = new JsonHttpContent(jsonFactory, data);
    content.setMediaType(new HttpMediaType(mimeType));
    HttpRequest httpRequest;
    try {
      httpRequest =
          transport.createRequestFactory().buildPostRequest(new GenericUrl(rpcServerUrl), content);
      httpRequest.getHeaders().setAccept(accept);
      return httpRequest;
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
  }
View Full Code Here

              }
            });
          }
        });
    // make request
    HttpRequest request = requestFactory.buildPostRequest(
        tokenServerUrl, new UrlEncodedContent(this));
    request.setParser(new JsonObjectParser(jsonFactory));
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    if (response.isSuccessStatusCode()) {
      return response;
    }
    throw TokenResponseException.from(jsonFactory, response);
  }
View Full Code Here

   * @throws IOException some other kind of I/O exception
   */
  public Response authenticate() throws ClientLoginResponseException, IOException {
    GenericUrl url = serverUrl.clone();
    url.appendRawPath("/accounts/ClientLogin");
    HttpRequest request =
        transport.createRequestFactory().buildPostRequest(url, new UrlEncodedContent(this));
    request.setParser(AuthKeyValueParser.INSTANCE);
    request.setContentLoggingLimit(0);
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    // check for an HTTP success response (2xx)
    if (response.isSuccessStatusCode()) {
      return response.parseAs(Response.class);
    }
    // On error, throw a ClientLoginResponseException with the parsed error details
View Full Code Here

   * @return newly created {@link HttpRequest}
   */
  @Override
  protected HttpRequest buildHttpRequest(HttpMethod method, GenericUrl url, Object body)
      throws IOException {
    HttpRequest httpRequest = super.buildHttpRequest(method, url, body);
    new MethodOverride().intercept(httpRequest);
    // custom methods may use POST with no content but require a Content-Length header
    if (body == null && method.equals(HttpMethod.POST)) {
      httpRequest.setContent(new EmptyContent());
    }
    return httpRequest;
  }
View Full Code Here

  }

  @Override
  protected HttpResponse executeUnparsed(HttpMethod method, GenericUrl url, Object body)
      throws IOException {
    HttpRequest request = buildHttpRequest(method, url, body);
    return executeUnparsed(request);
  }
View Full Code Here

TOP

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

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.