Examples of URLFetchService


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

    {
      strURL = strURL + "?id=" + userID + "&page=" + pageID;
    }
    request = new HTTPRequest(new URL(strURL),HTTPMethod.GET);
    request.addHeader(new HTTPHeader("Authorization",authorization));
    URLFetchService service = URLFetchServiceFactory.getURLFetchService();
    HTTPResponse response = service.fetch(request);
    return response;
  }
View Full Code Here

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

          + "&" + URLEncoder.encode(params,"UTF-8");
    String sig = generateSignature(params,oauth_token_secret);
    String authorization = generateAuthString(timestamp, nonce, sig);
    HTTPRequest request = new HTTPRequest(new URL(url.toString() + "?id=" + id),HTTPMethod.GET);
    request.addHeader(new HTTPHeader("Authorization",authorization));
    URLFetchService service = URLFetchServiceFactory.getURLFetchService();
    HTTPResponse response = service.fetch(request);
   
    return response;
  }
View Full Code Here

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

          + ",oauth_token=\"" + oauth_token + "\""
          + ",oauth_verifier=\"" + strPIN + "\"";

    HTTPRequest request = new HTTPRequest(url,HTTPMethod.GET);
    request.addHeader(new HTTPHeader("Authorization",authorization));
    URLFetchService service = URLFetchServiceFactory.getURLFetchService();
    HTTPResponse response = service.fetch(request);
   
    if(response.getResponseCode() == 200)
    {
      //继续执行
    }
View Full Code Here

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

      strBuf.append(",oauth_signature=\"").append(sig).append("\"");
      authorization = strBuf.toString();
     
      HTTPRequest request = new HTTPRequest(url,HTTPMethod.GET);
      request.addHeader(new HTTPHeader("Authorization",authorization));
      URLFetchService service = URLFetchServiceFactory.getURLFetchService();
      HTTPResponse response;
      try {
        response = service.fetch(request);
      } catch (SocketTimeoutException e) {
        Common.sendMessage(fromJID, "连接饭否超时,请重试");
        return;
      }
      if(response.getResponseCode() != 200)
      {
        String errMsg = "出现错误,请重试";
        Common.sendMessage(fromJID,errMsg);
        Common.log.warning(strJID + " :" + String.valueOf(response.getResponseCode()) + ": " + new String(response.getContent()));
        return;
      }
     
      /* 提取接收到的未经授权的Request Token */
      String tokenstring = new String(response.getContent());
      String[] tokenarr = tokenstring.split("&");
      String[] tokenarr2 = tokenarr[0].split("=");
      String oauth_token = tokenarr2[1];
      Common.setData(fromJID,"Account","request_token",oauth_token);
     
      /* 请求用户授权Request Token */
      String strMessage = "请访问以下网址获取PIN码: \n http://fanfou.com/oauth/authorize?oauth_token="
            + oauth_token + "&oauth_callback=oob"
            + " \n 手机用户请访问: \n http://m.fanfou.com/oauth/authorize?oauth_token="
            + oauth_token + "&oauth_callback=oob"
            + " \n 然后使用\"-bind PIN码\"命令绑定账号。";
      Common.sendMessage(fromJID,strMessage);
    }
    else if(msgarr.length == 3)                        //XAuth
    {
      URL url = new URL("http://fanfou.com/oauth/access_token");
      String username = msgarr[1];
      String password = msgarr[2];
      params = "oauth_consumer_key=" + API.consumer_key
          + "&oauth_nonce=" + String.valueOf(nonce)
          + "&oauth_signature_method=HMAC-SHA1"
          + "&oauth_timestamp=" + String.valueOf(timestamp)
          + "&x_auth_username=" + username
          + "&x_auth_password=" + password
          + "&x_auth_mode=client_auth";
   
      params = "GET&" + URLEncoder.encode(url.toString(),"UTF-8")
            + "&" + URLEncoder.encode(params,"UTF-8");
      String sig = API.generateSignature(params);
     
      authorization = "OAuth realm=\"Fantalker\",oauth_consumer_key=\"" + API.consumer_key
            + "\",oauth_signature_method=\"HMAC-SHA1\""
            + ",oauth_timestamp=\"" + String.valueOf(timestamp) + "\""
            + ",oauth_nonce=\"" + String.valueOf(nonce) + "\""
            + ",oauth_signature=\"" + sig + "\""
            + ",x_auth_username=\"" + username + "\""
            + ",x_auth_password=\"" + password + "\""
            + ",x_auth_mode=\"client_auth\"";
     
     
      HTTPRequest request = new HTTPRequest(url,HTTPMethod.GET);
      request.addHeader(new HTTPHeader("Authorization",authorization));
      URLFetchService service = URLFetchServiceFactory.getURLFetchService();
      HTTPResponse response;
      try {
        response = service.fetch(request);
      } catch (SocketTimeoutException e) {
        Common.sendMessage(fromJID, "连接饭否超时,请重试");
        return;
      }
     
View Full Code Here

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

     * @param msg
     * @return
     */
    private void imageUpload(UserModel userModel, String msg, String imagePath) throws Exception {

        URLFetchService fetchService =
                URLFetchServiceFactory.getURLFetchService();
        HTTPResponse fetchResponse = fetchService.fetch(new URL(imagePath));

        InputStream inputStream = new ByteArrayInputStream(fetchResponse.getContent());

        // 承認情報の生成
        ConfigurationBuilder cb = getConfigurationBuilder(userModel);
View Full Code Here

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

        return facebook;
    }

    private Media getPhotoMedia(String imageUrl) throws MalformedURLException, IOException {

        URLFetchService fetchService =
                URLFetchServiceFactory.getURLFetchService();
        HTTPResponse fetchResponse = fetchService.fetch(new URL(imageUrl));

        InputStream inputStream = new ByteArrayInputStream(fetchResponse.getContent());

        return new Media("photo by plucial", inputStream);
View Full Code Here

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

                    os = new ByteArrayOutputStream();
                    os.write(bytes);
                }
                request.setPayload(os.toByteArray());
            }
            URLFetchService service = URLFetchServiceFactory.getURLFetchService();
            return new AppEngineHttpResponseImpl(service.fetchAsync(request));
        } catch (IOException ioe) {
            // connection timeout or read timeout
            throw new TwitterException(ioe.getMessage(), ioe, responseCode);
        }
    }
