Search in sources :

Example 1 with DecoderResultProvider

use of io.netty.handler.codec.DecoderResultProvider in project netty by netty.

the class HttpObjectAggregatorTest method testBadResponse.

@Test
public void testBadResponse() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder(), new HttpObjectAggregator(1024 * 1024));
    ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.0 BAD_CODE Bad Server\r\n", CharsetUtil.UTF_8));
    Object inbound = ch.readInbound();
    assertThat(inbound, is(instanceOf(FullHttpResponse.class)));
    assertTrue(((DecoderResultProvider) inbound).decoderResult().isFailure());
    assertNull(ch.readInbound());
    ch.finish();
}
Also used : DecoderResultProvider(io.netty.handler.codec.DecoderResultProvider) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 2 with DecoderResultProvider

use of io.netty.handler.codec.DecoderResultProvider in project async-http-client by AsyncHttpClient.

the class HttpHandler method handleRead.

@Override
public void handleRead(final Channel channel, final NettyResponseFuture<?> future, final Object e) throws Exception {
    // future is already done because of an exception or a timeout
    if (future.isDone()) {
        // FIXME isn't the channel already properly closed?
        channelManager.closeChannel(channel);
        return;
    }
    AsyncHandler<?> handler = future.getAsyncHandler();
    try {
        if (e instanceof DecoderResultProvider) {
            DecoderResultProvider object = (DecoderResultProvider) e;
            Throwable t = object.decoderResult().cause();
            if (t != null) {
                readFailed(channel, future, t);
                return;
            }
        }
        if (e instanceof HttpResponse) {
            handleHttpResponse((HttpResponse) e, channel, future, handler);
        } else if (e instanceof HttpContent) {
            handleChunk((HttpContent) e, channel, future, handler);
        }
    } catch (Exception t) {
        // next request
        if (// 
        hasIOExceptionFilters && // 
        t instanceof IOException && requestSender.applyIoExceptionFiltersAndReplayRequest(future, (IOException) t, channel)) {
            return;
        }
        readFailed(channel, future, t);
        throw t;
    }
}
Also used : DecoderResultProvider(io.netty.handler.codec.DecoderResultProvider) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with DecoderResultProvider

use of io.netty.handler.codec.DecoderResultProvider in project netty by netty.

the class HttpObjectAggregatorTest method testBadRequest.

@Test
public void testBadRequest() {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder(), new HttpObjectAggregator(1024 * 1024));
    ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8));
    Object inbound = ch.readInbound();
    assertThat(inbound, is(instanceOf(FullHttpRequest.class)));
    assertTrue(((DecoderResultProvider) inbound).decoderResult().isFailure());
    assertNull(ch.readInbound());
    ch.finish();
}
Also used : DecoderResultProvider(io.netty.handler.codec.DecoderResultProvider) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Aggregations

DecoderResultProvider (io.netty.handler.codec.DecoderResultProvider)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 Test (org.junit.Test)2 IOException (java.io.IOException)1