本文整理汇总了Java中io.netty.channel.embedded.EmbeddedChannel.inboundMessages方法的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedChannel.inboundMessages方法的具体用法?Java EmbeddedChannel.inboundMessages怎么用?Java EmbeddedChannel.inboundMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.embedded.EmbeddedChannel
的用法示例。
在下文中一共展示了EmbeddedChannel.inboundMessages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRequestContentLength1
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testRequestContentLength1() {
// case 1: test that ContentDecompressor either sets the correct Content-Length header
// or removes it completely (handlers down the chain must rely on LastHttpContent object)
// force content to be in more than one chunk (5 bytes/chunk)
HttpRequestDecoder decoder = new HttpRequestDecoder(4096, 4096, 5);
HttpContentDecoder decompressor = new HttpContentDecompressor();
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
String headers = "POST / HTTP/1.1\r\n" +
"Content-Length: " + GZ_HELLO_WORLD.length + "\r\n" +
"Content-Encoding: gzip\r\n" +
"\r\n";
ByteBuf buf = Unpooled.copiedBuffer(headers.getBytes(CharsetUtil.US_ASCII), GZ_HELLO_WORLD);
assertTrue(channel.writeInbound(buf));
Queue<Object> req = channel.inboundMessages();
assertTrue(req.size() >= 1);
Object o = req.peek();
assertThat(o, is(instanceOf(HttpRequest.class)));
HttpRequest r = (HttpRequest) o;
String v = r.headers().get(HttpHeaders.Names.CONTENT_LENGTH);
Long value = v == null ? null : Long.parseLong(v);
assertTrue(value == null || value.longValue() == HELLO_WORLD.length());
assertHasInboundMessages(channel, true);
assertHasOutboundMessages(channel, false);
assertFalse(channel.finish());
}
示例2: testResponseContentLength1
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testResponseContentLength1() {
// case 1: test that ContentDecompressor either sets the correct Content-Length header
// or removes it completely (handlers down the chain must rely on LastHttpContent object)
// force content to be in more than one chunk (5 bytes/chunk)
HttpResponseDecoder decoder = new HttpResponseDecoder(4096, 4096, 5);
HttpContentDecoder decompressor = new HttpContentDecompressor();
EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor);
String headers = "HTTP/1.1 200 OK\r\n" +
"Content-Length: " + GZ_HELLO_WORLD.length + "\r\n" +
"Content-Encoding: gzip\r\n" +
"\r\n";
ByteBuf buf = Unpooled.copiedBuffer(headers.getBytes(CharsetUtil.US_ASCII), GZ_HELLO_WORLD);
assertTrue(channel.writeInbound(buf));
Queue<Object> resp = channel.inboundMessages();
assertTrue(resp.size() >= 1);
Object o = resp.peek();
assertThat(o, is(instanceOf(HttpResponse.class)));
HttpResponse r = (HttpResponse) o;
String v = r.headers().get(HttpHeaders.Names.CONTENT_LENGTH);
Long value = v == null ? null : Long.parseLong(v);
assertTrue(value == null || value.longValue() == HELLO_WORLD.length());
assertHasInboundMessages(channel, true);
assertHasOutboundMessages(channel, false);
assertFalse(channel.finish());
}