當前位置: 首頁>>代碼示例>>Java>>正文


Java Request.setCookies方法代碼示例

本文整理匯總了Java中org.restlet.Request.setCookies方法的典型用法代碼示例。如果您正苦於以下問題:Java Request.setCookies方法的具體用法?Java Request.setCookies怎麽用?Java Request.setCookies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.restlet.Request的用法示例。


在下文中一共展示了Request.setCookies方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: callAuthPageServerResource

import org.restlet.Request; //導入方法依賴的package包/類
/**
 * AuthPageServerResourceを実行する.
 * 
 * @param sessionId セッションID
 * @param scopes スコープ
 * @param applicationName アプリケーション名
 * @return 戻り値(RedirectRepresentation)
 */
private static RedirectRepresentation callAuthPageServerResource(final String sessionId,
        final ArrayList<Scope> scopes, final String applicationName) {

    Series<Cookie> cookies = new Series<>(Cookie.class);
    cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId);

    // scopesを文字列配列に変換する
    ArrayList<String> strScopes = ScopeUtil.scopesToStrings(scopes);
    
    ArrayList<String> actions = new ArrayList<>();
    actions.add(AuthPageServerResource.ACTION_ACCEPT);
    
    ArrayList<String> applicationNames = new ArrayList<>();
    applicationNames.add(applicationName);
    
    AuthPageServerResource.getQuery().put(AuthPageServerResource.SCOPE, strScopes);
    AuthPageServerResource.getQuery().put(AuthPageServerResource.GRANTED_SCOPE, new ArrayList<String>());
    AuthPageServerResource.getQuery().put(AuthPageServerResource.ACTION, actions);
    AuthPageServerResource.getQuery().put(AuthPageServerResource.APPLICATION_NAME, applicationNames);

    Request request = new Request();
    request.setCookies(cookies);
    Response response = new Response(request);
    AuthPageServerResource.init(request, response);

    RedirectRepresentation redirectRepresentation = null;
    try {
        Representation representation = AuthPageServerResource.showPage();
        if (representation != null) {
            if (representation instanceof RedirectRepresentation) {
                redirectRepresentation = (RedirectRepresentation) representation;
            }
        }
    } catch (OAuthException e) {
        e.printStackTrace();
    }

    return redirectRepresentation;
}
 
開發者ID:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:48,代碼來源:LocalOAuth2Main.java

示例2: callAuthorizationServerResource

import org.restlet.Request; //導入方法依賴的package包/類
/**
 * AuthorizationServerResourceを実行.
 * 
 * @param client クライアント情報
 * @param initialize 初期化フラグ(trueにするとContextを初期化する)
 * @param sessionId セッションID(引き継ぐセッションIDが存在すれば指定する、無ければnullを設定する)
 * @return not null: RedirectRepresentation型の戻り値を返す / null: エラー
 * @throws AuthorizationException Authorization例外.
 */
private static RedirectRepresentation callAuthorizationServerResource(final Client client,
        final boolean initialize, final String sessionId) throws AuthorizationException {

    // AuthorizationServerResourceを初期化する
    if (initialize) {
        Context context = new Context(sLogger);
        AuthorizationServerResource.init(context);
    }

    // request, responseを初期化 *
    Request request = new Request();
    request.setOriginalRef(new Reference(DUMMY_ORIGINAL_REF));
    Response response = new Response(request);
    request.setResourceRef(new Reference(DUMMY_REFERENCE));

    // セッションIDが指定されていたらRequestに設定する
    if (sessionId != null) {
        Series<Cookie> cookies = new Series<>(Cookie.class);
        cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId);
        request.setCookies(cookies);
    }

    AuthorizationServerResource.init(request, response, sClientManager, sTokenManager);
    
    // Formに設定する
    Form paramsA = new Form();
    paramsA.add(AuthorizationServerResource.CLIENT_ID, client.getClientId());
    paramsA.add(AuthorizationServerResource.REDIR_URI, DUMMY_REDIRECT_URI);
    paramsA.add(AuthorizationServerResource.RESPONSE_TYPE, "code");
    paramsA.add(AuthorizationServerResource.SCOPE, DUMMY_SCOPE1);

    /// requestAuthorizationを実行する
    Representation representationA;
    try {
        representationA = AuthorizationServerResource.requestAuthorization(paramsA);
    } catch (OAuthException e) {
        throw new AuthorizationException(e);
    }

    // 正常終了(ログイン畫麵リダイレクト)
    if (representationA instanceof RedirectRepresentation) {
        return (RedirectRepresentation) representationA;
    }

    return null;
}
 
開發者ID:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:56,代碼來源:LocalOAuth2Main.java

示例3: callLoginPageServerResource

import org.restlet.Request; //導入方法依賴的package包/類
/**
 * LoginPageServerResourceを実行する.
 * 
 * @param userId ユーザーID
 * @param password パスワード
 * @return 戻り値(ResultRepresentation)
 */
private static ResultRepresentation callLoginPageServerResource(final String userId, final String password) {
    // 前の処理からセッションIDを引き継ぐ
    String sessionId = AuthorizationServerResource.getSessionId();
    Series<Cookie> cookies = new Series<>(Cookie.class);
    cookies.add(AuthorizationBaseServerResource.ClientCookieID, sessionId);

    // (B)の処理
    LoginPageServerResource.initResult();
    Request request = new Request();
    Reference requestReference = new Reference(DUMMY_ORIGINAL_REF);
    requestReference.addQueryParameter(LoginPageServerResource.USER_ID, userId);
    requestReference.addQueryParameter(LoginPageServerResource.PASSWORD, password);
    requestReference.addQueryParameter(LoginPageServerResource.CONTINUE,
            RedirectRepresentation.RedirectProc.requestAuthorization.toString());

    // QueryParameterとは別の変數に値を入れているので、直接値を設定する
    ArrayList<String> userIds = new ArrayList<>();
    userIds.add(userId);
    ArrayList<String> passwords = new ArrayList<>();
    passwords.add(password);
    ArrayList<String> continues = new ArrayList<>();
    continues.add(RedirectRepresentation.RedirectProc.requestAuthorization.toString());

    LoginPageServerResource.getQuery().put(LoginPageServerResource.USER_ID, userIds);
    LoginPageServerResource.getQuery().put(LoginPageServerResource.PASSWORD, passwords);
    LoginPageServerResource.getQuery().put(LoginPageServerResource.CONTINUE, continues);

    request.setCookies(cookies);
    request.setOriginalRef(requestReference);
    request.setResourceRef(requestReference);
    Response response = new Response(request);
    LoginPageServerResource.init(request, response);
    ResultRepresentation resultRepresentation;
    try {
        resultRepresentation = (ResultRepresentation) LoginPageServerResource.getPage();
    } catch (OAuthException e) {
        resultRepresentation = new ResultRepresentation();
        resultRepresentation.setResult(false);
        resultRepresentation.setError(e.getMessage(), e.getErrorDescription());
    }

    return resultRepresentation;
}
 
開發者ID:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:51,代碼來源:LocalOAuth2Main.java


注:本文中的org.restlet.Request.setCookies方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。