Search in sources :

Example 21 with TooLongFrameException

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project nuls by nuls-io.

the class ClientChannelHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (!(cause instanceof IOException) && !(cause instanceof TooLongFrameException)) {
        Attribute<Node> nodeAttribute = ctx.channel().attr(NodeAttributeKey.NODE_KEY);
        Node node = nodeAttribute.get();
        Log.error("----------------nodeId:" + node.getId());
        Log.error(cause);
    }
    ctx.close();
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) Node(io.nuls.network.model.Node) IOException(java.io.IOException)

Example 22 with TooLongFrameException

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project vert.x by eclipse.

the class ServerConnection method processMessage.

private void processMessage(Object msg) {
    if (msg instanceof HttpObject) {
        HttpObject obj = (HttpObject) msg;
        DecoderResult result = obj.decoderResult();
        if (result.isFailure()) {
            Throwable cause = result.cause();
            if (cause instanceof TooLongFrameException) {
                String causeMsg = cause.getMessage();
                HttpVersion version;
                if (msg instanceof HttpRequest) {
                    version = ((HttpRequest) msg).protocolVersion();
                } else if (currentRequest != null) {
                    version = currentRequest.version() == io.vertx.core.http.HttpVersion.HTTP_1_0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1;
                } else {
                    version = HttpVersion.HTTP_1_1;
                }
                HttpResponseStatus status = causeMsg.startsWith("An HTTP line is larger than") ? HttpResponseStatus.REQUEST_URI_TOO_LONG : HttpResponseStatus.BAD_REQUEST;
                DefaultFullHttpResponse resp = new DefaultFullHttpResponse(version, status);
                writeToChannel(resp);
            }
            // That will close the connection as it is considered as unusable
            channel.pipeline().fireExceptionCaught(result.cause());
            return;
        }
        if (msg instanceof HttpRequest) {
            HttpRequest request = (HttpRequest) msg;
            if (server.options().isHandle100ContinueAutomatically()) {
                if (HttpHeaders.is100ContinueExpected(request)) {
                    write100Continue();
                }
            }
            HttpServerResponseImpl resp = new HttpServerResponseImpl(vertx, this, request);
            HttpServerRequestImpl req = new HttpServerRequestImpl(this, request, resp);
            handleRequest(req, resp);
        }
        if (msg instanceof HttpContent) {
            HttpContent chunk = (HttpContent) msg;
            if (chunk.content().isReadable()) {
                Buffer buff = Buffer.buffer(chunk.content());
                handleChunk(buff);
            }
            //TODO chunk trailers
            if (msg instanceof LastHttpContent) {
                if (!paused) {
                    handleEnd();
                } else {
                    // Requeue
                    pending.add(LastHttpContent.EMPTY_LAST_CONTENT);
                }
            }
        }
    } else if (msg instanceof WebSocketFrameInternal) {
        WebSocketFrameInternal frame = (WebSocketFrameInternal) msg;
        handleWsFrame(frame);
    }
    checkNextTick();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) WebSocketFrameInternal(io.vertx.core.http.impl.ws.WebSocketFrameInternal) DecoderResult(io.netty.handler.codec.DecoderResult) HttpVersion(io.netty.handler.codec.http.HttpVersion)

Example 23 with TooLongFrameException

use of org.apache.flink.shaded.netty4.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 24 with TooLongFrameException

use of org.apache.flink.shaded.netty4.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 25 with TooLongFrameException

use of org.apache.flink.shaded.netty4.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)

Aggregations

TooLongFrameException (io.netty.handler.codec.TooLongFrameException)33 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 Test (org.junit.jupiter.api.Test)4 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)3 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)3 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 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)2 HttpResponse (io.netty.handler.codec.http.HttpResponse)2 io.vertx.core (io.vertx.core)2