Search in sources :

Example 51 with HttpObject

use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.

the class RxNettysTestCase method test_BUILD_FULL_REQUEST_WhenNoRequest.

@Test
public final void test_BUILD_FULL_REQUEST_WhenNoRequest() {
    final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
    final List<HttpObject> reqs = new ArrayList<HttpObject>() {

        private static final long serialVersionUID = 1L;

        {
            this.addAll(Arrays.asList(req_contents));
            this.add(LastHttpContent.EMPTY_LAST_CONTENT);
        }
    };
    final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(reqs.toArray(new HttpObject[0]));
    assertNull(fullreq);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) HttpObject(io.netty.handler.codec.http.HttpObject) ArrayList(java.util.ArrayList) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) Test(org.junit.Test)

Example 52 with HttpObject

use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.

the class TestHttpUtil method buildByteBufResponse.

public static Observable<HttpObject> buildByteBufResponse(final String contentType, final ByteBuf content) {
    final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, OK, content);
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
    response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
    return Observable.<HttpObject>just(response);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpObject(io.netty.handler.codec.http.HttpObject) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse)

Example 53 with HttpObject

use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testTradeForCompleteRoundWithMultiContentRequest.

@Test
public final void testTradeForCompleteRoundWithMultiContentRequest() {
    final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    Observable.<HttpObject>concat(Observable.<HttpObject>just(request), Observable.<HttpObject>from(req_contents), Observable.<HttpObject>just(LastHttpContent.EMPTY_LAST_CONTENT)).subscribe(obj -> writeToInboundAndFlush(channel, obj));
    // new Action1<HttpObject>() {
    // @Override
    // public void call(final HttpObject obj) {
    // writeToInboundAndFlush(channel, obj);
    // }}
    assertTrue(trade.isActive());
    final FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK);
    trade.outbound(Observable.<HttpObject>just(response));
    assertFalse(trade.isActive());
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpObject(io.netty.handler.codec.http.HttpObject) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 54 with HttpObject

use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.

the class RxNettys method response200OK.

public static Observable<HttpObject> response200OK(final HttpVersion version) {
    final HttpResponse response = new DefaultFullHttpResponse(version, HttpResponseStatus.OK);
    response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
    return Observable.<HttpObject>just(response);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpObject(io.netty.handler.codec.http.HttpObject) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse)

Example 55 with HttpObject

use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.

the class RxNettys method response401Unauthorized.

public static Observable<HttpObject> response401Unauthorized(final HttpVersion version, final String vlaueOfWWWAuthenticate) {
    final HttpResponse response = new DefaultFullHttpResponse(version, HttpResponseStatus.UNAUTHORIZED);
    response.headers().set(HttpHeaderNames.WWW_AUTHENTICATE, vlaueOfWWWAuthenticate);
    response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
    return Observable.<HttpObject>just(response);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpObject(io.netty.handler.codec.http.HttpObject) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse)

Aggregations

HttpObject (io.netty.handler.codec.http.HttpObject)66 Test (org.junit.Test)38 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)31 HttpContent (io.netty.handler.codec.http.HttpContent)29 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)27 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)25 ArrayList (java.util.ArrayList)19 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)16 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)14 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)14 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)14 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)9 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)9 HttpResponse (io.netty.handler.codec.http.HttpResponse)9 Subscription (rx.Subscription)9 Nettys4Test (org.jocean.http.util.Nettys4Test)8 TestSubscriber (rx.observers.TestSubscriber)8 HttpRequest (io.netty.handler.codec.http.HttpRequest)7 DisposableWrapper (org.jocean.idiom.DisposableWrapper)7 Channel (io.netty.channel.Channel)6