当前位置: 首页>>代码示例>>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;未经允许,请勿转载。