Package com.google.appengine.api.urlfetch

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


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

      HTTPResponse httpResponse;
      try {
        httpResponse = fetchService.fetch(httpRequest);
      } catch (ResponseTooLargeException e) {
        return new TooLargeResponse(currentUrl);
      }

      if (!isRedirect(httpResponse.getResponseCode())) {
        boolean isResponseTooLarge =
          (getContentLength(httpResponse) > requestOptions.getMaxBodySize());
        return new AppEngineFetchResponse(httpResponse,
            isResponseTooLarge, currentUrl);
      } else {
View Full Code Here


  public String getMethod(URL url) throws IOException {
    log.finer("Calling GET on " + url);
    HTTPRequest req = new HTTPRequest(url);
    if(cookie!=null)
      req.setHeader(cookie);
    HTTPResponse resp = getURLFetchService().fetch(req);
    updateCookies(resp);
    int responseCode = -1;
    if (resp != null) {
      responseCode = resp.getResponseCode();
      if (responseCode == 200) {
        String response = new String(resp.getContent(), RESPONSE_CONTENT_ENCODING);
        log.finer("GET returns: " + response);
        return response;
      }
    }
    throw new IOException("Problem calling GET on: " + url.toString() + " response: " + responseCode);
View Full Code Here

      req.setHeader(cookie);
    if(sessionParam!=null)
      params = sessionParam + "&" + params;
    req.setPayload(params.getBytes(RESPONSE_CONTENT_ENCODING));
 
    HTTPResponse resp = getURLFetchService().fetch(req);
    updateCookies(resp);
    int responseCode = -1;
    if (resp != null) {
      responseCode = resp.getResponseCode();
      if (responseCode == 200) {
        // List<HTTPHeader> headers = resp.getHeaders();
        String response = new String(resp.getContent(), RESPONSE_CONTENT_ENCODING);
        log.finer("POST returns: " + response);
        return response;
      }
    }
    throw new IOException("Problem calling GET on: " + url.toString() + " response: " + responseCode);
View Full Code Here

    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    req.setPayload(getwork.toString().getBytes());
    req.addHeader(new HTTPHeader("Authorization", config.getAuth()));

    HTTPResponse resp = ufs.fetch(req);
    String content = new String(resp.getContent());
    if (resp.getResponseCode() != 200) {
      throw new IOException( //
          "fetchWork Error: " + resp.getResponseCode() + " "
              + content);
    }

    JSONObject respwork = new JSONObject(content);
    Object errorP = respwork.get("error");
View Full Code Here

    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    req.setPayload(getwork.toString().getBytes());
    req.addHeader(new HTTPHeader("Authorization", config.getAuth()));

    HTTPResponse resp = ufs.fetch(req);
    String content = new String(resp.getContent());
    if (resp.getResponseCode() != 200) {
      log.severe( //
      "submitWork Error: " + resp.getResponseCode() + " " + content);
      return false;
    }

    JSONObject respwork = new JSONObject(content);
    Object errorP = respwork.get("error");
View Full Code Here

   
    //URL url = new URL(urlStr);
    URLFetchService urlFetchService =
    URLFetchServiceFactory.getURLFetchService();
    HTTPRequest httpRequest = new HTTPRequest(url);
    HTTPResponse response = urlFetchService.fetch(httpRequest);
   
   
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setReadTimeout(60000);
    conn.setConnectTimeout(60000);
View Full Code Here

  public static byte[] getFile(String URLName) {

    try {
      URL url = new URL(URLName);
      URLFetchService u = URLFetchServiceFactory.getURLFetchService();
      HTTPResponse r = u.fetch(url);

      return r.getContent();

    } catch (MalformedURLException e) {
      System.err.println("Malformed URL:" + URLName);
      e.printStackTrace();
      return null;
View Full Code Here

      }
    }
    // connect
    URLFetchService service = URLFetchServiceFactory.getURLFetchService();
    try {
      HTTPResponse response = service.fetch(request);
      return new UrlFetchResponse(response);
    } catch (ResponseTooLargeException e) {
      IOException ioException = new IOException();
      ioException.initCause(e);
      throw ioException;
View Full Code Here

        //if were updating the auth
        if (null == authEntity || !authEntity.getProperty("secret").equals(updateAuth)) {
          //if there is no auth key, or the auth key doesn't match the one provided
          try {
            URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
            HTTPResponse response = fetchService.fetch(new URL(SECURE_HOST + "/auth/?site=" + req.getHeader("Host") + "&auth=" + updateAuth));
           
            if (response.getResponseCode() == 200) {
              //if successfully received a response, save the new auth key
              String content = new String(response.getContent());
              if (content.equals(new String("OK"))) {
                authEntity = new Entity(key);
                authEntity.setProperty("secret", updateAuth);
               
                datastoreService.put(authEntity);
View Full Code Here

        if (null == authEntity || !authEntity.getProperty("secret").equals(updateAuth)) {
          //if there is no auth key, or the auth key doesn't match the one provided
          try {
            URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
            String host = URLEncoder.encode(req.getHeader("Host"), "UTF-8");
            HTTPResponse response = fetchService.fetch(new URL(SECURE_HOST + "/auth/?site=" + host + "&auth=" + updateAuth));

            if (response.getResponseCode() == 200) {
              //if successfully received a response, save the new auth key
              String content = new String(response.getContent());
              if (content.equals(new String("OK"))) {
                authEntity = new Entity(key);
                authEntity.setProperty("secret", updateAuth);

                datastoreService.put(authEntity);
View Full Code Here

TOP

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

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.