本文整理汇总了Java中org.asynchttpclient.Response.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getStatusCode方法的具体用法?Java Response.getStatusCode怎么用?Java Response.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.asynchttpclient.Response
的用法示例。
在下文中一共展示了Response.getStatusCode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForAndAssertResponse
import org.asynchttpclient.Response; //导入方法依赖的package包/类
private void waitForAndAssertResponse(ListenableFuture<Response> responseFuture) throws InterruptedException, java.util.concurrent.ExecutionException, IOException {
Response response = responseFuture.get();
if (500 == response.getStatusCode()) {
StringBuilder sb = new StringBuilder();
sb.append("==============\n");
sb.append("500 response from call\n");
sb.append("Headers:" + response.getHeaders() + "\n");
sb.append("==============\n");
logger.debug(sb.toString());
assertEquals(response.getStatusCode(), 500, "Should have 500 status code");
assertTrue(response.getHeader("X-Exception").contains("invalid.chunk.length"), "Should have failed due to chunking");
fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception"));
} else {
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
}
}
示例2: getAllIndexNames
import org.asynchttpclient.Response; //导入方法依赖的package包/类
public List<String> getAllIndexNames() {
try {
Response response = httpClient.prepareGet("/_all").execute().get();
if (response.getStatusCode() != 200) {
throw RequestBuilderUtil.toHttpServerErrorException(response);
}
String jsonString = response.getResponseBody();
JsonObject responseObject = gson.fromJson(jsonString, JsonObject.class);
return responseObject.entrySet().stream()
.map(Map.Entry::getKey)
.collect(toList());
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
示例3: execute
import org.asynchttpclient.Response; //导入方法依赖的package包/类
@Override
public SearchResponse execute() {
JsonObject requestBody = object(
"scroll_id", scrollId,
"scroll", scroll
);
try {
Response response = httpClient.preparePost("/_search/scroll")
.setBody(gson.toJson(requestBody))
.execute()
.get();
//Did not find an entry
if (response.getStatusCode() == 404) {
return emptyResponse();
}
//Server Error
if (response.getStatusCode() >= 300) {
throw toHttpServerErrorException(response);
}
JsonObject jsonResponse = gson.fromJson(response.getResponseBody(), JsonObject.class);
SearchResponse.Builder searchResponse = parseResponse(jsonResponse, null, null);
return searchResponse.build();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
示例4: execute
import org.asynchttpclient.Response; //导入方法依赖的package包/类
public Void execute() {
if (indexNames.length == 0) {
throw new RuntimeException("index names are missing");
}
try {
String url = RequestBuilderUtil.buildUrl(indexNames, null, null);
Response response = httpClient.prepareDelete(url).execute().get();
if (response.getStatusCode() >= 300 && response.getStatusCode() != 404) {
throw RequestBuilderUtil.toHttpServerErrorException(response);
}
return null;
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
示例5: getIndexSettings
import org.asynchttpclient.Response; //导入方法依赖的package包/类
public JsonObject getIndexSettings() {
try {
Response response = httpClient.prepareGet("/_all/_settings").execute().get();
if (response.getStatusCode() != 200) {
throw RequestBuilderUtil.toHttpServerErrorException(response);
}
String jsonString = null;
jsonString = response.getResponseBody();
return gson.fromJson(jsonString, JsonObject.class);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
示例6: getIndexMapping
import org.asynchttpclient.Response; //导入方法依赖的package包/类
public JsonObject getIndexMapping(String indexName){
try {
Response response = httpClient.prepareGet("/" + indexName+"/_mapping").execute().get();
if (response.getStatusCode() != 200) {
throw RequestBuilderUtil.toHttpServerErrorException(response);
}
String jsonString = null;
jsonString = response.getResponseBody();
return gson.fromJson(jsonString, JsonObject.class);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
示例7: handleResponse
import org.asynchttpclient.Response; //导入方法依赖的package包/类
private void handleResponse(String id, Response response) {
if (response == null || response.getStatusCode() != OK_200) {
log.error("Handling error for id {} with response {}", id, response);
responses.offer(new PubSubMessage(id, DRPCError.CANNOT_REACH_DRPC.asJSON()));
return;
}
log.info("Received for id {}: {} {}", response.getStatusCode(), id, response.getStatusText());
String body = response.getResponseBody();
PubSubMessage message = PubSubMessage.fromJSON(body);
log.debug("Received for id {}:\n{}", message.getId(), message.getContent());
responses.offer(message);
}
示例8: apply
import org.asynchttpclient.Response; //导入方法依赖的package包/类
@Override
public JsonNode apply(Response response) {
MappingJsonFactory mappingJsonFactory = new MappingJsonFactory();
ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
objectNode.set(DruidJsonResponseContentKeys.RESPONSE.getName(), baseStrategy.apply(response));
try {
objectNode.set(
DruidJsonResponseContentKeys.DRUID_RESPONSE_CONTEXT.getName(),
mappingJsonFactory
.createParser(
response.getHeader(DruidJsonResponseContentKeys.DRUID_RESPONSE_CONTEXT.getName())
)
.readValueAsTree()
);
int statusCode = response.getStatusCode();
objectNode.set(
DruidJsonResponseContentKeys.STATUS_CODE.getName(),
mappingJsonFactory.createParser(String.valueOf(statusCode)).readValueAsTree()
);
if (CacheFeatureFlag.ETAG.isOn() && statusCode == OK.getStatusCode()) {
objectNode.set(
DruidJsonResponseContentKeys.ETAG.getName(),
mappingJsonFactory
.createParser(
response.getHeader(DruidJsonResponseContentKeys.ETAG.getName())
)
.readValueAsTree()
);
}
} catch (IOException ioe) {
throw new IllegalStateException(ioe);
}
return objectNode;
}
示例9: convertResponse
import org.asynchttpclient.Response; //导入方法依赖的package包/类
/**
* Convert response object.
*
* @param restyCommand the resty command
* @param response the response
* @return the object
*/
public Object convertResponse(RestyCommand restyCommand, Response response) {
Object result = null;
// response 为null
if (response == null) {
restyCommand.failed(new ServerException("Failed to get response, it's null"));
return result;
}
// response为FailedResponse, [connectException InterruptedException] status 500
if (FailedResponse.isFailedResponse(response)) {
restyCommand.failed(FailedResponse.class.cast(response).getException());
return result;
}
// 服务响应了请求,但是不是200
int statusCode = response.getStatusCode();
if (200 != statusCode) {
if (statusCode >= 400 && statusCode < 500) {
restyCommand.failed(new RequestException(response.getResponseBody()));
} else if (statusCode >= 500) {
restyCommand.failed(new ServerException(response.getResponseBody()));
}
return result;
}
byte[] body = response.getResponseBodyAsBytes();
// 使用转换器 转换响应结果 json->object
boolean converted = false;
Type returnType = restyCommand.getReturnType();
String respContentType = response.getContentType();
for (ResponseConverter converter : converterList) {
if (converter.support(returnType, respContentType)) {
converted = true;
result = converter.convert(body, returnType, respContentType);
break;
}
}
if (!converted) {
restyCommand.failed(new RestyException("没有合适的解析器,content-type:" + respContentType + ";body:" + response.getResponseBody()));
}
restyCommand.success();
return result;
}
示例10: execute
import org.asynchttpclient.Response; //导入方法依赖的package包/类
@Override
public SearchResponse execute() {
JsonObject body = new JsonObject();
try {
String url = RequestBuilderUtil.buildUrl(indices, types, "_search");
if (query != null) {
body.add("query", query);
}
if (storedFields != null) {
body.add("stored_fields", storedFields);
}
if (sourceFilters != null) {
body.add("_source", sourceFilters);
}
if (from != null) {
body.add("from", new JsonPrimitive(from));
}
if (size != null) {
body.add("size", new JsonPrimitive(size));
}
if (sorts != null) {
body.add("sort", sorts);
}
if (postFilter != null) {
body.add("post_filter", postFilter.build());
}
if (aggregations != null) {
JsonObject jsonObject = aggregations
.stream()
.collect(toJsonObject());
body.add("aggregations", jsonObject);
}
BoundRequestBuilder boundRequestBuilder = httpClient
.preparePost(url)
.setCharset(Charset.forName("UTF-8"));
if (timeoutMillis != null) {
boundRequestBuilder.setRequestTimeout(timeoutMillis);
}
if (scroll != null) {
boundRequestBuilder.addQueryParam("scroll", scroll);
}
Response response = boundRequestBuilder.setBody(gson.toJson(body))
.execute()
.get();
//Did not find an entry
if (response.getStatusCode() == 404) {
return emptyResponse();
}
//Server Error
if (response.getStatusCode() >= 300) {
throw toHttpServerErrorException(response);
}
JsonObject jsonResponse = gson.fromJson(response.getResponseBody(), JsonObject.class);
SearchResponse.Builder searchResponse = parseResponse(jsonResponse, scroll, httpClient);
JsonElement aggregationsJsonElement = jsonResponse.get("aggregations");
if (aggregationsJsonElement != null) {
final JsonObject aggregationsJsonObject = aggregationsJsonElement.getAsJsonObject();
aggregations.forEach(a -> {
JsonElement aggregationElement = aggregationsJsonObject.get(a.getName());
if (aggregationElement != null) {
AggregationResult aggregation = a.parseResponse(aggregationElement.getAsJsonObject());
searchResponse.addAggregation(a.getName(), aggregation);
}
});
}
return searchResponse.build();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(body.toString(), e);
}
}
示例11: toHttpServerErrorException
import org.asynchttpclient.Response; //导入方法依赖的package包/类
public static HttpServerErrorException toHttpServerErrorException(Response response) {
return new HttpServerErrorException(response.getStatusCode(), response.getStatusText() , new String(response.getResponseBodyAsBytes()));
}