use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project jersey by jersey.
the class JerseyClientHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
if (msg instanceof HttpResponse) {
final HttpResponse response = (HttpResponse) msg;
final ClientResponse jerseyResponse = new ClientResponse(new Response.StatusType() {
@Override
public int getStatusCode() {
return response.status().code();
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.Family.familyOf(response.status().code());
}
@Override
public String getReasonPhrase() {
return response.status().reasonPhrase();
}
}, jerseyRequest);
for (Map.Entry<String, String> entry : response.headers().entries()) {
jerseyResponse.getHeaders().add(entry.getKey(), entry.getValue());
}
// request entity handling.
if ((response.headers().contains(HttpHeaderNames.CONTENT_LENGTH) && HttpUtil.getContentLength(response) > 0) || HttpUtil.isTransferEncodingChunked(response)) {
ctx.channel().closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
isList.add(NettyInputStream.END_OF_INPUT_ERROR);
}
});
jerseyResponse.setEntityStream(new NettyInputStream(isList));
} else {
jerseyResponse.setEntityStream(new InputStream() {
@Override
public int read() throws IOException {
return -1;
}
});
}
if (asyncConnectorCallback != null) {
connector.executorService.execute(new Runnable() {
@Override
public void run() {
asyncConnectorCallback.response(jerseyResponse);
future.complete(jerseyResponse);
}
});
}
}
if (msg instanceof HttpContent) {
HttpContent httpContent = (HttpContent) msg;
ByteBuf content = httpContent.content();
if (content.isReadable()) {
// copy bytes - when netty reads last chunk, it automatically closes the channel, which invalidates all
// relates ByteBuffs.
byte[] bytes = new byte[content.readableBytes()];
content.getBytes(content.readerIndex(), bytes);
isList.add(new ByteArrayInputStream(bytes));
}
if (msg instanceof LastHttpContent) {
isList.add(NettyInputStream.END_OF_INPUT);
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeEmptyEnd.
@Test
public void testUpgradeEmptyEnd() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
LastHttpContent end = LastHttpContent.EMPTY_LAST_CONTENT;
assertTrue(ch.writeOutbound(end));
Http2DataFrame emptyFrame = ch.readOutbound();
try {
assertThat(emptyFrame.content().readableBytes(), is(0));
assertTrue(emptyFrame.isEndStream());
} finally {
emptyFrame.release();
}
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeTrailers.
@Test
public void testUpgradeTrailers() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
LastHttpContent trailers = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, true);
HttpHeaders headers = trailers.trailingHeaders();
headers.set("key", "value");
assertTrue(ch.writeOutbound(trailers));
Http2HeadersFrame headerFrame = ch.readOutbound();
assertThat(headerFrame.headers().get("key").toString(), is("value"));
assertTrue(headerFrame.isEndStream());
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeDataEndWithTrailers.
@Test
public void testUpgradeDataEndWithTrailers() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
LastHttpContent trailers = new DefaultLastHttpContent(hello, true);
HttpHeaders headers = trailers.trailingHeaders();
headers.set("key", "value");
assertTrue(ch.writeOutbound(trailers));
Http2DataFrame dataFrame = ch.readOutbound();
try {
assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
assertFalse(dataFrame.isEndStream());
} finally {
dataFrame.release();
}
Http2HeadersFrame headerFrame = ch.readOutbound();
assertThat(headerFrame.headers().get("key").toString(), is("value"));
assertTrue(headerFrame.isEndStream());
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project netty by netty.
the class Http2ServerDowngraderTest method testUpgradeDataEnd.
@Test
public void testUpgradeDataEnd() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
LastHttpContent end = new DefaultLastHttpContent(hello, true);
assertTrue(ch.writeOutbound(end));
Http2DataFrame dataFrame = ch.readOutbound();
try {
assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
assertTrue(dataFrame.isEndStream());
} finally {
dataFrame.release();
}
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
Aggregations