本文整理汇总了Java中com.ning.http.client.Response.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getStatusCode方法的具体用法?Java Response.getStatusCode怎么用?Java Response.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ning.http.client.Response
的用法示例。
在下文中一共展示了Response.getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: browse
import com.ning.http.client.Response; //导入方法依赖的package包/类
public Collection<MesosFileObject> browse(String slaveHostname, String fullPath) throws SlaveNotFoundException {
try {
Response response = asyncHttpClient.prepareGet(String.format("http://%s:5051/files/browse.json", slaveHostname))
.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);
}
}
}
示例2: get
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public BrokerResponse get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
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(new JSONObject(responseBody));
} catch (Exception e) {
throw new ExecutionException(e);
}
}
示例3: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public Response onCompleted(final Response response) throws Exception {
final long duration = System.currentTimeMillis() - startTime;
Boolean sameStatus = null;
try {
sameStatus = Integer.parseInt(originalData.getStatusCode()) == response.getStatusCode();
} catch (NumberFormatException e) {
LOG.warn("Unable to parse original status code to int: {}", originalData.getStatusCode());
}
resultDataLogger.logResultDataLine(originalData, response, sameStatus, duration, startTime);
LOG.info("Status={} OriginalStatus={} SameStatus={} Duration={} OriginalDuration={} Difference={} Request={}", response.getStatusCode(), originalData.getStatusCode(),
sameStatus, duration,
originalData.getDuration(),
duration - originalData.getDuration(), response.getUri().toASCIIString());
return response;
}
示例4: getContents
import com.ning.http.client.Response; //导入方法依赖的package包/类
public Optional<String> getContents(String user, String repo, String path, Optional<String> ref) {
try {
final BoundRequestBuilder builder = asyncHttpClient.prepareGet(String.format("%s/repos/%s/%s/contents/%s", baseUrl, user, repo, path))
.addHeader("Accept", "application/vnd.github.v3.raw");
if (ref.isPresent()) {
builder.addQueryParameter("ref", ref.get());
}
if (accessToken.isPresent()) {
builder.addQueryParameter("access_token", accessToken.get());
}
final Response response = builder.execute().get();
if (response.getStatusCode() == 200) {
return Optional.of(response.getResponseBody());
} else if (response.getStatusCode() == 404) {
return Optional.absent();
} else {
throw new RuntimeException(response.getResponseBody()); // TODO: better exception
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
示例5: read
import com.ning.http.client.Response; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public Optional<MesosFileChunkObject> read(String slaveHostname, String fullPath, Optional<Long> offset, Optional<Long> length) throws SlaveNotFoundException {
try {
final AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.prepareGet(String.format("http://%s:5051/files/read.json", slaveHostname))
.addQueryParameter("path", fullPath);
PerRequestConfig timeoutConfig = new PerRequestConfig();
timeoutConfig.setRequestTimeoutInMs((int) configuration.getSandboxHttpTimeoutMillis());
builder.setPerRequestConfig(timeoutConfig);
if (offset.isPresent()) {
builder.addQueryParameter("offset", offset.get().toString());
}
if (length.isPresent()) {
builder.addQueryParameter("length", length.get().toString());
}
final Response response = builder.execute().get();
if (response.getStatusCode() == 404) {
return Optional.absent();
}
if (response.getStatusCode() != 200) {
throw new RuntimeException(String.format("Got HTTP %s from Mesos slave", response.getStatusCode()));
}
return Optional.of(objectMapper.readValue(response.getResponseBodyAsStream(), MesosFileChunkObject.class));
} catch (ConnectException ce) {
throw new SlaveNotFoundException(ce);
} catch (Exception e) {
if ((e.getCause() != null) && (e.getCause().getClass() == ConnectException.class)) {
throw new SlaveNotFoundException(e);
} else {
throw Throwables.propagate(e);
}
}
}
示例6: sendRequest
import com.ning.http.client.Response; //导入方法依赖的package包/类
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())));
}
}
示例7: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public T onCompleted(Response response) throws Exception {
if (expectedStatusCodes.contains(response.getStatusCode())) {
if (response.hasResponseBody()) {
if (tClass == String.class) {
return tClass.cast(response.getResponseBody());
} else {
return objectMapper.readValue(response.getResponseBody(), tClass);
}
}
return null;
} else {
throw new HTTPException(response.getStatusCode());
}
}
示例8: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public Void onCompleted(final Response response) throws Exception {
final URI requestUri = response.getUri();
try {
if (!response.hasResponseStatus()) {
sendError(response, "the response didn't have a response status");
return null;
}
final int httpStatusCode = response.getStatusCode();
if (httpStatusCode != HttpStatus.SC_OK) {
return handleFailureHttpStatus(response, requestUri, httpStatusCode);
} else {
if(returnType.equals(Void.class)){
httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0));
} else {
if (checkResponseBody(response)) return null;
final String responseValue = response.getResponseBody(request.getBodyEncoding());
Logger.getInstance().d("ResponseBody: " + responseValue);
Object result;
if(returnType.equals(String.class)) {
result = responseValue;
} else if(returnType.equals(Character.class)) {
result = responseValue.charAt(0);
} else {
result = new ObjectMapper().readValue(responseValue, returnType);
}
httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0, result));
}
return null;
}
} catch (Exception e) {
sendError(response, e.toString());
return null;
}
}
示例9: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public Response onCompleted(Response response) throws Exception {
if (response.getStatusCode() < 200 || response.getStatusCode() > 206)
throw new RuntimeException("Unexpected Buttercoin API response: " + response.getStatusCode() + " " + response.getStatusText() + " " + response.getResponseBody("UTF-8"));
return response;
}
示例10: apply
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public URL apply(Response response) {
if (response.getStatusCode() != 202)
throw new RuntimeException("Not a 202 Created response: " + response.getStatusCode() + " " + response.getStatusText());
try {
return new URL(response.getHeader("Location"));
}
catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
示例11: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public Response onCompleted(Response response) throws Exception {
if (response.getStatusCode() != 200) {
LOG.info(" <- '{}'", response.getStatusCode());
}
return response;
}
示例12: onCompleted
import com.ning.http.client.Response; //导入方法依赖的package包/类
@Override
public Response onCompleted(Response response) throws Exception{
// TODO: Handle status codes other than 200...
int httpStatus = response.getStatusCode();
if (deferredResult.isSetOrExpired()) {
log.logAlreadyExpiredNonBlocking();
} else {
boolean deferredStatus = deferredResult.setResult(response.getResponseBody());
log.logEndNonBlocking(httpStatus, deferredStatus);
}
return response;
}
开发者ID:callistaenterprise,项目名称:blog-non-blocking-rest-service-with-spring-mvc,代码行数:16,代码来源:RouterCallback.java
示例13: onResult
import com.ning.http.client.Response; //导入方法依赖的package包/类
public void onResult(int id, Response response) {
try {
// TODO: Handle status codes other than 200...
int httpStatus = response.getStatusCode();
log.logEndProcessingStepNonBlocking(id, httpStatus);
// If many requests completes at the same time the following code must be executed in sequence for one thread at a time
// Since we don't have any Actor-like mechanism to rely on (for the time being...) we simply ensure that the code block is executed by one thread at a time by an old school synchronized block
// Since the processing in the block is very limited it will not cause a bottleneck.
synchronized (result) {
// Count down, aggregate answer and return if all answers (also cancel timer)...
int noOfRes = noOfResults.incrementAndGet();
// Perform the aggregation...
log.logMessage("Safely adding response #" + id);
result += response.getResponseBody() + '\n';
if (noOfRes >= noOfCalls) {
onAllCompleted();
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:callistaenterprise,项目名称:blog-non-blocking-rest-service-with-spring-mvc,代码行数:30,代码来源:AggregatorEventHandler.java
示例14: onComplete
import com.ning.http.client.Response; //导入方法依赖的package包/类
public MyResponse onComplete(Response response) {
cancelCancellable();
try {
String statusCode = response.getStatusCode() + " " + response.getStatusText();
reply(response.getResponseBody(), false, null, null, statusCode);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例15: setResponse
import com.ning.http.client.Response; //导入方法依赖的package包/类
public void setResponse(String endpoint, Response response) throws IOException {
Integer statusCode = response.getStatusCode();
String httpResponse = response.getResponseBody();
List<Cookie> cookies = response.getCookies();
this.response = new HttpResponse(statusCode, httpResponse, cookies);
}