本文整理了Java中io.netty.handler.codec.TooLongFrameException
类的一些代码示例,展示了TooLongFrameException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TooLongFrameException
类的具体详情如下:
包路径:io.netty.handler.codec.TooLongFrameException
类名称:TooLongFrameException
[英]An DecoderException which is thrown when the length of the frame decoded is greater than the allowed maximum.
[中]当解码帧的长度大于允许的最大值时抛出的DecoderException。
代码示例来源:origin: netty/netty
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (state == ST_CORRUPTED) {
in.skipBytes(in.readableBytes());
return;
if (this.idx > in.readerIndex() && lastReaderIndex != in.readerIndex()) {
this.idx = in.readerIndex() + (idx - lastReaderIndex);
in.skipBytes(in.readableBytes());
reset();
throw new TooLongFrameException(
"object length exceeds " + maxObjectLength + ": " + wrtIdx + " bytes discarded");
state = ST_CORRUPTED;
throw new CorruptedFrameException(
"invalid JSON received at byte position " + idx + ": " + ByteBufUtil.hexDump(in));
代码示例来源:origin: wildfly/wildfly
int length = data.readableBytes();
throw new TooLongFrameException("invalid payload for PING (payload length must be <= 125, was "
+ length);
size += length;
buf = ctx.alloc().buffer(size);
buf.writeByte(b0);
byte b = (byte) (maskPayload ? 0x80 | (byte) length : (byte) length);
buf.writeByte(b);
} else if (length <= 0xFFFF) {
int size = 4 + maskLength;
size += length;
buf = ctx.alloc().buffer(size);
buf.writeByte(b0);
buf.writeByte(maskPayload ? 0xFE : 126);
size += length;
buf = ctx.alloc().buffer(size);
buf.writeByte(b0);
buf.writeByte(maskPayload ? 0xFF : 127);
代码示例来源:origin: wildfly/wildfly
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.INVALID_STREAM);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.PROTOCOL_ERROR);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.INTERNAL_ERROR);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
HttpUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes());
removeMessage(streamId);
out.add(fullHttpMessage);
if (content.readableBytes() > maxContentLength - spdyDataFrame.content().readableBytes()) {
removeMessage(streamId);
throw new TooLongFrameException(
"HTTP content length exceeded " + maxContentLength + " bytes.");
代码示例来源:origin: wildfly/wildfly
private WebSocketFrame decodeTextFrame(ChannelHandlerContext ctx, ByteBuf buffer) {
int ridx = buffer.readerIndex();
int rbytes = actualReadableBytes();
int delimPos = buffer.indexOf(ridx, ridx + rbytes, (byte) 0xFF);
if (delimPos == -1) {
throw new TooLongFrameException();
} else {
throw new TooLongFrameException();
ByteBuf binaryData = readBytes(ctx.alloc(), buffer, frameSize);
buffer.skipBytes(1);
int ffDelimPos = binaryData.indexOf(binaryData.readerIndex(), binaryData.writerIndex(), (byte) 0xFF);
代码示例来源:origin: wildfly/wildfly
ChannelFuture future = ctx.writeAndFlush(TOO_LARGE_CLOSE.retainedDuplicate());
future.addListener(new ChannelFutureListener() {
@Override
ctx.writeAndFlush(TOO_LARGE.retainedDuplicate()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
HttpObjectDecoder decoder = ctx.pipeline().get(HttpObjectDecoder.class);
if (decoder != null) {
decoder.reset();
ctx.close();
throw new TooLongFrameException("Response entity too large: " + oversized);
} else {
throw new IllegalStateException();
代码示例来源:origin: mpusher/mpush
private Packet decodeFrame(ByteBuf in) {
int readableBytes = in.readableBytes();
int bodyLength = in.readInt();
if (readableBytes < (bodyLength + Packet.HEADER_LEN)) {
return null;
}
if (bodyLength > maxPacketSize) {
throw new TooLongFrameException("packet body length over limit:" + bodyLength);
}
return decodePacket(new Packet(in.readByte()), in, bodyLength);
}
代码示例来源:origin: normanmaurer/netty-in-action
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in,
List<Object> out)
throws Exception {
int readableBytes = in.readableBytes();
if (readableBytes > maxFrameSize) {
// discard the bytes
in.clear();
throw new TooLongFrameException();
}
ByteBuf buf = in.readBytes(readableBytes);
out.add(buf);
}
}
代码示例来源:origin: com.linkedin.pegasus/r2-netty
public void processHttpChunk(HttpContent chunk) throws TooLongFrameException
if (chunk.content().readableBytes() + _totalBytesWritten > _maxContentLength)
TooLongFrameException ex = new TooLongFrameException("HTTP content length exceeded " + _maxContentLength +
" bytes.");
fail(ex);
if (chunk.content().isReadable())
try
data = ByteString.read(is, rawData.readableBytes());
if (_bufferedBytes > _highWaterMark && _ctx.channel().config().isAutoRead())
_ctx.channel().config().setAutoRead(false);
代码示例来源:origin: normanmaurer/netty-in-action
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf in,
List<Object> out) throws Exception {
int readable = in.readableBytes();
if (readable > MAX_FRAME_SIZE) {
in.skipBytes(readable);
throw new TooLongFrameException("Frame too big!");
}
// do something
// ...
}
}
代码示例来源:origin: wildfly/wildfly
private WebSocketFrame decodeBinaryFrame(ChannelHandlerContext ctx, byte type, ByteBuf buffer) {
long frameSize = 0;
int lengthFieldSize = 0;
byte b;
do {
b = buffer.readByte();
frameSize <<= 7;
frameSize |= b & 0x7f;
if (frameSize > maxFrameSize) {
throw new TooLongFrameException();
}
lengthFieldSize++;
if (lengthFieldSize > 8) {
// Perhaps a malicious peer?
throw new TooLongFrameException();
}
} while ((b & 0x80) == 0x80);
if (type == (byte) 0xFF && frameSize == 0) {
receivedClosingHandshake = true;
return new CloseWebSocketFrame();
}
ByteBuf payload = readBytes(ctx.alloc(), buffer, (int) frameSize);
return new BinaryWebSocketFrame(payload);
}
代码示例来源:origin: org.elasticsearch.plugin/transport-netty4-client
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
try {
boolean continueDecode = true;
while (continueDecode) {
int messageLength = TcpTransport.readMessageLength(Netty4Utils.toBytesReference(in));
if (messageLength == -1) {
continueDecode = false;
} else {
int messageLengthWithHeader = messageLength + HEADER_SIZE;
// If the message length is greater than the network bytes available, we have not read a complete frame.
if (messageLengthWithHeader > in.readableBytes()) {
continueDecode = false;
} else {
final ByteBuf message = in.retainedSlice(in.readerIndex() + HEADER_SIZE, messageLength);
out.add(message);
in.readerIndex(in.readerIndex() + messageLengthWithHeader);
}
}
}
} catch (IllegalArgumentException ex) {
throw new TooLongFrameException(ex);
}
}
代码示例来源:origin: com.linkedin.pegasus/r2-netty
public void onDataRead(ByteBuf data, boolean end) throws TooLongFrameException
if (data.readableBytes() + _totalBytesWritten > _maxContentLength)
doResetAndNotify(new TooLongFrameException("HTTP content length exceeded " + _maxContentLength + " bytes."));
if (data.isReadable())
try
bytes = ByteString.read(is, data.readableBytes());
代码示例来源:origin: netty/netty
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
if (discardingTooLongFrame) {
buffer.skipBytes(actualReadableBytes());
checkpoint();
return;
}
Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
ByteInput input = new ChannelBufferByteInput(buffer);
if (maxObjectSize != Integer.MAX_VALUE) {
input = new LimitingByteInput(input, maxObjectSize);
}
try {
unmarshaller.start(input);
Object obj = unmarshaller.readObject();
unmarshaller.finish();
out.add(obj);
} catch (LimitingByteInput.TooBigObjectException ignored) {
discardingTooLongFrame = true;
throw new TooLongFrameException();
} finally {
// Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are
// readable. This helps to be sure that we do not leak resource
unmarshaller.close();
}
}
代码示例来源:origin: esl-client/esl-client
private String readLine(ByteBuf buffer, int maxLineLength) throws TooLongFrameException {
StringBuilder sb = new StringBuilder(64);
while (buffer.isReadable()) {
// this read should always succeed
byte nextByte = buffer.readByte();
if (nextByte == LF) {
return sb.toString();
} else {
// Abort decoding if the decoded line is too large.
if (sb.length() >= maxLineLength) {
throw new TooLongFrameException(
"ESL message line is longer than " + maxLineLength + " bytes.");
}
sb.append((char) nextByte);
}
}
return sb.toString();
}
}
代码示例来源:origin: netty/netty
private void fail(final ChannelHandlerContext ctx, String length) {
ctx.fireExceptionCaught(
new TooLongFrameException(
"frame length (" + length + ") exceeds the allowed maximum (" + maxLength + ')'));
}
代码示例来源:origin: esl-client/esl-client
private String readToLineFeedOrFail(ByteBuf buffer, int maxLineLegth) throws TooLongFrameException {
StringBuilder sb = new StringBuilder(64);
while (true) {
// this read might fail
byte nextByte = buffer.readByte();
if (nextByte == LF) {
return sb.toString();
} else {
// Abort decoding if the decoded line is too large.
if (sb.length() >= maxLineLegth) {
throw new TooLongFrameException(
"ESL header line is longer than " + maxLineLegth + " bytes.");
}
sb.append((char) nextByte);
}
}
}
代码示例来源:origin: netty/netty
private void fail(long frameLength) {
if (frameLength > 0) {
throw new TooLongFrameException(
"frame length exceeds " + maxFrameLength +
": " + frameLength + " - discarded");
} else {
throw new TooLongFrameException(
"frame length exceeds " + maxFrameLength +
" - discarding");
}
}
代码示例来源:origin: Nike-Inc/riposte
private Integer extractTooLongFrameMaxSizeFromExceptionMessage(TooLongFrameException ex) {
String exMessage = ex.getMessage();
if (exMessage == null || !exMessage.endsWith(" bytes.")) {
return null;
}
try {
String[] messageWords = exMessage.split(" ");
String maxSizeWord = messageWords[messageWords.length - 2];
return Integer.parseInt(maxSizeWord);
}
catch(Throwable t) {
// Couldn't parse it for some reason.
logger.debug("Unable to parse max size from TooLongFrameException. ex_message={}", exMessage, t);
return null;
}
}
代码示例来源:origin: io.netty/netty-codec-http
int length = data.readableBytes();
throw new TooLongFrameException("invalid payload for PING (payload length must be <= 125, was "
+ length);
size += length;
buf = ctx.alloc().buffer(size);
buf.writeByte(b0);
byte b = (byte) (maskPayload ? 0x80 | (byte) length : (byte) length);
buf.writeByte(b);
} else if (length <= 0xFFFF) {
int size = 4 + maskLength;
size += length;
buf = ctx.alloc().buffer(size);
buf.writeByte(b0);
buf.writeByte(maskPayload ? 0xFE : 126);
size += length;
buf = ctx.alloc().buffer(size);
buf.writeByte(b0);
buf.writeByte(maskPayload ? 0xFF : 127);
代码示例来源:origin: io.netty/netty-codec-http
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.INVALID_STREAM);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.PROTOCOL_ERROR);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.INTERNAL_ERROR);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
HttpUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes());
removeMessage(streamId);
out.add(fullHttpMessage);
if (content.readableBytes() > maxContentLength - spdyDataFrame.content().readableBytes()) {
removeMessage(streamId);
throw new TooLongFrameException(
"HTTP content length exceeded " + maxContentLength + " bytes.");
内容来源于网络,如有侵权,请联系作者删除!