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


Java Response.getStatus方法代碼示例

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


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

示例1: httpError

import retrofit.client.Response; //導入方法依賴的package包/類
private static void httpError(int expectedStatus, Response response) throws CommandException {
    if (null == response) {
        throw new IllegalArgumentException("Response was null");
    }

    // obtain response body
    String body = null;

    if (null != response.getBody()) {
        try (InputStream errStream = response.getBody().in()) {
            body = CharStreams.toString(new InputStreamReader(errStream));
        } catch (IOException ignored) {
        }
    }

    throw new CommandException("HTTP " + response.getStatus() + " "
            + response.getReason() + " but expected " + expectedStatus + ":\n" + body);
}
 
開發者ID:apiman,項目名稱:apiman-cli,代碼行數:19,代碼來源:ManagementApiUtil.java

示例2: handleError

import retrofit.client.Response; //導入方法依賴的package包/類
@Override
public Throwable handleError(RetrofitError cause) {
    Response r = cause.getResponse();
    if (r != null) {
        switch (r.getStatus()) {
            case 500:
                Log.d(TAG, "500 error during request to " + r.getUrl());
                return new ServerErrorException(cause.getMessage());
            case 403:
                Log.d(TAG, "403 error during request to " + r.getUrl());
                return new ForbiddenException(cause.getMessage());
            case 404:
                Log.d(TAG, "404 error during request to " + r.getUrl());
                return new NotFoundException(cause.getMessage());
            case 400:
                Log.d(TAG, "400 error during request to " + r.getUrl());
                return new BadRequestException(cause.getMessage());
        }
    }

    return cause;
}
 
開發者ID:EnlightNS,項目名稱:enlightns-android,代碼行數:23,代碼來源:EnlightnsAPIHelper.java

示例3: getErrorMessage

