com.ning.http.client.Response.getStatusCode()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中com.ning.http.client.Response.getStatusCode方法的一些代码示例,展示了Response.getStatusCode的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getStatusCode方法的具体详情如下:
包路径:com.ning.http.client.Response
类名称:Response
方法名:getStatusCode

Response.getStatusCode介绍

[英]Returns the status code for the request.
[中]返回请求的状态代码。

代码示例

代码示例来源:origin: alibaba/nacos

@Override
public Integer onCompleted(Response response) throws Exception {
  if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
    Loggers.RAFT.warn("[RAFT] failed to publish data to peer, datumId={}, peer={}, http code={}", datum.key, server, response.getStatusCode());
    return 1;
  }
  return 0;
}

代码示例来源:origin: alibaba/nacos

@Override
  public Integer onCompleted(Response response) throws Exception {
    if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
      Loggers.SRV_LOG.warn("[STATUS-SYNCHRONIZE] failed to request serverStatus, remote server: {}",
        serverIP);
      return 1;
    }
    return 0;
  }
});

代码示例来源:origin: alibaba/nacos

@Override
public Integer onCompleted(Response response) throws Exception {
  if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
    Loggers.RAFT.warn("[RAFT] failed to publish data to peer, datumId={}, peer={}, http code={}",
      datum.key, server, response.getStatusCode());
    return 1;
  }
  latch.countDown();
  return 0;
}

代码示例来源:origin: alibaba/nacos

@Override
  public Integer onCompleted(Response response) throws Exception {
    if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
      Loggers.SRV_LOG.warn("[STATUS-SYNCHRONIZE] failed to request domStatus, remote server: {}", serverIP);
      return 1;
    }
    return 0;
  }
});

代码示例来源:origin: alibaba/nacos

@Override
  public Integer onCompleted(Response response) throws Exception {
    if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
      Loggers.RAFT.warn("[RAFT] failed to delete data from peer, datumId={}, peer={}, http code={}", key, server, response.getStatusCode());
      return 1;
    }
    RaftPeer local = peers.local();
    local.resetLeaderDue();
    return 0;
  }
});

代码示例来源:origin: alibaba/nacos

@Override
  public Integer onCompleted(Response response) throws Exception {
    if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
      Loggers.RAFT.error("NACOS-RAFT vote failed: {}, url: {}", response.getResponseBody(), url);
      return 1;
    }
    RaftPeer peer = JSON.parseObject(response.getResponseBody(), RaftPeer.class);
    Loggers.RAFT.info("received approve from peer: {}", JSON.toJSONString(peer));
    peers.decideLeader(peer);
    return 0;
  }
});

代码示例来源:origin: apache/incubator-pinot

@Override
 public BrokerResponse get(long timeout, TimeUnit unit)
   throws ExecutionException {
  try {
   LOGGER.debug("Sending query {} to {}", _query, _url);
   Response httpResponse = _response.get(timeout, unit);
   LOGGER.debug("Completed query, HTTP status is {}", httpResponse.getStatusCode());
   if (httpResponse.getStatusCode() != 200) {
    throw new PinotClientException(
      "Pinot returned HTTP status " + httpResponse.getStatusCode() + ", expected 200");
   }
   String responseBody = httpResponse.getResponseBody();
   return BrokerResponse.fromJson(OBJECT_READER.readTree(responseBody));
  } catch (Exception e) {
   throw new ExecutionException(e);
  }
 }
}

代码示例来源:origin: alibaba/nacos

@Override
  public Integer onCompleted(Response response) throws Exception {
    if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
      Loggers.RAFT.error("[NACOS-RAFT] get peer failed: {}, peer: {}",
        response.getResponseBody(), peer.ip);
      peer.state = RaftPeer.State.FOLLOWER;
      return 1;
    }
    update(JSON.parseObject(response.getResponseBody(), RaftPeer.class));
    return 0;
  }
});

代码示例来源:origin: alibaba/nacos

@Override
public Integer onCompleted(Response response) throws Exception {
  if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
    Loggers.RAFT.error("NACOS-RAFT beat failed: {}, peer: {}",
      response.getResponseBody(), server);
    MetricsMonitor.getLeaderSendBeatFailedException().increment();
    return 1;
  }
  peers.update(JSON.parseObject(response.getResponseBody(), RaftPeer.class));
  Loggers.RAFT.info("receive beat response from: {}", url);
  return 0;
}

代码示例来源:origin: alibaba/nacos