View Full Code Here

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

    public static String getText(HTTPResponse response, String encoding) throws UnsupportedEncodingException {
        return new String(response.getContent(), encoding);
    }

    private static Object fetch(URL url, HTTPMethod method, Map<String, Object> options) throws IOException {
        URLFetchService urlFetch = URLFetchServiceFactory.getURLFetchService();
        FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();

        // specify the fetch options
        for (Entry<String, Object> entry : options.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
           
            switch(key) {
                case "allowTruncate":
                    if (DefaultGroovyMethods.asBoolean(value))
                        fetchOptions.allowTruncate();
                    else
                        fetchOptions.disallowTruncate();
                    break;
                case "followRedirects":
                    if (DefaultGroovyMethods.asBoolean(value))
                        fetchOptions.followRedirects();
                    else
                        fetchOptions.doNotFollowRedirects();
                    break;
                case "deadline":
                    fetchOptions.setDeadline(((Number)value).doubleValue());
                    break;
            // bypass the headers, payload, params and async options
                case "headers":
                case "payload":
                case "params":
                case "async":
                    break;
                default:
                    throw new RuntimeException("Unknown fetch option: " + key);
            }
        }

        // add params
        if (options.containsKey("params")) {
            String encodedParams = MiscExtensions.toQueryString((Map<?,?>)options.get("params"));
            // if it's a POST method, encode the params as an URL encoded payload
            if (method == HTTPMethod.POST) {
                @SuppressWarnings("unchecked") Map<String, String> headersMap = (Map<String, String>) options.get("headers");
                if (headersMap == null) {
                    headersMap = new LinkedHashMap<>();
                    options.put("headers", headersMap);
                }
                headersMap.put("Content-Type", "application/x-www-form-urlencoded");
               
                options.put("payload", encodedParams.getBytes());
            } else {
                url = new URL(url.toString() + "?" + encodedParams);
            }
        }

        HTTPRequest request = new HTTPRequest(url, method, fetchOptions);

        // add the headers to the request
        if (options.containsKey("headers")) {
            @SuppressWarnings("unchecked") Map<String, String> headers = (Map<String, String>) options.get("headers");
            for (Entry<String, String> e : headers.entrySet()) {
                request.addHeader(new HTTPHeader(e.getKey(), e.getValue()));
            }
        }

        // add the payload
        if (options.containsKey("payload")) {
            request.setPayload((byte[]) options.get("payload"));
        }

        // do an async call, if the async: true option is present
        if (options.containsKey("async") && DefaultGroovyMethods.asBoolean(options.get("async"))) return urlFetch.fetchAsync(request);
        return urlFetch.fetch(request);
    }
View Full Code Here

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

  private static final double TIMEOUT_SECONDS = 10.0;

  public static String doGet(String strUrl) throws IOException {

  URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();

  java.net.URL url = new java.net.URL(strUrl);

  HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, FetchOptions.Builder.withDeadline(TIMEOUT_SECONDS));

  HTTPResponse response = ufs.fetch(request);

  byte[] content = response.getContent();

  return new String(content, Constants.HTTP_ENCODEING);
  }
View Full Code Here

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

  return new String(content, Constants.HTTP_ENCODEING);
  }

  public static String doPost(String strUrl, String payload) throws IOException {

  URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();

  java.net.URL url = new java.net.URL(strUrl);

  HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST, FetchOptions.Builder.withDeadline(TIMEOUT_SECONDS).allowTruncate());

  request.setPayload(payload.getBytes());
 
  log.info("doPost url :" + strUrl);

  HTTPResponse response = ufs.fetch(request);

  byte[] content = response.getContent();

  return new String(content, Constants.HTTP_ENCODEING);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.