亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? oauthclient.java

?? android開發入門與實踐源代碼
?? JAVA
字號:
/*
 * Copyright 2007, 2008 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.oauth.client;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.oauth.OAuth;
import net.oauth.OAuthAccessor;
import net.oauth.OAuthConsumer;
import net.oauth.OAuthException;
import net.oauth.OAuthMessage;
import net.oauth.OAuthProblemException;
import net.oauth.http.HttpClient;
import net.oauth.http.HttpMessage;
import net.oauth.http.HttpMessageDecoder;
import net.oauth.http.HttpResponseMessage;

/**
 * Methods for an OAuth consumer to request tokens from a service provider.
 * <p>
 * This class can also be used to request access to protected resources, in some
 * cases. But not in all cases. For example, this class can't handle arbitrary
 * HTTP headers.
 * <p>
 * Methods of this class return a response as an OAuthMessage, from which you
 * can get a body or parameters but not both. Calling a getParameter method will
 * read and close the body (like readBodyAsString), so you can't read it later.
 * If you read or close the body first, then getParameter can't read it. The
 * response headers should tell you whether the response contains encoded
 * parameters, that is whether you should call getParameter or not.
 * <p>
 * Methods of this class don't follow redirects. When they receive a redirect
 * response, they throw an OAuthProblemException, with properties
 * HttpResponseMessage.STATUS_CODE = the redirect code
 * HttpResponseMessage.LOCATION = the redirect URL. Such a redirect can't be
 * handled at the HTTP level, if the second request must carry another OAuth
 * signature (with different parameters). For example, Google's Service Provider
 * routinely redirects requests for access to protected resources, and requires
 * the redirected request to be signed.
 * 
 * @author John Kristian
 */
public class OAuthClient {

    public OAuthClient(HttpClient http)
    {
        this.http = http;
    }

    private final HttpClient http;

    /** Get a fresh request token from the service provider. */
    public void getRequestToken(OAuthAccessor accessor, String httpMethod)
            throws IOException, OAuthException, URISyntaxException {
        getRequestToken(accessor, httpMethod, null);
    }

    /** Get a fresh request token from the service provider. */
    public void getRequestToken(OAuthAccessor accessor, String httpMethod,
            Collection<? extends Map.Entry> parameters) throws IOException,
            OAuthException, URISyntaxException {
        accessor.accessToken = null;
        accessor.tokenSecret = null;
        {
            // This code supports the 'Variable Accessor Secret' extension
            // described in http://oauth.pbwiki.com/AccessorSecret
            Object accessorSecret = accessor
                    .getProperty(OAuthConsumer.ACCESSOR_SECRET);
            if (accessorSecret != null) {
                List<Map.Entry> p = (parameters == null) ? new ArrayList<Map.Entry>(
                        1)
                        : new ArrayList<Map.Entry>(parameters);
                p.add(new OAuth.Parameter("oauth_accessor_secret",
                        accessorSecret.toString()));
                parameters = p;
                // But don't modify the caller's parameters.
            }
        }
        OAuthMessage response = invoke(accessor, httpMethod,
                accessor.consumer.serviceProvider.requestTokenURL, parameters);
        accessor.requestToken = response.getParameter(OAuth.OAUTH_TOKEN);
        accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
        response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
    }

    public void getRequestToken(OAuthAccessor accessor) throws IOException,
            OAuthException, URISyntaxException {
        getRequestToken(accessor, null);
    }

    /**
     * Get an access token from the service provider (in exchange for an
     * authorized request token).
     */
    public OAuthMessage getAccessToken(OAuthAccessor accessor, String httpMethod,
            Collection<? extends Map.Entry> parameters) throws IOException, OAuthException, URISyntaxException {
        if (accessor.requestToken != null) {
            if (parameters == null) {
                parameters = OAuth.newList(OAuth.OAUTH_TOKEN, accessor.requestToken);
            } else if (!OAuth.newMap(parameters).containsKey(OAuth.OAUTH_TOKEN)) {
                List<Map.Entry> p = new ArrayList<Map.Entry>(parameters);
                p.add(new OAuth.Parameter(OAuth.OAUTH_TOKEN, accessor.requestToken));
                parameters = p;
            }
        }
        OAuthMessage response = invoke(accessor, httpMethod,
                accessor.consumer.serviceProvider.accessTokenURL, parameters);
        response.requireParameters(OAuth.OAUTH_TOKEN, OAuth.OAUTH_TOKEN_SECRET);
        accessor.accessToken = response.getParameter(OAuth.OAUTH_TOKEN);
        accessor.tokenSecret = response.getParameter(OAuth.OAUTH_TOKEN_SECRET);
        return response;
    }