@Override
public Integer onCompleted(Response response) throws Exception {
  if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
    return 1;

代码示例来源:origin: alibaba/nacos

@Override
public Integer onCompleted(Response response) throws Exception {
  ip.setCheckRT(System.currentTimeMillis() - startTime);
  int httpCode = response.getStatusCode();
  if (HttpURLConnection.HTTP_OK == httpCode) {
    checkOK(ip, task, "http:" + httpCode);
    reEvaluateCheckRT(System.currentTimeMillis() - startTime, task, Switch.getHttpHealthParams());
  } else if (HttpURLConnection.HTTP_UNAVAILABLE == httpCode || HttpURLConnection.HTTP_MOVED_TEMP == httpCode) {
    // server is busy, need verification later
    checkFail(ip, task, "http:" + httpCode);
    reEvaluateCheckRT(task.getCheckRTNormalized() * 2, task, Switch.getHttpHealthParams());
  } else {
    //probably means the state files has been removed by administrator
    checkFailNow(ip, task, "http:" + httpCode);
    reEvaluateCheckRT(Switch.getHttpHealthParams().getMax(), task, Switch.getHttpHealthParams());
  }
  return httpCode;
}

代码示例来源:origin: com.ning/async-http-client

public int getStatusCode() {
  return response.getStatusCode();
}

代码示例来源:origin: HubSpot/Singularity

@Override
public Response onCompleted(Response response) throws Exception {
 Optional<String> responseBody = Optional.absent();
 if (response.hasResponseBody()) {
  responseBody = Optional.of(response.getResponseBodyExcerpt(maxHealthcheckResponseBodyBytes));
 }
 saveResult(Optional.of(response.getStatusCode()), responseBody, Optional.<String> absent(), Optional.<Throwable>absent());
 return response;
}

代码示例来源:origin: com.ning/async-http-client

private void fireCompleted(Response response) {
    if (listener != null) {
      listener.onCompleted(uri, response.getStatusCode(), response.getStatusText());
    }
  }
}

代码示例来源:origin: HubSpot/Singularity

@Override
public Response onCompleted(Response response) throws Exception {
 LOG.trace("Webhook {} for {} completed with {} after {}", webhook.getUri(), update, response.getStatusCode(), JavaUtils.duration(start));
 if (response.hasResponseBody()) {
  LOG.trace("Webhook response message is: '{}'", response.getResponseBody());
 }
 if (JavaUtils.isHttpSuccess(response.getStatusCode()) || shouldDeleteUpdateOnFailure) {
  deleteWebhookUpdate();
 }
 if (completableFuture != null) {
  completableFuture.complete(response);
 }
 return response;
}

代码示例来源:origin: HubSpot/Singularity

private LoadBalancerUpdateHolder sendRequest(LoadBalancerRequestId loadBalancerRequestId, Request request, BaragonRequestState onFailure) {
 try {
  LOG.trace("Sending LB {} request for {} to {}", request.getMethod(), loadBalancerRequestId, request.getUrl());
  ListenableFuture<Response> future = httpClient.executeRequest(request);
  Response response = future.get(loadBalancerTimeoutMillis, TimeUnit.MILLISECONDS);
  LOG.trace("LB {} request {} returned with code {}", request.getMethod(), loadBalancerRequestId, response.getStatusCode());
  if (response.getStatusCode() == 504) {
   return new LoadBalancerUpdateHolder(BaragonRequestState.UNKNOWN, Optional.of(String.format("LB %s request %s timed out", request.getMethod(), loadBalancerRequestId)));
  } else if (!JavaUtils.isHttpSuccess(response.getStatusCode())) {
   return new LoadBalancerUpdateHolder(onFailure, Optional.of(String.format("Response status code %s", response.getStatusCode())));
  }
  BaragonResponse lbResponse = readResponse(response);
  return new LoadBalancerUpdateHolder(lbResponse.getLoadBalancerState(), lbResponse.getMessage());
 } catch (TimeoutException te) {
  LOG.trace("LB {} request {} timed out after waiting {}", request.getMethod(), loadBalancerRequestId, JavaUtils.durationFromMillis(loadBalancerTimeoutMillis));
  return new LoadBalancerUpdateHolder(BaragonRequestState.UNKNOWN, Optional.of(String.format("Timed out after %s", JavaUtils.durationFromMillis(loadBalancerTimeoutMillis))));
 } catch (Throwable t) {
  LOG.error("LB {} request {} to {} threw error", request.getMethod(), loadBalancerRequestId, request.getUrl(), t);
  return new LoadBalancerUpdateHolder(BaragonRequestState.UNKNOWN, Optional.of(String.format("Exception %s - %s", t.getClass().getSimpleName(), t.getMessage())));
 }
}

