Search in sources :

Example 1 with HttpPipelinedRequest

use of org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest in project elasticsearch by elastic.

the class Netty4HttpRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    final FullHttpRequest request;
    final HttpPipelinedRequest pipelinedRequest;
    if (this.httpPipeliningEnabled && msg instanceof HttpPipelinedRequest) {
        pipelinedRequest = (HttpPipelinedRequest) msg;
        request = (FullHttpRequest) pipelinedRequest.last();
    } else {
        pipelinedRequest = null;
        request = (FullHttpRequest) msg;
    }
    final FullHttpRequest copy = new DefaultFullHttpRequest(request.protocolVersion(), request.method(), request.uri(), Unpooled.copiedBuffer(request.content()), request.headers(), request.trailingHeaders());
    final Netty4HttpRequest httpRequest = new Netty4HttpRequest(serverTransport.xContentRegistry, copy, ctx.channel());
    final Netty4HttpChannel channel = new Netty4HttpChannel(serverTransport, httpRequest, pipelinedRequest, detailedErrorsEnabled, threadContext);
    if (request.decoderResult().isSuccess()) {
        serverTransport.dispatchRequest(httpRequest, channel);
    } else {
        assert request.decoderResult().isFailure();
        serverTransport.dispatchBadRequest(httpRequest, channel, request.decoderResult().cause());
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpPipelinedRequest(org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest)

Example 2 with HttpPipelinedRequest

use of org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest in project elasticsearch by elastic.

the class Netty4HttpChannelTests method testReleaseOnSendToClosedChannel.

public void testReleaseOnSendToClosedChannel() {
    final Settings settings = Settings.builder().build();
    final NamedXContentRegistry registry = xContentRegistry();
    try (Netty4HttpServerTransport httpServerTransport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, registry, new NullDispatcher())) {
        final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
        final Netty4HttpRequest request = new Netty4HttpRequest(registry, httpRequest, embeddedChannel);
        final HttpPipelinedRequest pipelinedRequest = randomBoolean() ? new HttpPipelinedRequest(request.request(), 1) : null;
        final Netty4HttpChannel channel = new Netty4HttpChannel(httpServerTransport, request, pipelinedRequest, randomBoolean(), threadPool.getThreadContext());
        final TestResponse response = new TestResponse(bigArrays);
        assertThat(response.content(), instanceOf(Releasable.class));
        embeddedChannel.close();
        channel.sendResponse(response);
    // ESTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
    }
}
Also used : NullDispatcher(org.elasticsearch.http.NullDispatcher) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpPipelinedRequest(org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest) Releasable(org.elasticsearch.common.lease.Releasable) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings) HttpTransportSettings(org.elasticsearch.http.HttpTransportSettings)

Aggregations

DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 HttpPipelinedRequest (org.elasticsearch.http.netty4.pipelining.HttpPipelinedRequest)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Releasable (org.elasticsearch.common.lease.Releasable)1 Settings (org.elasticsearch.common.settings.Settings)1 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)1 HttpTransportSettings (org.elasticsearch.http.HttpTransportSettings)1 NullDispatcher (org.elasticsearch.http.NullDispatcher)1