当前位置: 首页>>代码示例>>Java>>正文


Java DecoderResult类代码示例

本文整理汇总了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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:HttpObjectDecoder.java

示例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);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:HttpInvalidMessageTest.java

示例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);
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:17,代码来源:HttpInvalidMessageTest.java

示例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);
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:17,代码来源:HttpInvalidMessageTest.java

示例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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:11,代码来源:MqttMessage.java

示例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;
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:11,代码来源:MqttMessage.java

示例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");
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:11,代码来源:HttpSnoopServerHandler.java

示例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);
}
 
开发者ID:compasses,项目名称:elastic-rabbitmq,代码行数:34,代码来源:SearchQueryDecoder.java

示例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);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:15,代码来源:RequestInfoSetterHandlerTest.java

示例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();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:15,代码来源:RequestInfoSetterHandlerTest.java

示例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);
	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:37,代码来源:ChannelOperationsHandler.java

示例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");
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:11,代码来源:HttpSnoopServerHandler.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:14,代码来源:HttpObjectDecoder.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:8,代码来源:DefaultHttpObject.java

示例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);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:11,代码来源:HttpInvalidMessageTest.java


注:本文中的io.netty.handler.codec.DecoderResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。