    /**
     * Construct a request message, send it to the service provider and get the
     * response.
     * 
     * @return the response
     * @throws URISyntaxException
     *                 the given url isn't valid syntactically
     * @throws OAuthProblemException
     *                 the HTTP response status code was not OK
     */
    public OAuthMessage invoke(OAuthAccessor accessor, String httpMethod,
            String url, Collection<? extends Map.Entry> parameters)
    throws IOException, OAuthException, URISyntaxException {
        String ps = (String) accessor.consumer.getProperty(PARAMETER_STYLE);
        ParameterStyle style = (ps == null) ? ParameterStyle.BODY : Enum
                .valueOf(ParameterStyle.class, ps);
        OAuthMessage request = accessor.newRequestMessage(httpMethod, url,
                parameters);
        Object accepted = accessor.consumer.getProperty(ACCEPT_ENCODING);
        if (accepted != null) {
            request.getHeaders().add(
                    new OAuth.Parameter(HttpMessage.ACCEPT_ENCODING, accepted
                            .toString()));
        }
        return invoke(request, style);
    }

    /**
     * The name of the OAuthConsumer property whose value is the ParameterStyle
     * to be used by invoke.
     */
    public static final String PARAMETER_STYLE = "parameterStyle";

    /**
     * The name of the OAuthConsumer property whose value is the Accept-Encoding
     * header in HTTP requests.
     */
    public static final String ACCEPT_ENCODING = "HTTP.header." + HttpMessage.ACCEPT_ENCODING;

    /**
     * Construct a request message, send it to the service provider and get the
     * response.
     * 
     * @return the response
     * @throws URISyntaxException
     *                 the given url isn't valid syntactically
     * @throws OAuthProblemException
     *                 the HTTP response status code was not OK
     */
    public OAuthMessage invoke(OAuthAccessor accessor, String url,
            Collection<? extends Map.Entry> parameters) throws IOException,
            OAuthException, URISyntaxException {
        return invoke(accessor, null, url, parameters);
    }

    /** @deprecated Use invoke(OAuthMessage, ParameterStyle) instead. */
    @Deprecated
    public OAuthMessage invoke(OAuthMessage request) throws IOException,
            OAuthException {
        return invoke(request, ParameterStyle.BODY);
    }

    /**
     * Send a request message to the service provider and get the response.
     * 
     * @return the response
     * @throws IOException
     *                 failed to communicate with the service provider
     * @throws OAuthProblemException
     *                 the HTTP response status code was not OK
     */
    /** Send a message to the service provider and get the response. */
    public OAuthMessage invoke(OAuthMessage request, ParameterStyle style)
            throws IOException, OAuthException {
        final boolean isPost = POST.equalsIgnoreCase(request.method);
        InputStream body = request.getBodyAsStream();
        if (style == ParameterStyle.BODY && !(isPost && body == null)) {
            style = ParameterStyle.QUERY_STRING;
        }
        String url = request.URL;
        final List<Map.Entry<String, String>> headers =
            new ArrayList<Map.Entry<String, String>>(request.getHeaders());
        switch (style) {
        case QUERY_STRING:
            url = OAuth.addParameters(url, request.getParameters());
            break;
        case BODY: {
            byte[] form = OAuth.formEncode(request.getParameters()).getBytes(
                    request.getBodyEncoding());
            headers.add(new OAuth.Parameter(HttpMessage.CONTENT_TYPE,
                    OAuth.FORM_ENCODED));
            headers.add(new OAuth.Parameter(CONTENT_LENGTH, form.length + ""));
            body = new ByteArrayInputStream(form);
            break;
        }
        case AUTHORIZATION_HEADER:
            headers.add(new OAuth.Parameter("Authorization", request.getAuthorizationHeader(null)));
            // Find the non-OAuth parameters:
            List<Map.Entry<String, String>> others = request.getParameters();
            if (others != null && !others.isEmpty()) {
                others = new ArrayList<Map.Entry<String, String>>(others);
                for (Iterator<Map.Entry<String, String>> p = others.iterator(); p
                        .hasNext();) {
                    if (p.next().getKey().startsWith("oauth_")) {
                        p.remove();
                    }
                }
                // Place the non-OAuth parameters elsewhere in the request:
                if (isPost && body == null) {
                    byte[] form = OAuth.formEncode(others).getBytes(
                            request.getBodyEncoding());
                    headers.add(new OAuth.Parameter(HttpMessage.CONTENT_TYPE,
                            OAuth.FORM_ENCODED));
                    headers.add(new OAuth.Parameter(CONTENT_LENGTH, form.length
                            + ""));
                    body = new ByteArrayInputStream(form);
                } else {
                    url = OAuth.addParameters(url, others);
                }
            }
            break;
        }
        final HttpMessage httpRequest = new HttpMessage(request.method, new URL(url), body);
        httpRequest.headers.addAll(headers);
        HttpResponseMessage httpResponse = http.execute(httpRequest);
        httpResponse = HttpMessageDecoder.decode(httpResponse);
        OAuthMessage response = new OAuthResponseMessage(httpResponse);
        if (httpResponse.getStatusCode() != HttpResponseMessage.STATUS_OK) {
            OAuthProblemException problem = new OAuthProblemException();
            try {
                response.getParameters(); // decode the response body
            } catch (IOException ignored) {
            }
            problem.getParameters().putAll(response.getDump());
            try {
                InputStream b = response.getBodyAsStream();
                if (b != null) {
                    b.close(); // release resources
                }
            } catch (IOException ignored) {
            }
            throw problem;
        }
        return response;
    }

