Package com.google.appengine.api.urlfetch

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


        String authorizationHeader;
        if (req.getAuthorization() != null && (authorizationHeader = req.getAuthorization().getAuthorizationHeader(req)) != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Authorization: ", z_T4JInternalStringUtil.maskString(authorizationHeader));
            }
            request.setHeader(new HTTPHeader("Authorization", authorizationHeader));
        }
        if (null != req.getRequestHeaders()) {
            for (String key : req.getRequestHeaders().keySet()) {
                request.addHeader(new HTTPHeader(key, req.getRequestHeaders().get(key)));
                logger.debug(key + ": " + req.getRequestHeaders().get(key));
            }
        }
    }
View Full Code Here


    }

    if (text.startsWith("[test]")) return;

    final HTTPRequest request = new HTTPRequest(KWeiboUpdateApiUrl, HTTPMethod.POST);
    request.addHeader(new HTTPHeader("Authorization", "Basic " + iBase64.encode(iWeiboCredential.getBytes("US-ASCII"))));
    request.setPayload(("source=" + mConfig.getProperty("weibo.app.key") + "&status=" + URLEncoder.encode(text, "UTF-8")).getBytes("US-ASCII"));
    final HTTPResponse result = iURLFetch.fetch(request);
    if (result.getResponseCode() != 200) {
      final String msg = "Failed to post to Weibo: " + result.getResponseCode() + "\n" + new String(result.getContent(), "UTF-8");
      log.warning(msg);
View Full Code Here

                urlfetch = URLFetchServiceFactory.getURLFetchService();
            }

            URL url = new URL(GEOIP_URL + ip);
            HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET);
            request.addHeader(new HTTPHeader("User-Agent", USER_AGENT));

            HTTPResponse response = urlfetch.fetch(request);
            if (response.getResponseCode() != 200) {
                return null;
            }
View Full Code Here

  public String getAuthorizationHeaderValue() {
    return "OAuth " + getCredentials().getAccessToken();
  }

  public void authorize(HTTPRequest req) {
    req.setHeader(new HTTPHeader("Authorization", getAuthorizationHeaderValue()));
  }
View Full Code Here

    String send(String base) throws IOException {
      URL url = new URL(base + urlBuilder.toString());
      HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST, getFetchOptions());

      // TODO(ohler): use multipart/form-data for efficiency
      req.setHeader(new HTTPHeader("Content-Type", "application/x-www-form-urlencoded"));
      req.setHeader(new HTTPHeader(WALKAROUND_TRUSTED_HEADER, secret.getHexData()));
      // NOTE(danilatos): Appengine will send 503 if the backend is at the
      // max number of concurrent requests. We might come up with a use for
      // handling this error code specifically. For now, we didn't go through
      // the code to make sure that all other overload situations also manifest
      // themselves as 503 rather than random exceptions that turn into 500s.
      // Therefore, the code in this class treats all 5xx responses as an
      // indication of possible overload.
      req.setHeader(new HTTPHeader("X-AppEngine-FailFast", "true"));
      req.setPayload(contentBuilder.toString().getBytes(Charsets.UTF_8));

      log.info("Sending to " + url);
      String ret = fetch(req);
      log.info("Request completed");
View Full Code Here

    }
    final HTTPRequest req = new HTTPRequest(new URL(baseUrl), HTTPMethod.POST,
        FetchOptions.Builder.disallowTruncate().followRedirects()
            .validateCertificate().setDeadline(20.0));
    log.info("payload=" + ops);
    req.setHeader(new HTTPHeader("Content-Type", "application/json; charset=UTF-8"));
    req.setPayload(ops.toString().getBytes(Charsets.UTF_8));
    try {
      return new RetryHelper(RetryHelper.backoffStrategy(0, 1000, 10 * 60 * 1000))
          .run(new RetryHelper.Body<JSONObject>() {
            @Override public JSONObject run() throws RetryableFailure, PermanentFailure {
View Full Code Here

      HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options);

      for (Entry<String, String> entry : request.getHeaders().entries()) {
         String header = entry.getKey();
         if (!prohibitedHeaders.contains(header))
            gaeRequest.addHeader(new HTTPHeader(header, entry.getValue()));
      }
      gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT));
      /**
       * byte [] content is replayable and the only content type supportable by GAE. As such, we
       * convert the original request content to a byte array.
       */
      if (request.getPayload() != null) {
         InputStream input = request.getPayload().getInput();
         try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            request.getPayload().writeTo(out);
            byte[] array = out.toByteArray();
            if (!request.getPayload().isRepeatable()) {
               Payload oldPayload = request.getPayload();
               request.setPayload(array);
               HttpUtils.copy(oldPayload.getContentMetadata(), request.getPayload().getContentMetadata());
            }
            gaeRequest.setPayload(array);
            if (array.length > 0) {
               gaeRequest.setHeader(new HTTPHeader("Expect", "100-continue"));
            }
         } catch (IOException e) {
            Throwables.propagate(e);
         } finally {
            Closeables.closeQuietly(input);
         }

         for (Entry<String, String> header : contentMetadataCodec.toHeaders(
               request.getPayload().getContentMetadata()).entries()) {
            if (!prohibitedHeaders.contains(header.getKey()))
               gaeRequest.setHeader(new HTTPHeader(header.getKey(), header.getValue()));
         }
      }
      return gaeRequest;
   }
View Full Code Here

   @Test
   void testConvertWithHeaders() throws IOException {
      HTTPResponse gaeResponse = createMock(HTTPResponse.class);
      expect(gaeResponse.getResponseCode()).andReturn(200);
      List<HTTPHeader> headers = Lists.newArrayList();
      headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
      expect(gaeResponse.getHeaders()).andReturn(headers);
      expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
      replay(gaeResponse);
      HttpResponse response = req.apply(gaeResponse);
      assertEquals(response.getStatusCode(), 200);
View Full Code Here

   @Test
   void testConvertWithContent() throws IOException {
      HTTPResponse gaeResponse = createMock(HTTPResponse.class);
      expect(gaeResponse.getResponseCode()).andReturn(200);
      List<HTTPHeader> headers = Lists.newArrayList();
      headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
      expect(gaeResponse.getHeaders()).andReturn(headers);
      expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
      replay(gaeResponse);
      HttpResponse response = req.apply(gaeResponse);
      assertEquals(response.getStatusCode(), 200);
View Full Code Here

  @Override
  public List<GcsBucket> listBuckets() throws GcsException {
    try {
      HTTPRequest request = ExtendedOauthRawGcsService.makeGetRequest();
      request.addHeader(new HTTPHeader("Accept-Encoding", "identity"));
      HTTPResponse response = ExtendedOauthRawGcsService.doRequest(request, urlFetchService);
      System.out.println("new String(response.getContent()) = " + new String(response.getContent()));
      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document document = builder.parse(new ByteArrayInputStream(response.getContent()));
      return Parser.parseBucketList(document);
View Full Code Here

TOP

Related Classes of com.google.appengine.api.urlfetch.HTTPHeader

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.