Search in sources :

Example 21 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testTradeForCallAbortAfterRequestPublish.

@Test
public final void testTradeForCallAbortAfterRequestPublish() {
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf("testcontent"));
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
    trade.inbound().subscribe(reqSubscriber);
    writeToInboundAndFlush(channel, request);
    trade.close();
    assertFalse(trade.isActive());
    reqSubscriber.assertValueCount(1);
    reqSubscriber.assertValue(RxNettys.<HttpObject>wrap4release(request));
    reqSubscriber.assertCompleted();
    reqSubscriber.assertNoErrors();
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestSubscriber(rx.observers.TestSubscriber) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 22 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testTradeForCallAbortAndUseInboundRequest.

@Test
public final void testTradeForCallAbortAndUseInboundRequest() {
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf("testcontent"));
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    writeToInboundAndFlush(channel, request);
    trade.close();
    assertTrue(!trade.isActive());
    final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
    trade.inbound().subscribe(reqSubscriber);
    reqSubscriber.assertTerminalEvent();
    reqSubscriber.assertError(Exception.class);
    reqSubscriber.assertValueCount(0);
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestSubscriber(rx.observers.TestSubscriber) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 23 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project jocean-http by isdom.

the class NettysTestCase method test_httpobjs2fullreq_success2.

@Test
public final void test_httpobjs2fullreq_success2() throws Exception {
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf(REQ_CONTENT));
    assertEquals(1, request.refCnt());
    final FullHttpRequest fullreq = Nettys.httpobjs2fullreq(Arrays.<HttpObject>asList(request));
    assertNotNull(fullreq);
    assertEquals(REQ_CONTENT, new String(Nettys.dumpByteBufAsBytes(fullreq.content()), Charsets.UTF_8));
    assertEquals(2, request.refCnt());
    fullreq.release();
    assertEquals(1, request.refCnt());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.Test)

Example 24 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project jocean-http by isdom.

the class RxNettysTestCase method test_BUILD_FULL_REQUEST_ForSingleFullRequest.

@Test
public final void test_BUILD_FULL_REQUEST_ForSingleFullRequest() throws IOException {
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf(REQ_CONTENT));
    assertEquals(1, request.refCnt());
    final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(new HttpObject[] { request });
    assertNotNull(fullreq);
    assertEquals(REQ_CONTENT, new String(Nettys.dumpByteBufAsBytes(fullreq.content()), Charsets.UTF_8));
    assertEquals(2, request.refCnt());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.Test)

Example 25 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project jocean-http by isdom.

the class DefaultHttpServerBuilderTestCase method buildFullRequest.

private DefaultFullHttpRequest buildFullRequest(final byte[] bytes) {
    final ByteBuf content = Unpooled.buffer(0);
    content.writeBytes(bytes);
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
    HttpUtil.setContentLength(request, content.readableBytes());
    return request;
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)206 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)110 Test (org.junit.jupiter.api.Test)72 Test (org.junit.Test)56 ByteBuf (io.netty.buffer.ByteBuf)54 HttpRequest (io.netty.handler.codec.http.HttpRequest)45 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)42 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)40 AsciiString (io.netty.util.AsciiString)30 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)23 Channel (io.netty.channel.Channel)19 ChannelPromise (io.netty.channel.ChannelPromise)19 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)18 IOException (java.io.IOException)17 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)14 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)14 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)12 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 Bootstrap (io.netty.bootstrap.Bootstrap)10