Search in sources :

Example 21 with TooLongFrameException

use of io.netty.handler.codec.TooLongFrameException in project vert.x by eclipse.

the class Http1xTest method testServerConnectionExceptionHandler.

@Test
public void testServerConnectionExceptionHandler() throws Exception {
    server.connectionHandler(conn -> {
        conn.exceptionHandler(err -> {
            assertTrue(err instanceof TooLongFrameException);
            testComplete();
        });
    });
    server.requestHandler(req -> {
        fail();
    });
    CountDownLatch listenLatch = new CountDownLatch(1);
    server.listen(onSuccess(s -> listenLatch.countDown()));
    awaitLatch(listenLatch);
    HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
    });
    req.putHeader("the_header", TestUtils.randomAlphaString(10000));
    req.sendHead();
    await();
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) io.vertx.core(io.vertx.core) io.vertx.core.impl(io.vertx.core.impl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) io.vertx.core.net(io.vertx.core.net) AtomicReference(java.util.concurrent.atomic.AtomicReference) io.vertx.core.http(io.vertx.core.http) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientRequestImpl(io.vertx.core.http.impl.HttpClientRequestImpl) Buffer(io.vertx.core.buffer.Buffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestUtils(io.vertx.test.core.TestUtils) RecordParser(io.vertx.core.parsetools.RecordParser) Pump(io.vertx.core.streams.Pump) JsonObject(io.vertx.core.json.JsonObject) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 22 with TooLongFrameException

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

the class StompSubframeDecoder method readLine.

private static String readLine(ByteBuf buffer, int maxLineLength) {
    AppendableCharSequence buf = new AppendableCharSequence(128);
    int lineLength = 0;
    for (; ; ) {
        byte nextByte = buffer.readByte();
        if (nextByte == StompConstants.CR) {
            nextByte = buffer.readByte();
            if (nextByte == StompConstants.LF) {
                return buf.toString();
            }
        } else if (nextByte == StompConstants.LF) {
            return buf.toString();
        } else {
            if (lineLength >= maxLineLength) {
                throw new TooLongFrameException("An STOMP line is larger than " + maxLineLength + " bytes.");
            }
            lineLength++;
            buf.append((char) nextByte);
        }
    }
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) AppendableCharSequence(io.netty.util.internal.AppendableCharSequence)

Example 23 with TooLongFrameException

use of io.netty.handler.codec.TooLongFrameException in project riposte by Nike-Inc.

the class BackstopperRiposteFrameworkErrorHandlerListenerTest method shouldHandleTooLongFrameExceptionAndAddCauseMetadata.

@Test
public void shouldHandleTooLongFrameExceptionAndAddCauseMetadata() {
    ApiExceptionHandlerListenerResult result = listener.shouldHandleException(new TooLongFrameException());
    assertThat(result.shouldHandleResponse).isTrue();
    assertThat(result.errors).isEqualTo(singletonError(testProjectApiErrors.getMalformedRequestApiError()));
    assertThat(result.errors.first().getMetadata().get("cause")).isEqualTo("The request exceeded the maximum payload size allowed");
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) ApiExceptionHandlerListenerResult(com.nike.backstopper.handler.listener.ApiExceptionHandlerListenerResult) Test(org.junit.Test)

Example 24 with TooLongFrameException

use of io.netty.handler.codec.TooLongFrameException in project bookkeeper by apache.

the class PerChannelBookieClient method exceptionCaught.

/**
 * Called by netty when an exception happens in one of the netty threads
 * (mostly due to what we do in the netty threads).
 */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    exceptionCounter.inc();
    if (cause instanceof CorruptedFrameException || cause instanceof TooLongFrameException) {
        LOG.error("Corrupted frame received from bookie: {}", ctx.channel().remoteAddress());
        ctx.close();
        return;
    }
    if (cause instanceof AuthHandler.AuthenticationException) {
        LOG.error("Error authenticating connection", cause);
        errorOutOutstandingEntries(BKException.Code.UnauthorizedAccessException);
        Channel c = ctx.channel();
        if (c != null) {
            closeChannel(c);
        }
        return;
    }
    if (cause instanceof DecoderException && cause.getCause() instanceof SSLHandshakeException) {
        LOG.error("TLS handshake failed", cause);
        errorOutPendingOps(BKException.Code.SecurityException);
        Channel c = ctx.channel();
        if (c != null) {
            closeChannel(c);
        }
    }
    if (cause instanceof IOException) {
        LOG.warn("Exception caught on:{} cause:", ctx.channel(), cause);
        ctx.close();
        return;
    }
    synchronized (this) {
        if (state == ConnectionState.CLOSED) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unexpected exception caught by bookie client channel handler, " + "but the client is closed, so it isn't important", cause);
            }
        } else {
            LOG.error("Unexpected exception caught by bookie client channel handler", cause);
        }
    }
    // Since we are a library, cant terminate App here, can we?
    ctx.close();
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) CorruptedFrameException(io.netty.handler.codec.CorruptedFrameException) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) Channel(io.netty.channel.Channel) LocalChannel(io.netty.channel.local.LocalChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) IOException(java.io.IOException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 25 with TooLongFrameException

use of io.netty.handler.codec.TooLongFrameException in project graylog2-server by Graylog2.

the class LenientDelimiterBasedFrameDecoderTest method testFailSlowTooLongFrameRecovery.

@Test
public void testFailSlowTooLongFrameRecovery() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientDelimiterBasedFrameDecoder(1, true, false, false, Delimiters.nulDelimiter()));
    for (int i = 0; i < 2; i++) {
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }));
        try {
            assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0 })));
            fail(DecoderException.class.getSimpleName() + " must be raised.");
        } catch (TooLongFrameException e) {
        // Expected
        }
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 }));
        ByteBuf buf = ch.readInbound();
        assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
        buf.release();
    }
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

TooLongFrameException (io.netty.handler.codec.TooLongFrameException)31 ByteBuf (io.netty.buffer.ByteBuf)15 Test (org.junit.Test)9 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)7 Channel (io.netty.channel.Channel)5 Buffer (io.vertx.core.buffer.Buffer)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CorruptedFrameException (io.netty.handler.codec.CorruptedFrameException)4 TestUtils (io.vertx.test.core.TestUtils)4 java.util (java.util)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Test (org.junit.jupiter.api.Test)4 ChannelHandler (io.netty.channel.ChannelHandler)2 EventLoop (io.netty.channel.EventLoop)2 DecoderException (io.netty.handler.codec.DecoderException)2 DelimiterBasedFrameDecoder (io.netty.handler.codec.DelimiterBasedFrameDecoder)2 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 io.vertx.core (io.vertx.core)2 Future (io.vertx.core.Future)2