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