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


Java AuthFailureError類代碼示例

本文整理匯總了Java中com.android.volley.AuthFailureError的典型用法代碼示例。如果您正苦於以下問題:Java AuthFailureError類的具體用法?Java AuthFailureError怎麽用?Java AuthFailureError使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: performRequest

import com.android.volley.AuthFailureError; //導入依賴的package包/類
/**
 * 請求執行
 * @param request the request to perform
 * @param additionalHeaders additional headers to be sent together with
 *         {@link Request#getHeaders()}
 * @return
 * @throws IOException
 * @throws AuthFailureError
 */
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    //傳入request 進行創建封裝過後的httprequest子類 httpurlrequest
    HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);
    addHeaders(httpRequest, additionalHeaders);
    addHeaders(httpRequest, request.getHeaders());
    onPrepareRequest(httpRequest);
    HttpParams httpParams = httpRequest.getParams();
    int timeoutMs = request.getTimeoutMs();
    // TODO: Reevaluate this connection timeout based on more wide-scale
    // data collection and possibly different for wifi vs. 3G.
    HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
    HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
    return mClient.execute(httpRequest);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:HttpClientStack.java

示例2: getAuthToken

import com.android.volley.AuthFailureError; //導入依賴的package包/類
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = this.mAccountManager.getAuthToken(this.mAccount, this.mAuthTokenType, this.mNotifyAuthFailure, null, null);
    try {
        Bundle result = (Bundle) future.getResult();
        String authToken = null;
        if (future.isDone() && !future.isCancelled()) {
            if (result.containsKey("intent")) {
                throw new AuthFailureError((Intent) result.getParcelable("intent"));
            }
            authToken = result.getString("authtoken");
        }
        if (authToken != null) {
            return authToken;
        }
        throw new AuthFailureError("Got null auth token for type: " + this.mAuthTokenType);
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:AndroidAuthenticator.java

示例3: placeJsonObjectRequest

import com.android.volley.AuthFailureError; //導入依賴的package包/類
/**
 * @param apiTag         tag to uniquely distinguish Volley requests. Null is allowed
 * @param url            URL to fetch the string at
 * @param httpMethod     the request method to use (GET or POST)
 * @param params         A {@link JSONObject} to post with the request. Null is allowed and
 *                       indicates no parameters will be posted along with request.
 * @param headers        optional Http headers
 * @param serverCallback Listener to receive the String response
 */
public void placeJsonObjectRequest(@Nullable final String apiTag, String url, int httpMethod, @Nullable JSONObject params, final @Nullable HashMap<String, String> headers, final ServerCallback serverCallback) {

    Request request = new JsonObjectRequest(httpMethod, url, params, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            serverCallback.onAPIResponse(apiTag, response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            serverCallback.onErrorResponse(apiTag, error);
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            return headers != null ? headers : super.getHeaders();
        }
    };

    request.setRetryPolicy(retryPolicy);

    addToRequestQueue(request);
}
 
開發者ID:ferozbaig96,項目名稱:VolleySimple,代碼行數:33,代碼來源:VolleySimple.java

示例4: getAuthToken

import com.android.volley.AuthFailureError; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
            mAuthTokenType, mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:AndroidAuthenticator.java

示例5: execute

import com.android.volley.AuthFailureError; //導入依賴的package包/類
public void execute() {
    final String url = URL + "/upvote";
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("username", mUsername);
            params.put("guid", mGuid);
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_NORMAL_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
 
開發者ID:Q115,項目名稱:Goalie_Android,代碼行數:24,代碼來源:RESTUpvote.java

示例6: getHeaders

import com.android.volley.AuthFailureError; //導入依賴的package包/類
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
    Map<String, String> headers = new HashMap<>();
    headers.put("Content-Type", getContentType());

    if (onInterceptRequest != null) {
        onInterceptRequest.interceptHeader(headers);
    }

    if (!settings.mapHeaders.isEmpty()) {
        for (Map.Entry<String, String> entry : settings.mapHeaders.entrySet()) {
            headers.put(entry.getKey(), entry.getValue());
        }
    }

    return headers;
}
 
開發者ID:giovanimoura,項目名稱:plainrequest,代碼行數:18,代碼來源:RequestCustom.java

示例7: performRequest

import com.android.volley.AuthFailureError; //導入依賴的package包/類
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws AuthFailureError {
    mLastUrl = request.getUrl();
    mLastHeaders = new HashMap<String, String>();
    if (request.getHeaders() != null) {
        mLastHeaders.putAll(request.getHeaders());
    }
    if (additionalHeaders != null) {
        mLastHeaders.putAll(additionalHeaders);
    }
    try {
        mLastPostBody = request.getBody();
    } catch (AuthFailureError e) {
        mLastPostBody = null;
    }
    return mResponseToReturn;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:MockHttpStack.java

示例8: execute

import com.android.volley.AuthFailureError; //導入依賴的package包/類
public void execute() {
    final String url = URL + "/register";
    isRegistering = true;
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public Map<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("username", mUsername);
            params.put("device", "android");
            params.put("pushID", mPushID);
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_EXTENDED_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
 
開發者ID:Q115,項目名稱:Goalie_Android,代碼行數:26,代碼來源:RESTRegister.java

示例9: execute

import com.android.volley.AuthFailureError; //導入依賴的package包/類
public void execute() {
    final String url = URL + "/remind";
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("fromUsername", mUsername);
            params.put("toUsername", mToUsername);
            params.put("guid", mGuid);
            params.put("isRemindingRef", isRemindingRef ? "1" : "0");
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_NORMAL_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
 
開發者ID:Q115,項目名稱:Goalie_Android,代碼行數:26,代碼來源:RESTRemind.java

示例10: setEntityIfNonEmptyBody

import com.android.volley.AuthFailureError; //導入依賴的package包/類
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
        Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
開發者ID:Ace201m,項目名稱:Codeforces,代碼行數:9,代碼來源:HttpClientStack.java

示例11: performRequest

import com.android.volley.AuthFailureError; //導入依賴的package包/類
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion,
            connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:41,代碼來源:HurlStack.java

示例12: performRequest

import com.android.volley.AuthFailureError; //導入依賴的package包/類
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);
    addHeaders(httpRequest, additionalHeaders);
    addHeaders(httpRequest, request.getHeaders());
    onPrepareRequest(httpRequest);
    HttpParams httpParams = httpRequest.getParams();
    int timeoutMs = request.getTimeoutMs();
    // TODO: Reevaluate this connection timeout based on more wide-scale
    // data collection and possibly different for wifi vs. 3G.
    HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
    HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
    return mClient.execute(httpRequest);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:HttpClientStack.java

示例13: addBodyIfExists

import com.android.volley.AuthFailureError; //導入依賴的package包/類
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        connection.setDoOutput(true);
        connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType());
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:HurlStack.java

示例14: resultContainsIntent

import com.android.volley.AuthFailureError; //導入依賴的package包/類
@Test(expected = AuthFailureError.class)
public void resultContainsIntent() throws Exception {
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    when(mAccountManager.getAuthToken(mAccount, "cooltype", false, null, null)).thenReturn(mFuture);
    when(mFuture.getResult()).thenReturn(bundle);
    when(mFuture.isDone()).thenReturn(true);
    when(mFuture.isCancelled()).thenReturn(false);
    mAuthenticator.getAuthToken();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:AndroidAuthenticatorTest.java

示例15: setEntityIfNonEmptyBody

import com.android.volley.AuthFailureError; //導入依賴的package包/類
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
                                            Request<?> request) throws AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        HttpEntity entity = new ByteArrayEntity(body);
        httpRequest.setEntity(entity);
    }
}
 
開發者ID:mobillium,項目名稱:omnicrow-android,代碼行數:9,代碼來源:OmniCrowHttpClientStack.java


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