代码示例来源:origin: HubSpot/Singularity

if (response.getStatusCode() == 404) {
 return Optional.absent();
if (response.getStatusCode() != 200) {
 throw new RuntimeException(String.format("Got HTTP %s from Mesos slave", response.getStatusCode()));

代码示例来源:origin: HubSpot/Singularity

public Collection<MesosFileObject> browse(String slaveHostname, String fullPath) throws SlaveNotFoundException {
 try {
  PerRequestConfig timeoutConfig = new PerRequestConfig();
  timeoutConfig.setRequestTimeoutInMs((int) configuration.getSandboxHttpTimeoutMillis());
  Response response = asyncHttpClient
    .prepareGet(String.format("http://%s:5051/files/browse", slaveHostname))
    .setPerRequestConfig(timeoutConfig)
    .addQueryParameter("path", fullPath)
    .execute()
    .get();
  if (response.getStatusCode() == 404) {
   return Collections.emptyList();
  }
  if (response.getStatusCode() != 200) {
   throw new RuntimeException(String.format("Got HTTP %s from Mesos slave", response.getStatusCode()));
  }
  return objectMapper.readValue(response.getResponseBodyAsStream(), MESOS_FILE_OBJECTS);
 } catch (ConnectException ce) {
  throw new SlaveNotFoundException(ce);
 } catch (Exception e) {
  if (e.getCause().getClass() == ConnectException.class) {
   throw new SlaveNotFoundException(e);
  } else {
   throw Throwables.propagate(e);
  }
 }
}

代码示例来源:origin: HubSpot/Singularity

private void downloadFilesFromLocalDownloadService(List<? extends S3Artifact> s3Artifacts, SingularityExecutorTask task) throws InterruptedException {
 final List<FutureHolder> futures = Lists.newArrayListWithCapacity(s3Artifacts.size());
 for (S3Artifact s3Artifact : s3Artifacts) {
  String destination = task.getArtifactPath(s3Artifact, task.getTaskDefinition().getTaskDirectoryPath()).toString();
  ArtifactDownloadRequest artifactDownloadRequest = new ArtifactDownloadRequest(destination, s3Artifact,
    Optional.of(SingularityExecutorArtifactFetcher.this.executorConfiguration.getLocalDownloadServiceTimeoutMillis()));
  task.getLog().debug("Requesting {} from {}", artifactDownloadRequest, localDownloadUri);
  BoundRequestBuilder postRequestBldr = localDownloadHttpClient.preparePost(localDownloadUri);
  try {
   postRequestBldr.setBody(objectMapper.writeValueAsBytes(artifactDownloadRequest));
  } catch (JsonProcessingException e) {
   throw Throwables.propagate(e);
  }
  try {
   ListenableFuture<Response> future = localDownloadHttpClient.executeRequest(postRequestBldr.build());
   futures.add(new FutureHolder(future, System.currentTimeMillis(), s3Artifact));
  } catch (IOException ioe) {
   throw Throwables.propagate(ioe);
  }
 }
 for (FutureHolder future : futures) {
  Response response = future.getReponse();
  task.getLog().debug("Future for {} got status code {} after {}", future.s3Artifact.getName(), response.getStatusCode(), JavaUtils.duration(future.start));
  if (response.getStatusCode() != 200) {
   throw new IllegalStateException("Got status code:" + response.getStatusCode());
  }
 }
}

代码示例来源:origin: HubSpot/Singularity

private SingularityUserPermissionsResponse verifyUncached(String authHeaderValue) {
  try {
   Response response = asyncHttpClient.prepareGet(webhookAuthConfiguration.getAuthVerificationUrl())
     .addHeader("Authorization", authHeaderValue)
     .execute()
     .get();
   if (response.getStatusCode() > 299) {
    throw WebExceptions.unauthorized(String.format("Got status code %d when verifying jwt", response.getStatusCode()));
   } else {
    String responseBody = response.getResponseBody();
    SingularityUserPermissionsResponse permissionsResponse = objectMapper.readValue(responseBody, SingularityUserPermissionsResponse.class);
    if (!permissionsResponse.getUser().isPresent()) {
     throw WebExceptions.unauthorized(String.format("No user present in response %s", permissionsResponse));
    }
    if (!permissionsResponse.getUser().get().isAuthenticated()) {
     throw WebExceptions.unauthorized(String.format("User not authenticated (response: %s)", permissionsResponse));
    }
    permissionsCache.put(authHeaderValue, permissionsResponse);
    return permissionsResponse;
   }
  } catch (Throwable t) {
   throw new RuntimeException(t);
  }
 }
}

相关文章