    /** Where to place parameters in an HTTP message. */
    public enum ParameterStyle {
        AUTHORIZATION_HEADER, BODY, QUERY_STRING;
    };

    protected static final String PUT = OAuthMessage.PUT;
    protected static final String POST = OAuthMessage.POST;
    protected static final String DELETE = OAuthMessage.DELETE;
    protected static final String CONTENT_LENGTH = HttpMessage.CONTENT_LENGTH;

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区视频在线观看| 99视频有精品| 欧美一区二区三区免费在线看| 一区二区三国产精华液| 在线观看视频欧美| 午夜视频在线观看一区| 91精品国产黑色紧身裤美女| 久久电影国产免费久久电影 | eeuss鲁一区二区三区| 亚洲激情在线激情| 91丨九色porny丨蝌蚪| 中文字幕精品三区| 色哟哟在线观看一区二区三区| 亚洲欧美乱综合| 欧美日韩在线播| 久久黄色级2电影| 国产精品理论在线观看| 欧美性视频一区二区三区| 日本欧美在线观看| 国产丝袜在线精品| 欧美日韩久久久一区| 麻豆一区二区99久久久久| 国产免费观看久久| 精品视频一区二区三区免费| 久久精品理论片| 中文字幕一区免费在线观看| 欧美精品第1页| 高潮精品一区videoshd| 亚洲va欧美va天堂v国产综合| 日韩精品一区二区三区视频播放| 成人妖精视频yjsp地址| 午夜免费欧美电影| 国产精品另类一区| 91精品国产入口| 国产成人免费在线观看| 日日欢夜夜爽一区| 中文字幕中文字幕中文字幕亚洲无线 | 精品视频在线免费| 国产激情视频一区二区三区欧美| 亚洲一区影音先锋| 国产无一区二区| 欧美精品日韩综合在线| 成人白浆超碰人人人人| 国产剧情一区二区三区| 亚洲精品亚洲人成人网在线播放| 精品少妇一区二区三区在线播放 | 欧亚一区二区三区| 国产一区999| 免费在线观看成人| 一区二区三区日韩欧美精品| 国产香蕉久久精品综合网| 欧美日韩一区二区三区在线看 | 色哟哟一区二区| 国产一区二区91| 日韩电影在线免费| 亚洲综合久久av| 中文字幕在线免费不卡| 久久精品欧美一区二区三区不卡 | 日本不卡在线视频| 亚洲影院理伦片| 亚洲欧美色图小说| 中文字幕一区二区不卡| 国产欧美日韩视频在线观看| 欧美va亚洲va国产综合| 欧美一区二区精品| 欧美日韩午夜在线| 欧美亚洲综合在线| 91久久精品国产91性色tv| 99久久久久久| 福利一区二区在线观看| 国产精品小仙女| 国产精品香蕉一区二区三区| 久久99精品久久只有精品| 日本少妇一区二区| 久久精品国产色蜜蜜麻豆| 六月丁香婷婷色狠狠久久| 日韩高清中文字幕一区| 日本伊人色综合网| 欧美a级理论片| 欧美aaa在线| 久久精品国产久精国产| 久久超级碰视频| 国产精选一区二区三区| 国产精品综合在线视频| 成人午夜激情在线| 福利一区二区在线| 91丝袜美女网| 日本韩国欧美三级| 欧美精品xxxxbbbb| 欧美va亚洲va在线观看蝴蝶网| 日韩三级视频中文字幕| 欧美成人vps| 亚洲国产高清在线| 夜色激情一区二区| 亚洲福利一区二区三区| 日本不卡的三区四区五区| 精品一区二区在线视频| 国产v综合v亚洲欧| 91麻豆免费看片| 69堂精品视频| 久久久久久亚洲综合影院红桃| 久久久久九九视频| 亚洲六月丁香色婷婷综合久久| 亚洲一线二线三线视频| 男男成人高潮片免费网站| 国产成人av一区二区三区在线| 波多野结衣中文字幕一区| 欧美色综合网站| www久久精品| 亚洲男人天堂av网| 免播放器亚洲一区| 不卡一区中文字幕| 91 com成人网| 欧美激情在线看| 肉肉av福利一精品导航| 成人动漫一区二区在线| 欧美日韩黄色一区二区| 欧美国产视频在线| 丝袜亚洲另类欧美综合| 丁香六月久久综合狠狠色| 欧美午夜免费电影| 国产欧美日韩不卡| 午夜视黄欧洲亚洲| 成人午夜免费av| 欧美一级片在线| 亚洲男同性恋视频| 国产精品主播直播| 91精品久久久久久久久99蜜臂| 国产精品―色哟哟| 免费欧美高清视频| 亚洲 欧美综合在线网络| 久久99国产精品尤物| 欧美亚洲图片小说| 久久综合久久鬼色| 亚洲高清视频的网址| 国产电影一区在线| 日韩欧美美女一区二区三区| 亚洲欧美日韩国产手机在线| 国产成人亚洲精品狼色在线| 91精品国产乱码久久蜜臀| 亚洲美腿欧美偷拍| 国产成人在线视频免费播放| 91精品国产一区二区三区蜜臀| 亚洲人成伊人成综合网小说| 老司机午夜精品| 欧美日韩一区二区不卡| 亚洲精品视频在线看| 丰满白嫩尤物一区二区| 久久综合久久综合九色| 毛片av一区二区三区| 777奇米成人网| 亚洲国产cao| 欧美午夜寂寞影院| 一区二区三区在线观看欧美| 91色.com| 亚洲精品成a人| 色av一区二区| 亚洲综合清纯丝袜自拍| 日本韩国一区二区三区视频| 亚洲免费伊人电影| 色婷婷综合五月| 亚洲精品成人a在线观看| 91精品福利在线| 一区二区三区成人| 不卡免费追剧大全电视剧网站| 久久婷婷国产综合精品青草| 麻豆国产欧美一区二区三区| 欧美一三区三区四区免费在线看| 视频精品一区二区| 欧美一级精品在线| 毛片av中文字幕一区二区| 精品福利一二区| 国产一区在线不卡| 国产日本一区二区| 成人不卡免费av| 亚洲免费在线观看| 欧美日韩中文字幕一区| 日韩成人精品在线| 精品免费日韩av| 国产毛片精品视频| 中文字幕一区二区三区视频| 色综合天天综合在线视频| 一区二区三区电影在线播| 欧美日韩一本到| 久久国产夜色精品鲁鲁99| 久久免费美女视频| 成人激情小说乱人伦| 一区二区三区欧美| 制服丝袜中文字幕一区| 国产在线精品免费| 国产精品久久午夜夜伦鲁鲁| 色偷偷久久人人79超碰人人澡| 丝袜亚洲另类欧美| 337p日本欧洲亚洲大胆精品| 处破女av一区二区| 亚洲va欧美va天堂v国产综合| 日韩欧美专区在线| 豆国产96在线|亚洲| 亚洲国产一区视频| 久久这里都是精品|