当前位置: 首页>>代码示例>>Java>>正文


Java EmbeddedChannel.inboundMessages方法代码示例

本文整理汇总了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());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:30,代码来源:HttpContentDecoderTest.java

示例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());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:30,代码来源:HttpContentDecoderTest.java


注:本文中的io.netty.channel.embedded.EmbeddedChannel.inboundMessages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。