import retrofit.client.Response; //導入方法依賴的package包/類
public static String getErrorMessage(Response response) {
    String text = responseToString(response);
    try {
        JSONObject object = new JSONObject(text);
        if (object.has("errors")) {
            JSONArray errors = object.getJSONArray("errors");
            if (errors.length() > 0) {
                JSONObject error = errors.getJSONObject(0);
                if (error.has("message")) {
                    return error.getString("message");
                }
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
        Log.e("Api", "getErrorMessage: "+text );
    }
    if (response.getStatus() > 500) {
        return App.getContext().getString(R.string.check_network);
    }
    return null;
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:23,代碼來源:ApiFactory.java

示例4: register

import retrofit.client.Response; //導入方法依賴的package包/類
private void register(final boolean legacy) {
    try {
        if (legacy) {
            collectorRegistrationService.legacyRegister(this.collectorId, this.collectorRegistrationRequest);
        } else {
            collectorRegistrationService.register(this.collectorId, this.collectorRegistrationRequest);
        }
    } catch (RetrofitError e) {
        final Response response = e.getResponse();
        if (response != null) {
            if (!legacy && response.getStatus() == 404) {
                // Try again with the Graylog 1.x URL if we didn't try yet.
                register(true);
            } else {
                LOG.warn("Unable to send heartbeat to Graylog server, result was: {} - {}", response.getStatus(), response.getReason());
            }
        } else {
            final String message;
            if (e.getCause() != null) {
                message = e.getCause().getClass().getSimpleName() + ": " + e.getCause().getMessage();
            } else {
                message = e.getClass().getSimpleName() + ": " + e.getMessage();
            }
            LOG.warn("Unable to send heartbeat to Graylog server: {}", message);
        }
    }
}
 
開發者ID:DevOpsStudio,項目名稱:Re-Collector,代碼行數:28,代碼來源:HeartbeatService.java

示例5: intercept

import retrofit.client.Response; //導入方法依賴的package包/類
@Override
public void intercept(RequestFacade request) {
    if (!loggedIn) {
        try {
            FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
            to.addField("username", username);
            to.addField("password", password);
            to.addField("grant_type", "password");

            String base64Auth = BaseEncoding.base64().encode(new String(clientId + ":" + clientSecret).getBytes());
            List<Header> headers = new ArrayList<Header>();
            headers.add(new Header("Authorization", "Basic " + base64Auth));

            Request req = new Request("POST", tokenIssuingEndpoint, headers, to);

            Response resp = client.execute(req);

            if (resp.getStatus() < 200 || resp.getStatus() > 299) {
                throw new SecuredRestException("Login failure: "
                        + resp.getStatus() + " - " + resp.getReason());
            } else {
                String body = IOUtils.toString(resp.getBody().in());
                accessToken = new Gson().fromJson(body, JsonObject.class).get("access_token").getAsString();
                request.addHeader("Authorization", "Bearer " + accessToken);
                loggedIn = true;
            }
        } catch (Exception e) {
            throw new SecuredRestException(e);
        }
    } else {
        request.addHeader("Authorization", "Bearer " + accessToken);
    }
}
 
開發者ID:kflauri2312lffds,項目名稱:Android_watch_magpie,代碼行數:34,代碼來源:SecuredRestBuilder.java

示例6: handleError

import retrofit.client.Response; //導入方法依賴的package包/類
@Override
public Throwable handleError(RetrofitError cause) {
    Response r = cause.getResponse();
    if (r != null) {
        if (r.getStatus() == 401) {
            return new OAuthUnauthorizedException(cause);
        }
        if (r.getUrl().endsWith("/checkin") && r.getStatus() == 409) {
            return new CheckinInProgressException(cause);
        }
    }
    return cause;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:14,代碼來源:TraktErrorHandler.java

示例7: waitForServer

import retrofit.client.Response; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void waitForServer(int waitTime) {
    if (waitTime == 0) {
        return;
    }

    LOGGER.info("Waiting {} seconds for server to start...", waitTime);
    final StatusApi apiClient = buildServerApiClient(StatusApi.class);

    final long start = System.currentTimeMillis();
    while (true) {
        if (System.currentTimeMillis() - start > waitTime * 1000) {
            throw new CommandException("Timed out after " + waitTime + " seconds waiting for server to start");
        }

        try {
            final Response response = apiClient.checkStatus();
            if (HttpURLConnection.HTTP_OK == response.getStatus()) {
                LOGGER.info("Server started");
                break;
            }

            Thread.sleep(STATUS_CHECK_INTERVAL);
        } catch (Exception ignored) {
        }
    }
}
 
開發者ID:apiman,項目名稱:apiman-cli,代碼行數:31,代碼來源:ManagementApiServiceImpl.java

示例8: invokeAndCheckResponse

import retrofit.client.Response; //導入方法依賴的package包/類
public static void invokeAndCheckResponse(int expectedStatus, Supplier<Response> request) throws CommandException {
    try {
        // invoke the request
        final Response response = request.get();

        // check response code is successful
        if (response.getStatus() != expectedStatus) {
            httpError(expectedStatus, response);
        }

    } catch (RetrofitError e) {
        httpError(expectedStatus, e.getResponse());
    }
}
 
開發者ID:apiman,項目名稱:apiman-cli,代碼行數:15,代碼來源:ManagementApiUtil.java

示例9: shouldResendRequest

import retrofit.client.Response; //導入方法依賴的package包/類
public static boolean shouldResendRequest(Exception e) {
    if (e != null && e instanceof RetrofitError) {
        Response response = ((RetrofitError) e).getResponse();
        int status = -1;
        if (response != null) status = response.getStatus();
        return status == 429 || status == 502 || status == 520;
    } else return false;
}
 
開發者ID:TheAndroidMaster,項目名稱:Pasta-for-Spotify,代碼行數:9,代碼來源:StaticUtils.java

示例10: updateFollowingStatus

import retrofit.client.Response; //導入方法依賴的package包/類
private void updateFollowingStatus(Response response) {
    stopMenuLoading();
    if (response.getStatus() == 204) {
        mIsFollowing = true;
    } else if (response.getStatus() == 404) {
        mIsFollowing = false;
    }

    mFollowMenu.setChecked(mIsFollowing);
    mFollowMenu.setTitle(mIsFollowing ? R.string.action_unfollow : R.string.action_follow);
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:12,代碼來源:TeamFragment.java

示例11: checkUnfollowingRes

import retrofit.client.Response; //導入方法依賴的package包/類
private void checkUnfollowingRes(Response res) {
    stopMenuLoading();

    if (res.getStatus() == 204) {
        swapFollowStatus();
    }
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:8,代碼來源:TeamFragment.java

示例12: checkFollowingRes

import retrofit.client.Response; //導入方法依賴的package包/類
private void checkFollowingRes(Response res) {
    stopMenuLoading();
    if (res.getStatus() == 204) {
        swapFollowStatus();
    }
    TypedInput body = res.getBody();
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:8,代碼來源:TeamFragment.java

示例13: bucketCreated

import retrofit.client.Response; //導入方法依賴的package包/類
private void bucketCreated(Response data) {
    Activity activity = getActivity();
    if (activity == null) {
        return;
    }
    UiUtils.dismissDialog(mDialog);
    if (data.getStatus() == 202) {
        UiUtils.showToast(activity, R.string.shot_created);
        activity.setResult(Activity.RESULT_OK);
        activity.finish();
    }
}
 
開發者ID:goodev,項目名稱:droidddle,代碼行數:13,代碼來源:CreateShotFragment.java

示例14: handleError

import retrofit.client.Response; //導入方法依賴的package包/類
@Override
public Throwable handleError(final RetrofitError cause) {
  Response r = cause.getResponse();
  if (r != null && r.getStatus() >= 400) {
    try (InputStreamReader reader = new InputStreamReader(r.getBody().in(), Charsets.UTF_8)) {
      return new RuntimeException(CharStreams.toString(reader));
    } catch (IOException ioe) {
      logger.error("IOException during stream read: " + ioe.getMessage(), ioe);
    }
  }
  return cause;
}
 
開發者ID:nkiraly,項目名稱:influxdb-inflow,代碼行數:13,代碼來源:InfluxDBHTTPErrorHandler.java

示例15: handleError

import retrofit.client.Response; //導入方法依賴的package包/類
@Override
public Throwable handleError(RetrofitError error) {
    logger.debug("error: "+error.getKind());
    if (error.getKind().equals(RetrofitError.Kind.NETWORK)) {
        // Phone is not connected at all
        return new NoConnectivityException(context.getString(R.string.no_internet_connection));
    }

    if (error.getKind().equals(RetrofitError.Kind.CONVERSION)) {
        // Web services usually return JSON, so the phone is probably trying to use mobile data without credit
        return new NoConnectivityException(context.getString(R.string.no_internet_connection_mobile_out_of_credit));
    }

    Response response = error.getResponse();
    String errorDescription = "Unknown Retrofit error";

    if (response == null) {
        return error;
    }

    switch (response.getStatus()) {
        case HttpStatus.SC_BAD_REQUEST:
            // 404 returned from the server means there is no matching data
            errorDescription = error.getMessage().replace("400", "");
            break;

        case  HttpStatus.SC_UNAUTHORIZED:
            //return new UnauthorizedException(error);

        case HttpStatus.SC_NOT_FOUND:
            if (!TextUtils.isEmpty(error.getMessage())) {
                // 404 returned from the server means there is no matching data
                errorDescription = error.getMessage().replace("404", "");
            }
            break;

        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            if (!TextUtils.isEmpty(error.getMessage())) {
                // 500 returned from the server means the server error
                errorDescription = error.getMessage().replace("500", "");
            }
            break;

        case HttpStatus.SC_SERVICE_UNAVAILABLE:
            return new NoConnectivityException("Server is not responding");

        default:
            try {
                errorDescription = context.getString(R.string.error_network_http_error, error.getResponse().getStatus());
            } catch (Exception ex2) {
                logger.error("handleError: " + ex2.getLocalizedMessage());
                errorDescription = context.getString(R.string.error_unknown);
            }
            break;
    }


    //return error;
    return new Exception(errorDescription);
}
 
開發者ID:manishpatelgt,項目名稱:MyTwitterRepo,代碼行數:61,代碼來源:RetrofitErrorHandler.java


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