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


Java HttpRequest.HttpRequestException方法代碼示例

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


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

示例1: uploadMeasurements

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
@Override
public RequestResult uploadMeasurements(String content) {
    Log.d("uploadMeasurements(): Sending post request");
    try {
        HttpRequest request = HttpRequest.post(url)
                .followRedirects(false)
                .connectTimeout(CONN_TIMEOUT)
                .readTimeout(READ_TIMEOUT);
        // add API key
        request.part("key", apiKey);
        // add app name
        request.part("appId", appId);
        // add file data as file
        request.part("datafile", "TowerCollector_measurements_" + System.currentTimeMillis() + ".csv", "text/csv", content);
        return handleResponse(request.code(), request.body());
    } catch (HttpRequest.HttpRequestException ex) {
        Log.d("uploadMeasurements(): Errors encountered", ex);
        reportExceptionWithSuppress(ex);
        return RequestResult.Failure;
    }
}
 
開發者ID:zamojski,項目名稱:TowerCollector,代碼行數:22,代碼來源:OcidUploadClient.java

示例2: makeRequest

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, String body, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);
    String cookies = accountManager.getCookies(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken, cookies);
    if (body != "") {
        request.send(body);
    }

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, body, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}
 
開發者ID:tdb-alcorn,項目名稱:defect-party,代碼行數:41,代碼來源:APIUtility.java

示例3: fetchUpdates

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
public String fetchUpdates() {
    Log.d("fetchUpdates(): Sending get request");
    try {
        HttpRequest request = HttpRequest.get(url)
                .followRedirects(false)
                .connectTimeout(CONN_TIMEOUT)
                .readTimeout(READ_TIMEOUT);
        return handleResponse(request.code(), request.body());
    } catch (HttpRequest.HttpRequestException ex) {
        Log.d("fetchUpdates(): Errors encountered", ex);
        reportExceptionWithSuppress(ex);
        return null;
    }
}
 
開發者ID:zamojski,項目名稱:TowerCollector,代碼行數:15,代碼來源:UpdateClient.java

示例4: reportExceptionWithSuppress

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
protected void reportExceptionWithSuppress(HttpRequest.HttpRequestException ex) {
    Throwable originalException = ex.getCause();
    // suppress known exceptions
    if (originalException instanceof UnknownHostException
            || originalException instanceof SocketTimeoutException
            || originalException instanceof SocketException
            || originalException instanceof EOFException) {
        return;
    }
    reportException(ex);
}
 
開發者ID:zamojski,項目名稱:TowerCollector,代碼行數:12,代碼來源:ClientBase.java

示例5: makeRequest

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken);

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}
 
開發者ID:kalemontes,項目名稱:OIDCAndroidLib,代碼行數:37,代碼來源:APIUtility.java

示例6: sendBody

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
public static void sendBody(final Request request, final HttpRequest httpRequest) throws IOException {
    final String requestMethod = request.getMethod();
    final TypedOutput requestBody = request.getBody();

    // Only POST and PUT has body as far as I know
    if ((METHOD_POST.equals(requestMethod)) || METHOD_PUT.equals(requestMethod)) {

        if (requestBody != null) {

            // Content-Type
            httpRequest.contentType(requestBody.mimeType());

            // Payload
            ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
            requestBody.writeTo(outputBytes);
            byte[] dataBytes = outputBytes.toByteArray();

            try {
                httpRequest.send(dataBytes);
            } catch (HttpRequest.HttpRequestException hre) {
                // Throw original IOException since Retrofit handles this
                throw hre.getCause();
            }
        }

    }
}
 
開發者ID:groodt,項目名稱:http-request-retrofit-client,代碼行數:28,代碼來源:HttpRequestClient.java

示例7: exception

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
@Override
public boolean exception(Exception e, Context ctx, Object source) throws CocoException {
    if (e instanceof CocoException || e instanceof HttpRequest.HttpRequestException)
        e.printStackTrace();
    else
        Log.e(e);
    return false;
}
 
開發者ID:soarcn,項目名稱:COCOFramework,代碼行數:9,代碼來源:ExceptionManager.java

示例8: error

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void error(Exception e, Context ctx, Object source) {
    if (e instanceof CocoException || e instanceof HttpRequest.HttpRequestException)
        e.printStackTrace();
    else
        Log.e(e);
}
 
開發者ID:soarcn,項目名稱:COCOFramework,代碼行數:8,代碼來源:ExceptionManager.java

示例9: routeServer

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Route a server from remote
 */
void routeServer(){

    Map<String, Object> params = Maps.newHashMap();
    params.put("appName", client.getAppName());
    params.put("clientPid", SysUtil.pid());

    String[] serverList = client.getServers().split(",");

    for (String server : serverList){
        try {
            // request route server
            ServerRouteResp resp = doGet(server, ClientUris.SERVER_ROUTE, null, params, ServerRouteResp.class);
            if(resp == null){
                log.warn("server({}) route is null", server);
                continue;
            }

            String routedServer = resp.getServer();
            String clientId = resp.getClientId();


            // register to the routed server
            params.put("clientId", clientId);
            params.put("appKey", client.getAppKey());
            Boolean registerResp = doGet(routedServer, ClientUris.REGISTER, null, params, Boolean.class);
            if (registerResp == Boolean.FALSE){
                log.warn("failed to register server({})", routedServer);
                continue;
            }

            // set current server
            currentServer = routedServer;

            // set headers for next requests
            headers.put(Constants.CLIENT_ID_HEADER, clientId);
            headers.put(Constants.APP_KEY_HEADER, client.getAppKey());
            headers.put(Constants.CLIENT_VERSION_HEADER, CLIENT_VERSION);
            headers.put(Constants.PULLING_TIMEOUT_HEADER, String.valueOf(client.getPullingTimeout()));

            log.info("route successfully, current server is {}", currentServer);
            // route successfully
            return;
        } catch (HttpRequest.HttpRequestException e){
            log.warn("server({}) is unavailable, trying next server", server);
        }
    }
    throw new Server503Exception("all servers are unavailable: " + Arrays.toString(serverList));
}
 
開發者ID:ihaolin,項目名稱:diablo,代碼行數:52,代碼來源:DiabloAgent.java


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