當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。