Package com.google.appengine.api.urlfetch

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


    getwork.put("params", new JSONArray());
    getwork.put("id", 0);

    URL url = new URL(config.getJsonRpcServer());

    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);
View Full Code Here


    getwork.put("method", "getwork");
    getwork.append("params", work.data);
    getwork.put("id", 0);

    URL url = new URL(config.getJsonRpcServer());
    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;
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);
View Full Code Here

      if (payload.length != 0) {
        request.setPayload(payload);
      }
    }
    // 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

      out.println("<hr />");
      out.println("");

      try {
        URL url = new URL(pageName);
        URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
        Future<HTTPResponse> fetchResponse = fetchService.fetchAsync(url);

        String result = new String(fetchResponse.get().getContent());
        result = result.replace("<", "&lt;").replace(">", "&gt;");
        out.println(result);
View Full Code Here

      if (null != updateAuth) {
        //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"))) {
View Full Code Here

      if (null != updateAuth) {
        //if we're 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();
            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"))) {
View Full Code Here

    }
  }

  @Test
  public void testAuthIsRetried() throws IOException, InterruptedException, ExecutionException {
    URLFetchService urlFetchService = mock(URLFetchService.class, RETURNS_MOCKS);
    FailingFetchService failingFetchService = new FailingFetchService(urlFetchService, 1);
    failingFetchService.fetch(mock(HTTPRequest.class));

    failingFetchService = new FailingFetchService(urlFetchService, 1);
    failingFetchService.fetchAsync(mock(HTTPRequest.class)).get();
View Full Code Here

    failingFetchService.fetchAsync(mock(HTTPRequest.class)).get();
  }

  @Test
  public void testErrorsArePropigated() throws IOException, InterruptedException {
    URLFetchService urlFetchService = mock(URLFetchService.class, RETURNS_MOCKS);
    FailingFetchService failingFetchService =
        new FailingFetchService(urlFetchService, Integer.MAX_VALUE);
    try {
      failingFetchService.fetch(mock(HTTPRequest.class));
      fail();
View Full Code Here

TOP

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

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.