本文整理了Java中retrofit.client.Response.getHeaders
方法的一些代码示例,展示了Response.getHeaders
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getHeaders
方法的具体详情如下:
包路径:retrofit.client.Response
类名称:Response
方法名:getHeaders
[英]An unmodifiable collection of headers.
[中]标题的不可修改的集合。
代码示例来源:origin: gitskarios/GithubAndroidSdk
public int getLinkData(Response r) {
List<Header> headers = r.getHeaders();
Map<String, String> headersMap = new HashMap<String, String>(headers.size());
for (Header header : headers) {
headersMap.put(header.getName(), header.getValue());
}
String link = headersMap.get("Link");
if (link != null) {
String[] parts = link.split(",");
try {
PaginationLink bottomPaginationLink = new PaginationLink(parts[0]);
if (bottomPaginationLink.rel == RelType.next) {
return bottomPaginationLink.page;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return -1;
}
}
代码示例来源:origin: spinnaker/fiat
private void handleNon404s(RetrofitError e) {
String msg = "";
if (e.getKind() == RetrofitError.Kind.NETWORK) {
msg = String.format("Could not find the server %s", gitHubProperties.getBaseUrl());
} else if (e.getResponse().getStatus() == 401) {
msg = "HTTP 401 Unauthorized.";
} else if (e.getResponse().getStatus() == 403) {
val rateHeaders = e.getResponse()
.getHeaders()
.stream()
.filter(header -> RATE_LIMITING_HEADERS.contains(header.getName()))
.map(Header::toString)
.collect(Collectors.toList());
msg = "HTTP 403 Forbidden. Rate limit info: " + StringUtils.join(rateHeaders, ", ");
}
log.error(msg, e);
}
代码示例来源:origin: fullcontact/fullcontact4j
for (Header h : response.getHeaders()) {
if (FCConstants.HEADER_RATE_LIMIT_PER_MINUTE.equals(h.getName())) {
maxRequestsPerSecond = Integer.parseInt(h.getValue()) / 60;
Utils.info("Error extracting rate limit headers: " + response.getHeaders());
return null;
Utils.info("Missing rate limit headers info, not including in response. Raw Headers: " + response.getHeaders());
return null;
代码示例来源:origin: gitskarios/GithubAndroidSdk
@Override
public Response execute(Request request) throws IOException {
Response response = super.execute(request);
try {
for (Header header : response.getHeaders()) {
if (header.getName().equals("Link")) {
String[] parts = header.getValue().split(",");
for (String part : parts) {
PaginationLink bottomPaginationLink = new PaginationLink(part);
if (bottomPaginationLink.rel == RelType.last) {
baseClient.last = bottomPaginationLink.uri;
baseClient.lastPage = bottomPaginationLink.page;
} else if (bottomPaginationLink.rel == RelType.next) {
baseClient.next = bottomPaginationLink.uri;
baseClient.nextPage = bottomPaginationLink.page;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
}
代码示例来源:origin: com.github.heuermh.ensemblrestclient/ensembl-rest-client
/**
* Return the number of seconds before the rate limit resets, or <code>-1</code> if the exception was not
* the result of a HTTP 429 Too Many Requests rate limit error.
*
* @since 1.5
* @see #isRateLimitError
* @return the number of seconds before the rate limit resets, or <code>-1</code> if the exception was not
* the result of a HTTP 429 Too Many Requests rate limit error
*/
public long getRateLimitReset()
{
if (retrofitError.getResponse() == null)
{
return -1;
}
for (Header header : retrofitError.getResponse().getHeaders())
{
if ("X-RateLimit-Reset".equals(header.getName()))
{
return Long.parseLong(header.getValue());
}
}
return -1;
}
}
代码示例来源:origin: com.squareup.retrofit/retrofit
static Response replaceResponseBody(Response response, TypedInput body) {
return new Response(response.getUrl(), response.getStatus(), response.getReason(),
response.getHeaders(), body);
}
代码示例来源:origin: com.hp.autonomy.hod/java-hod-client
private <E extends EntityType, T extends TokenType> void checkRefresh(final TokenProxy<E, T> tokenProxy, final Response response) {
final List<Header> headers = response.getHeaders();
for(final Header header : headers) {
if(TOKEN_HEADER_NAME.equals(header.getName())) {
try {
final AuthenticationToken.Json parsedHeader = objectMapper.readValue(header.getValue(), AuthenticationToken.Json.class);
final AuthenticationToken<E, T> token = parsedHeader.buildToken(tokenProxy.getEntityType(), tokenProxy.getTokenType());
tokenRepository.update(tokenProxy, token);
} catch (final IOException e) {
throw new TokenRepositoryException(e);
}
break;
}
}
}
代码示例来源:origin: gitskarios/GithubAndroidSdk
@Override
protected Observable<Pair<User, String>> getApiObservable(RestAdapter restAdapter) {
return restAdapter.create(UsersService.class).me().onErrorResumeNext(throwable -> {
if (throwable instanceof RetrofitError) {
Response response = ((RetrofitError) throwable).getResponse();
if (response != null && response.getStatus() == 401) {
List<Header> headers = response.getHeaders();
if (headers != null) {
for (Header header : headers) {
if (header.getName().equals("X-GitHub-OTP") && header.getValue()
.contains("required")) {
return Observable.error(new TwoFactorAuthException());
}
}
return Observable.error(new UnauthorizedException());
}
}
}
return Observable.error(throwable);
}).map(user -> new Pair<>(user, getToken()));
}
代码示例来源:origin: gitskarios/GithubAndroidSdk
@Override
protected Observable<GithubAuthorization> getApiObservable(RestAdapter restAdapter) {
return restAdapter.create(LoginService.class)
.createAuthorization(createAuthorization)
.onErrorResumeNext(throwable -> {
if (throwable instanceof RetrofitError) {
Response response = ((RetrofitError) throwable).getResponse();
if (response != null && response.getStatus() == 401) {
List<Header> headers = response.getHeaders();
if (headers != null) {
for (Header header : headers) {
if (header.getName().equals("X-GitHub-OTP") && header.getValue()
.contains("required")) {
String value = header.getValue();
if (value.contains("app")) {
return Observable.error(new TwoFactorAppException());
} else {
return Observable.error(new TwoFactorAuthException());
}
}
}
return Observable.error(new UnauthorizedException());
}
}
}
return Observable.error(throwable);
});
}
代码示例来源:origin: com.squareup.retrofit/retrofit
for (Header header : response.getHeaders()) {
log.log(header.toString());
if (!response.getHeaders().isEmpty()) {
log.log("");
内容来源于网络,如有侵权,请联系作者删除!