use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project vert.x by eclipse.
the class Http1xTest method testInvalidTrailersInHttpClientResponse.
@Test
public void testInvalidTrailersInHttpClientResponse() throws Exception {
server.requestHandler(req -> {
NetSocket so = req.netSocket();
so.write("HTTP/1.1 200 OK\r\n");
so.write("Transfer-Encoding: chunked\r\n");
so.write("\r\n");
so.write("0\r\n");
for (int i = 0; i < 2000; i++) {
so.write("01234567");
}
});
AtomicInteger status = new AtomicInteger();
testHttpClientResponseDecodeError(err -> {
switch(status.incrementAndGet()) {
case 1:
assertTrue(err instanceof TooLongFrameException);
break;
case 2:
assertTrue(err instanceof VertxException);
assertTrue(err.getMessage().equals("Connection was closed"));
testComplete();
break;
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project elasticsearch by elastic.
the class Netty4SizeHeaderFrameDecoder method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
try {
boolean continueProcessing = TcpTransport.validateMessageHeader(Netty4Utils.toBytesReference(in));
final ByteBuf message = in.skipBytes(TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE);
if (!continueProcessing)
return;
out.add(message);
} catch (IllegalArgumentException ex) {
throw new TooLongFrameException(ex);
} catch (IllegalStateException ex) {
/* decode will be called until the ByteBuf is fully consumed; when it is fully
* consumed, transport#validateMessageHeader will throw an IllegalStateException which
* is okay, it means we have finished consuming the ByteBuf and we can get out
*/
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project riposte by Nike-Inc.
the class BackstopperRiposteFrameworkErrorHandlerListenerTest method shouldHandleInvalidHttpRequestExceptionWithNonNullCause.
@DataProvider(value = { "true", "false" })
@Test
public void shouldHandleInvalidHttpRequestExceptionWithNonNullCause(boolean useTooLongFrameExceptionAsCause) {
// given
Throwable cause = (useTooLongFrameExceptionAsCause) ? new TooLongFrameException("TooLongFrameException occurred") : new RuntimeException("runtime exception");
String expectedCauseMetadataMessage = (useTooLongFrameExceptionAsCause) ? listener.TOO_LONG_FRAME_LINE_METADATA_MESSAGE : "Invalid HTTP request";
String outerExceptionMessage = "message - " + UUID.randomUUID().toString();
ApiError expectedApiErrorBase = (useTooLongFrameExceptionAsCause) ? listener.TOO_LONG_FRAME_LINE_API_ERROR_BASE : testProjectApiErrors.getMalformedRequestApiError();
// when
ApiExceptionHandlerListenerResult result = listener.shouldHandleException(new InvalidHttpRequestException(outerExceptionMessage, cause));
// then
assertThat(result.shouldHandleResponse).isTrue();
assertThat(result.errors).isEqualTo(singletonError(new ApiErrorWithMetadata(expectedApiErrorBase, Pair.of("cause", expectedCauseMetadataMessage))));
assertThat(result.extraDetailsForLogging.get(0).getLeft()).isEqualTo("exception_message");
assertThat(result.extraDetailsForLogging.get(0).getRight()).isEqualTo(outerExceptionMessage);
assertThat(result.extraDetailsForLogging.get(1).getLeft()).isEqualTo("exception_cause_details");
assertThat(result.extraDetailsForLogging.get(1).getRight()).isEqualTo(cause.toString());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project reactor-netty by reactor.
the class HttpServerHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
// read message and track if it was keepAlive
if (msg instanceof HttpRequest) {
final HttpRequest request = (HttpRequest) msg;
DecoderResult decoderResult = request.decoderResult();
if (decoderResult.isFailure()) {
Throwable cause = decoderResult.cause();
HttpServerOperations.log.debug("Decoding failed: " + msg + " : ", cause);
HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_0, cause instanceof TooLongFrameException ? HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE : HttpResponseStatus.BAD_REQUEST);
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, 0).set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
return;
}
if (persistentConnection) {
pendingResponses += 1;
if (HttpServerOperations.log.isDebugEnabled()) {
HttpServerOperations.log.debug("Increasing pending responses, now " + "{}", pendingResponses);
}
persistentConnection = isKeepAlive(request);
} else {
if (HttpServerOperations.log.isDebugEnabled()) {
HttpServerOperations.log.debug("dropping pipelined HTTP request, " + "previous response requested connection close");
}
ReferenceCountUtil.release(msg);
return;
}
if (pendingResponses > 1) {
if (HttpServerOperations.log.isDebugEnabled()) {
HttpServerOperations.log.debug("buffering pipelined HTTP request, " + "pending response count: {}, queue: {}", pendingResponses, pipelined != null ? pipelined.size() : 0);
}
overflow = true;
doPipeline(ctx, msg);
return;
} else {
overflow = false;
parentContext.createOperations(ctx.channel(), msg);
if (!(msg instanceof FullHttpRequest)) {
return;
}
}
} else if (persistentConnection && pendingResponses == 0) {
if (HttpServerOperations.log.isDebugEnabled()) {
HttpServerOperations.log.debug("Dropped HTTP content, " + "Since response has been sent already:{}", msg);
}
if (msg instanceof LastHttpContent) {
ctx.fireChannelRead(msg);
} else {
ReferenceCountUtil.release(msg);
}
ctx.read();
return;
} else if (overflow) {
if (HttpServerOperations.log.isDebugEnabled()) {
HttpServerOperations.log.debug("buffering pipelined HTTP content, " + "pending response count: {}, pending pipeline:{}", pendingResponses, pipelined != null ? pipelined.size() : 0);
}
doPipeline(ctx, msg);
return;
}
ctx.fireChannelRead(msg);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project teiid by teiid.
the class ObjectDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
if (result == null) {
ByteBuf frame = null;
try {
frame = (ByteBuf) super.decode(ctx, buffer);
} catch (TooLongFrameException e) {
throw new IOException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40166), e);
}
if (frame == null) {
return null;
}
CompactObjectInputStream cois = new CompactObjectInputStream(new ByteBufInputStream(frame), classLoader);
result = cois.readObject();
streams = ExternalizeUtil.readList(cois, StreamFactoryReference.class);
streamIndex = 0;
}
while (streamIndex < streams.size()) {
// read the new chunk size
if (streamDataToRead == -1) {
if (buffer.readableBytes() < 2) {
return null;
}
streamDataToRead = buffer.readUnsignedShort();
}
if (stream == null) {
// $NON-NLS-1$
store = storageManager.createFileStore("temp-stream");
StreamFactoryReference sfr = streams.get(streamIndex);
sfr.setStreamFactory(new FileStoreInputStreamFactory(store, Streamable.ENCODING));
this.stream = new BufferedOutputStream(store.createOutputStream());
}
// end of stream
if (streamDataToRead == 0) {
stream.close();
stream = null;
streamIndex++;
streamDataToRead = -1;
continue;
}
if (store.getLength() + streamDataToRead > maxLobSize) {
if (error == null) {
error = new StreamCorruptedException(// $NON-NLS-1$ //$NON-NLS-2$
"lob too big: " + (store.getLength() + streamDataToRead) + " (max: " + maxLobSize + ')');
}
}
int toRead = Math.min(buffer.readableBytes(), streamDataToRead);
if (toRead == 0) {
return null;
}
if (error == null) {
buffer.readBytes(this.stream, toRead);
} else {
buffer.skipBytes(toRead);
}
streamDataToRead -= toRead;
if (streamDataToRead == 0) {
// get the next chunk
streamDataToRead = -1;
}
}
Object toReturn = result;
result = null;
streams = null;
stream = null;
store = null;
if (error != null) {
StreamCorruptedException sce = error;
error = null;
throw sce;
}
return toReturn;
}
Aggregations