本文整理汇总了Java中com.ning.http.client.HttpResponseStatus类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseStatus类的具体用法?Java HttpResponseStatus怎么用?Java HttpResponseStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponseStatus类属于com.ning.http.client包,在下文中一共展示了HttpResponseStatus类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStatusReceived
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
public com.ning.http.client.AsyncHandler.STATE onStatusReceived(
HttpResponseStatus responseStatus) throws Exception {
int statusCode = responseStatus.getStatusCode();
testCaseReport.setResponseStatusCode(statusCode);
if (statusCode != testCase.getExpectedResCode()) {
testCaseReport.setError("Expected status code ["+testCase.getExpectedResCode()
+"] does not match actual status code ["+statusCode+"]");
testCaseReport.setStatus(TestStatus.Failed.status);
testCaseReport.setFailureReason(TestFailureReason.InvalidStatusCode.status);
if(testCase.isAbortOnInvalidStatusCode())
{
return STATE.ABORT;
}
}
builder.accumulate(responseStatus);
return STATE.CONTINUE;
}
示例2: onStatusReceived
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
@Override
public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
if (log.isTraceEnabled()) {
log.trace("{} onStatusReceived {}", exchange.getExchangeId(), responseStatus);
}
try {
statusCode = responseStatus.getStatusCode();
statusText = responseStatus.getStatusText();
getEndpoint().getBinding().onStatusReceived(getEndpoint(), exchange, responseStatus);
} catch (Exception e) {
exchange.setException(e);
}
return STATE.CONTINUE;
}
示例3: onStatusReceived
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
@Override
public void onStatusReceived(AhcEndpoint endpoint, Exchange exchange, HttpResponseStatus responseStatus) throws Exception {
// preserve headers from in by copying any non existing headers
// to avoid overriding existing headers with old values
// Just filter the http protocol headers
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), httpProtocolHeaderFilterStrategy, false);
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, responseStatus.getStatusCode());
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_TEXT, responseStatus.getStatusText());
}
示例4: transactionMarker
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
@Override
public void transactionMarker() throws Exception {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger statusCode = new AtomicInteger();
asyncHttpClient.prepareGet("http://localhost:" + getPort() + "/hello3/")
.execute(new AsyncHandler<Response>() {
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart part) {
return null;
}
@Override
public Response onCompleted() throws Exception {
latch.countDown();
return null;
}
@Override
public STATE onHeadersReceived(HttpResponseHeaders headers) {
return null;
}
@Override
public STATE onStatusReceived(HttpResponseStatus status) {
statusCode.set(status.getStatusCode());
return null;
}
@Override
public void onThrowable(Throwable t) {}
});
latch.await();
asyncHttpClient.close();
if (statusCode.get() != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
}
示例5: prepareResponse
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
public Response prepareResponse(HttpResponseStatus status, HttpResponseHeaders headers, List<HttpResponseBodyPart> bodyParts) {
return new JDKResponse(status, headers, bodyParts);
}
示例6: onStatusReceived
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
@Override
public STATE onStatusReceived(final HttpResponseStatus responseStatus) throws Exception {
this.status = responseStatus;
return STATE.CONTINUE;
}
示例7: HTTPAsyncPost
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
public HTTPAsyncPost(AsyncHttpClient client, HTTPLogObject http_log) {
RequestBuilder builder = new RequestBuilder("POST");
url_request = http_log.getURLRequest();
HTTPUtils util = new HTTPUtils();
builder = util.buildDefaultHeaders(builder, http_log);
// Add additional POST headers, if specified
builder = util.buildCustomPOSTHeaders(builder, http_log);
builder.addHeader("User-Agent", http_log.getUseragent());
String one_time_payload = POSTPayloadCache.instance.fetchPayload(http_log.getRequest());
logger.debug("Here is the randomized payload: " + one_time_payload);
builder.setBody(one_time_payload);
Request request = builder.setUrl(http_log.getURLRequest()).build();
AsyncHandler<Response> asyncHandler = new AsyncHandler<Response>() {
private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
public STATE onBodyPartReceived(final HttpResponseBodyPart content)
throws Exception {
builder.accumulate(content);
return STATE.CONTINUE;
}
public STATE onStatusReceived(final HttpResponseStatus status)
throws Exception {
builder.accumulate(status);
return STATE.CONTINUE;
}
public STATE onHeadersReceived(final HttpResponseHeaders headers)
throws Exception {
builder.accumulate(headers);
return STATE.CONTINUE;
}
public Response onCompleted() throws Exception {
logger.debug("POST - " + url_request + " - "
+ builder.build().getStatusCode());
return builder.build();
}
@Override
public void onThrowable(Throwable t) {
logger.error(t.getMessage());
}
};
try {
client.executeRequest(request, asyncHandler);
} catch (IOException e) {
logger.error(e.getMessage());
}
}
示例8: HTTPAsyncGet
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
public HTTPAsyncGet(AsyncHttpClient client, HTTPLogObject http_log) {
RequestBuilder builder = new RequestBuilder("GET");
url_request = http_log.getURLRequest();
HTTPUtils util = new HTTPUtils();
builder = util.buildDefaultHeaders(builder, http_log);
// Add additional GET headers, if specified
builder = util.buildCustomGETHeaders(builder, http_log);
builder.addHeader("User-Agent", http_log.getUseragent());
Request request = builder.setUrl(url_request).build();
AsyncHandler<Response> asyncHandler = new AsyncHandler<Response>() {
private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
public STATE onBodyPartReceived(final HttpResponseBodyPart content)
throws Exception {
builder.accumulate(content);
return STATE.CONTINUE;
}
public STATE onStatusReceived(final HttpResponseStatus status)
throws Exception {
builder.accumulate(status);
return STATE.CONTINUE;
}
public STATE onHeadersReceived(final HttpResponseHeaders headers)
throws Exception {
builder.accumulate(headers);
return STATE.CONTINUE;
}
public Response onCompleted() throws Exception {
logger.debug("GET - " + url_request + " - "
+ builder.build().getStatusCode());
return builder.build();
}
@Override
public void onThrowable(Throwable t) {
logger.error(t.getMessage());
}
};
try {
client.executeRequest(request, asyncHandler);
} catch (IOException e) {
logger.error(e.getMessage());
}
}
示例9: sse
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
public String sse(final String path, final int count) throws Exception {
CountDownLatch latch = new CountDownLatch(count);
String result = client.prepareGet("http://localhost:" + port + path)
.addHeader("Content-Type", MediaType.sse.name())
.addHeader("last-event-id", count + "")
.execute(new AsyncHandler<String>() {
StringBuilder sb = new StringBuilder();
@Override
public void onThrowable(final Throwable t) {
t.printStackTrace();
}
@Override
public AsyncHandler.STATE onBodyPartReceived(final HttpResponseBodyPart bodyPart)
throws Exception {
sb.append(new String(bodyPart.getBodyPartBytes(), StandardCharsets.UTF_8));
latch.countDown();
return AsyncHandler.STATE.CONTINUE;
}
@Override
public AsyncHandler.STATE onStatusReceived(final HttpResponseStatus responseStatus)
throws Exception {
assertEquals(200, responseStatus.getStatusCode());
return AsyncHandler.STATE.CONTINUE;
}
@Override
public AsyncHandler.STATE onHeadersReceived(final HttpResponseHeaders headers)
throws Exception {
FluentCaseInsensitiveStringsMap h = headers.getHeaders();
assertEquals("close", h.get("Connection").get(0).toLowerCase());
assertEquals("text/event-stream; charset=utf-8",
h.get("Content-Type").get(0).toLowerCase());
return AsyncHandler.STATE.CONTINUE;
}
@Override
public String onCompleted() throws Exception {
return sb.toString();
}
}).get();
latch.await();
return result;
}
示例10: onStatusReceived
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
@Override
public STATE onStatusReceived(HttpResponseStatus status) throws Exception {
builder.reset();
builder.accumulate(status);
return STATE.CONTINUE;
}
示例11: testEntityChunkedOutput
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
@Test
public void testEntityChunkedOutput() throws URISyntaxException, IOException, ExecutionException, InterruptedException {
Inflector<ContainerRequestContext, ChunkedOutput<?>> inflector = new Inflector<ContainerRequestContext, ChunkedOutput<?>>() {
@Override
public ChunkedOutput<Entity> apply(ContainerRequestContext containerRequestContext) {
final ChunkedOutput<Entity> output = new ChunkedOutput<Entity>(Entity.class);
new Thread() {
int i = 0;
@Override
public void run() {
try {
while (i <= 4) {
if (i == 0) {
output.write(new Entity(true, 0));
} else {
output.write(new Entity(false, 1000));
}
i++;
}
output.close();
} catch (IOException e) {
fail("writing should not fail", e);
}
}
}.start();
return output;
}
};
ServerBootstrap bootstrap = getServerBootstrap();
int port = bindJerseyServer(inflector, bootstrap, EntityWriter.class);
final AsyncHttpClient client = getHttpClient();
ListenableFuture<Object> request = client.prepareGet("http://localhost:" + port + "/").execute(new AsyncHandler<Object>() {
@Override
public void onThrowable(Throwable t) {
fail("Should not throw up", t);
}
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
return STATE.CONTINUE;
}
@Override
public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
return STATE.CONTINUE;
}
@Override
public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
return STATE.CONTINUE;
}
@Override
public Object onCompleted() throws Exception {
return STATE.CONTINUE;
}
});
request.get();
bootstrap.shutdown();
}
示例12: onStatusReceived
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
public AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
responseBuilder.reset();
responseBuilder.accumulate(responseStatus);
statusReceived = true;
return AsyncHandler.STATE.CONTINUE;
}
示例13: onStatusReceived
import com.ning.http.client.HttpResponseStatus; //导入依赖的package包/类
/**
* Callback from the {@link com.ning.http.client.AsyncHttpClient} when the HTTP response status was received
*
* @param endpoint the endpoint
* @param exchange the exchange
* @param responseStatus the HTTP response status
* @throws Exception is thrown if error occurred in the callback
*/
void onStatusReceived(AhcEndpoint endpoint, Exchange exchange, HttpResponseStatus responseStatus) throws Exception;