本文整理汇总了Java中io.netty.handler.codec.DecoderResult类的典型用法代码示例。如果您正苦于以下问题:Java DecoderResult类的具体用法?Java DecoderResult怎么用?Java DecoderResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DecoderResult类属于io.netty.handler.codec包,在下文中一共展示了DecoderResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invalidMessage
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
private HttpMessage invalidMessage(ByteBuf in, Exception cause) {
currentState = State.BAD_MESSAGE;
// Advance the readerIndex so that ByteToMessageDecoder does not complain
// when we produced an invalid message without consuming anything.
in.skipBytes(in.readableBytes());
if (message != null) {
message.setDecoderResult(DecoderResult.failure(cause));
} else {
message = createInvalidMessage();
message.setDecoderResult(DecoderResult.failure(cause));
}
HttpMessage ret = message;
message = null;
return ret;
}
示例2: testBadChunk
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Test
public void testBadChunk() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder());
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0\r\n", CharsetUtil.UTF_8));
ch.writeInbound(Unpooled.copiedBuffer("Transfer-Encoding: chunked\r\n\r\n", CharsetUtil.UTF_8));
ch.writeInbound(Unpooled.copiedBuffer("BAD_LENGTH\r\n", CharsetUtil.UTF_8));
HttpRequest req = (HttpRequest) ch.readInbound();
assertTrue(req.getDecoderResult().isSuccess());
LastHttpContent chunk = (LastHttpContent) ch.readInbound();
DecoderResult dr = chunk.getDecoderResult();
assertFalse(dr.isSuccess());
assertTrue(dr.isFailure());
ensureInboundTrafficDiscarded(ch);
}
示例3: testBadChunk
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Test
public void testBadChunk() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder());
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0\r\n", CharsetUtil.UTF_8));
ch.writeInbound(Unpooled.copiedBuffer("Transfer-Encoding: chunked\r\n\r\n", CharsetUtil.UTF_8));
ch.writeInbound(Unpooled.copiedBuffer("BAD_LENGTH\r\n", CharsetUtil.UTF_8));
HttpRequest req = (HttpRequest) ch.readInbound();
assertTrue(req.getDecoderResult().isSuccess());
HttpContent chunk = (HttpContent) ch.readInbound();
DecoderResult dr = chunk.getDecoderResult();
assertFalse(dr.isSuccess());
assertTrue(dr.isFailure());
ensureInboundTrafficDiscarded(ch);
}
示例4: testBadChunk
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Test
public void testBadChunk() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder());
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0\r\n", CharsetUtil.UTF_8));
ch.writeInbound(Unpooled.copiedBuffer("Transfer-Encoding: chunked\r\n\r\n", CharsetUtil.UTF_8));
ch.writeInbound(Unpooled.copiedBuffer("BAD_LENGTH\r\n", CharsetUtil.UTF_8));
HttpRequest req = ch.readInbound();
assertTrue(req.getDecoderResult().isSuccess());
HttpContent chunk = ch.readInbound();
DecoderResult dr = chunk.getDecoderResult();
assertFalse(dr.isSuccess());
assertTrue(dr.isFailure());
ensureInboundTrafficDiscarded(ch);
}
示例5: MqttMessage
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
public MqttMessage(
MqttFixedHeader fixedHeader,
Object variableHeader,
Object payload,
DecoderResult decoderResult) {
this.fixedHeader = fixedHeader;
this.variableHeader = variableHeader;
this.payload = payload;
this.decoderResult = decoderResult;
}
示例6: MqttMessage
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
public MqttMessage(
MqttFixedHeader mqttFixedHeader,
Object variableHeader,
Object payload,
DecoderResult decoderResult) {
this.mqttFixedHeader = mqttFixedHeader;
this.variableHeader = variableHeader;
this.payload = payload;
this.decoderResult = decoderResult;
}
示例7: appendDecoderResult
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
private static void appendDecoderResult(StringBuilder buf, HttpObject o) {
DecoderResult result = o.getDecoderResult();
if (result.isSuccess()) {
return;
}
buf.append(".. WITH DECODER FAILURE: ");
buf.append(result.cause());
buf.append("\r\n");
}
示例8: channelRead0
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest httpRequest) throws Exception {
DecoderResult result = httpRequest.decoderResult();
if (!result.isSuccess()) {
throw new BadRequestException(result.cause());
}
logger.info("Get search request: " + httpRequest.uri());
// only decode get path is enough
Map<String, List<String>> requestParameters;
QueryStringDecoder stringDecoder = new QueryStringDecoder(httpRequest.uri());
requestParameters = stringDecoder.parameters();
QueryMeta meta = new QueryMeta();
for(Map.Entry<String, List<String>> entry : requestParameters.entrySet()) {
if (entry.getKey().equals("options[]")) {
// add filters
List<String> filters = entry.getValue();
filters.forEach(filter -> {
String[] typeVal = filter.split(":");
meta.addMeta(typeVal[0], typeVal[1]);
});
} else if (entry.getKey().equals("orderby")) {
meta.setOrderBy(entry.getValue().get(0));
} else {
logger.warn("Unknown query parameter, ignore it:" + entry.toString());
}
}
DecodedSearchRequest searchRequest = new DecodedSearchRequest(httpRequest, meta, orderNumber++);
ctx.fireChannelRead(searchRequest);
}
示例9: doChannelRead_HttpRequest_throws_exception_when_failed_decoder_result
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Test
public void doChannelRead_HttpRequest_throws_exception_when_failed_decoder_result() {
// given
HttpRequest msgMock = mock(HttpRequest.class);
DecoderResult decoderResult = mock(DecoderResult.class);
doReturn(true).when(decoderResult).isFailure();
doReturn(decoderResult).when(msgMock).getDecoderResult();
// when
Throwable thrownException = Assertions.catchThrowable(() -> handler.doChannelRead(ctxMock, msgMock));
// then
assertThat(thrownException).isExactlyInstanceOf(InvalidHttpRequestException.class);
}
示例10: doChannelRead_HttpContent_throws_exception_when_failed_decoder_result
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Test
public void doChannelRead_HttpContent_throws_exception_when_failed_decoder_result() {
// given
DecoderResult decoderResult = mock(DecoderResult.class);
doReturn(true).when(decoderResult).isFailure();
doReturn(decoderResult).when(httpContentMock).getDecoderResult();
// when
Throwable thrownException = Assertions.catchThrowable(() -> handler.doChannelRead(ctxMock, httpContentMock));
// then
assertThat(thrownException).isExactlyInstanceOf(InvalidHttpRequestException.class);
verify(httpContentMock).release();
}
示例11: channelRead
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Override
final public void channelRead(ChannelHandlerContext ctx, Object msg)
throws Exception {
if (msg == null || msg == Unpooled.EMPTY_BUFFER || msg instanceof EmptyByteBuf) {
return;
}
try {
ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
if (ops != null) {
ops.onInboundNext(ctx, msg);
}
else {
if (log.isDebugEnabled()) {
String loggingMsg = msg.toString();
if (msg instanceof HttpResponse) {
DecoderResult decoderResult = ((HttpResponse) msg).decoderResult();
if (decoderResult.isFailure()) {
log.debug("Decoding failed: " + msg + " : ", decoderResult.cause());
}
}
if (msg instanceof ByteBufHolder) {
loggingMsg = ((ByteBufHolder) msg).content()
.toString(Charset.defaultCharset());
}
log.debug("{} No ChannelOperation attached. Dropping: {}", ctx
.channel().toString(), loggingMsg);
}
ReferenceCountUtil.release(msg);
}
}
catch (Throwable err) {
Exceptions.throwIfFatal(err);
exceptionCaught(ctx, err);
ReferenceCountUtil.safeRelease(msg);
}
}
示例12: appendDecoderResult
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
private static void appendDecoderResult(StringBuilder buf, HttpObject o) {
DecoderResult result = o.decoderResult();
if (result.isSuccess()) {
return;
}
buf.append(".. WITH DECODER FAILURE: ");
buf.append(result.cause());
buf.append("\r\n");
}
示例13: invalidChunk
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
private HttpContent invalidChunk(ByteBuf in, Exception cause) {
currentState = State.BAD_MESSAGE;
// Advance the readerIndex so that ByteToMessageDecoder does not complain
// when we produced an invalid message without consuming anything.
in.skipBytes(in.readableBytes());
HttpContent chunk = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER);
chunk.setDecoderResult(DecoderResult.failure(cause));
message = null;
trailer = null;
return chunk;
}
示例14: setDecoderResult
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Override
public void setDecoderResult(DecoderResult decoderResult) {
if (decoderResult == null) {
throw new NullPointerException("decoderResult");
}
this.decoderResult = decoderResult;
}
示例15: testRequestWithBadInitialLine
import io.netty.handler.codec.DecoderResult; //导入依赖的package包/类
@Test
public void testRequestWithBadInitialLine() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder());
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8));
HttpRequest req = (HttpRequest) ch.readInbound();
DecoderResult dr = req.getDecoderResult();
assertFalse(dr.isSuccess());
assertTrue(dr.isFailure());
ensureInboundTrafficDiscarded(ch);
}