本文整理汇总了Java中com.ning.http.client.HttpResponseHeaders类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseHeaders类的具体用法?Java HttpResponseHeaders怎么用?Java HttpResponseHeaders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponseHeaders类属于com.ning.http.client包,在下文中一共展示了HttpResponseHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHeadersReceived
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
public com.ning.http.client.AsyncHandler.STATE onHeadersReceived(
HttpResponseHeaders headers) throws Exception {
if(testCase.getExpectedResContentType()!=null)
{
if(testCase.getExpectedResContentType()!=null && !testCase.getExpectedResContentType().trim().isEmpty()
&& headers.getHeaders().getFirstValue(HttpHeaders.CONTENT_TYPE)!=null
&& headers.getHeaders().getFirstValue(HttpHeaders.CONTENT_TYPE)
.indexOf(testCase.getExpectedResContentType())!=0)
{
testCaseReport.setError("Expected content type ["+testCase.getExpectedResContentType()
+"] does not match actual content type ["+headers.getHeaders().getFirstValue(HttpHeaders.CONTENT_TYPE)+"]");
testCaseReport.setStatus(TestStatus.Failed.status);
testCaseReport.setFailureReason(TestFailureReason.InvalidContentType.status);
if(testCase.isAbortOnInvalidContentType())
{
return STATE.ABORT;
}
}
}
else if(headers.getHeaders().getFirstValue(HttpHeaders.CONTENT_TYPE)!=null)
{
testCase.setExpectedResContentType(headers.getHeaders().getFirstValue(HttpHeaders.CONTENT_TYPE));
}
builder.accumulate(headers);
return STATE.CONTINUE;
}
示例2: onHeadersReceived
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
@Override
public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
if (log.isTraceEnabled()) {
log.trace("{} onHeadersReceived {}", exchange.getExchangeId(), headers);
}
try {
getEndpoint().getBinding().onHeadersReceived(getEndpoint(), exchange, headers);
} catch (Exception e) {
exchange.setException(e);
}
return STATE.CONTINUE;
}
示例3: onHeadersReceived
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
@Override
public void onHeadersReceived(AhcEndpoint endpoint, Exchange exchange, HttpResponseHeaders headers) throws Exception {
for (Map.Entry<String, List<String>> entry : headers.getHeaders().entrySet()) {
String key = entry.getKey();
List<String> value = entry.getValue();
if (value.size() == 1) {
exchange.getOut().getHeaders().put(key, value.get(0));
} else {
exchange.getOut().getHeaders().put(key, value);
}
}
}
示例4: transactionMarker
import com.ning.http.client.HttpResponseHeaders; //导入依赖的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: respondWithContentLength
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
private void respondWithContentLength(long cl, long actual)
throws ExecutionException {
when(http.get(any(), any())).thenAnswer(invoc -> {
Object[] args = invoc.getArguments();
//noinspection unchecked
((FunctionT<
HttpResponseHeaders, Boolean, SizeLimitExceededException
>) args[1]).apply(withContentLength(cl));
return new byte[CastUtil.assumeInt(actual)];
});
}
示例6: prepareResponse
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
public Response prepareResponse(HttpResponseStatus status, HttpResponseHeaders headers, List<HttpResponseBodyPart> bodyParts) {
return new JDKResponse(status, headers, bodyParts);
}
示例7: onHeadersReceived
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
@Override
public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception {
return super.onHeadersReceived(headers);
}
示例8: onHeadersReceived
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
@Override
public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception {
this.headers = headers;
return STATE.CONTINUE;
}
示例9: HTTPAsyncPost
import com.ning.http.client.HttpResponseHeaders; //导入依赖的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());
}
}
示例10: HTTPAsyncGet
import com.ning.http.client.HttpResponseHeaders; //导入依赖的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());
}
}
示例11: withContentLength
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
private static HttpResponseHeaders withContentLength(long cl) {
return NingHttpHeaders
.builder()
.addHeader("Content-Length", String.valueOf(cl))
.build();
}
示例12: sse
import com.ning.http.client.HttpResponseHeaders; //导入依赖的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;
}
示例13: onHeadersReceived
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
@Override
public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
builder.accumulate(headers);
return STATE.CONTINUE;
}
示例14: testEntityChunkedOutput
import com.ning.http.client.HttpResponseHeaders; //导入依赖的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();
}
示例15: onHeadersReceived
import com.ning.http.client.HttpResponseHeaders; //导入依赖的package包/类
public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
responseBuilder.accumulate(headers);
return AsyncHandler.STATE.CONTINUE;
}