Package com.google.appengine.api.urlfetch

Examples of com.google.appengine.api.urlfetch.HTTPRequest


   * exception that would have been thrown by put.
   */
  private Future<RawGcsCreationToken> putAsync(final GcsRestCreationToken token,
      ByteBuffer chunk, final boolean isFinalChunk, long timeoutMillis) {
    final int length = chunk.remaining();
    HTTPRequest request = createPutRequest(token, chunk, isFinalChunk, timeoutMillis, length);
    final HTTPRequestInfo info = new HTTPRequestInfo(request);
    return new FutureWrapper<HTTPResponse, RawGcsCreationToken>(urlfetch.fetchAsync(request)) {
      @Override
      protected Throwable convertException(Throwable e) {
        return OauthRawGcsService.convertException(info, e);
View Full Code Here


  }

  /** True if deleted, false if not found. */
  @Override
  public boolean deleteObject(GcsFilename filename, long timeoutMillis) throws IOException {
    HTTPRequest req = makeRequest(filename, null, DELETE, timeoutMillis, headers);
    HTTPResponse resp;
    try {
      resp = urlfetch.fetch(req);
    } catch (IOException e) {
      throw createIOException(new HTTPRequestInfo(req), e);
View Full Code Here

        startOffsetBytes);
    final int n = dst.remaining();
    Preconditions.checkArgument(n > 0, "%s: dst full: %s", this, dst);
    final int want = Math.min(READ_LIMIT_BYTES, n);

    final HTTPRequest req = makeRequest(filename, null, GET, timeoutMillis, headers);
    req.setHeader(
        new HTTPHeader(RANGE, "bytes=" + startOffsetBytes + "-" + (startOffsetBytes + want - 1)));
    final HTTPRequestInfo info = new HTTPRequestInfo(req);
    return new FutureWrapper<HTTPResponse, GcsFileMetadata>(urlfetch.fetchAsync(req)) {
      @Override
      protected GcsFileMetadata wrap(HTTPResponse resp) throws IOException {
View Full Code Here

  }

  @Override
  public GcsFileMetadata getObjectMetadata(GcsFilename filename, long timeoutMillis)
      throws IOException {
    HTTPRequest req = makeRequest(filename, null, HEAD, timeoutMillis, headers);
    HTTPResponse resp;
    try {
      resp = urlfetch.fetch(req);
    } catch (IOException e) {
      throw createIOException(new HTTPRequestInfo(req), e);
View Full Code Here

  }

  @Override
  public void composeObject(Iterable<String> source, GcsFilename dest, long timeoutMillis)
      throws IOException {
    HTTPRequest req =
        makeRequest(dest, COMPOSE_QUERY_STRINGS, PUT, timeoutMillis, headers);
    StringBuilder xmlContent = new StringBuilder(Iterables.size(source) * 50);
    xmlContent.append("<ComposeRequest>");
    Escaper escaper = XmlEscapers.xmlContentEscaper();
    for (String srcFileName : source) {
      xmlContent.append("<Component><Name>");
      xmlContent.append(escaper.escape(srcFileName));
      xmlContent.append("</Name></Component>");
    }
    xmlContent.append("</ComposeRequest>");
    byte[] payload = xmlContent.toString().getBytes(UTF_8);
    req.setHeader(new HTTPHeader(CONTENT_LENGTH, String.valueOf(payload.length)));
    req.setPayload(payload);
    HTTPResponse resp;
    try {
      resp = urlfetch.fetch(req);
    } catch (IOException e) {
      throw createIOException(new HTTPRequestInfo(req), e);
View Full Code Here

        break;
    }

    try {

      HTTPRequest httpRequest = new HTTPRequest(request.getUri().toURL(), method);
      HTTPResponse httpResponse = fetchService.fetch(httpRequest);
      return new AppEngineFetchResponse(httpResponse);

    } catch (MalformedURLException e) {
      throw new FetchException(e);
View Full Code Here

    String currentUrl = url;

    for (int i = 0; i <= requestOptions.getMaxRedirects(); i++) {

      HTTPRequest httpRequest = new HTTPRequest(new URL(currentUrl),
          method, options);

      addHeaders(httpRequest, requestOptions);

      if (method == HTTPMethod.POST && content != null) {
        httpRequest.setPayload(content.getBytes());
      }

      HTTPResponse httpResponse;
      try {
        httpResponse = fetchService.fetch(httpRequest);
View Full Code Here

     *            ignored.
     * @return a newly created {@link HTTPRequest} instance containing data from
     *         <code>exchange</code>.
     */
    public HTTPRequest writeRequest(GHttpEndpoint endpoint, Exchange exchange, HTTPRequest request) throws Exception {
        HTTPRequest answer = new HTTPRequest(
                getRequestUrl(endpoint, exchange),
                getRequestMethod(endpoint, exchange));
        writeRequestHeaders(endpoint, exchange, answer);
        writeRequestBody(endpoint, exchange, answer);
        return answer;
View Full Code Here

    }
  }

  @Override
  public Response get(String path) throws IOException {
    HTTPRequest req = new HTTPRequest(new URL(makeUrl(path)), HTTPMethod.GET);
    req.getFetchOptions().doNotFollowRedirects();
    for (String[] headerPair : getHeadersForGet()) {
      req.addHeader(new HTTPHeader(headerPair[0], headerPair[1]));
    }
    addCookies(req);
    HTTPResponse resp = urlFetch.fetch(req);
    return createResponse(resp);
  }
View Full Code Here

    return createResponse(resp);
  }

  @Override
  public Response post(String path, String mimeType, byte[] body) throws IOException {
    HTTPRequest req = new HTTPRequest(new URL(makeUrl(path)), HTTPMethod.POST);
    req.getFetchOptions().doNotFollowRedirects();
    for (String[] headerPair : getHeadersForPost(mimeType)) {
      req.addHeader(new HTTPHeader(headerPair[0], headerPair[1]));
    }
    addCookies(req);
    req.setPayload(body);
    HTTPResponse resp = urlFetch.fetch(req);
    return createResponse(resp);
  }
View Full Code Here

TOP

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