Java Code Examples for io.netty.handler.codec.DecoderResult#cause()

The following examples show how to use io.netty.handler.codec.DecoderResult#cause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RiposteHandlerInternalUtil.java    From riposte with Apache License 2.0 6 votes vote down vote up
Throwable getDecoderFailure(HttpObject httpObject) {
    if (httpObject == null) {
        return null;
    }

    DecoderResult decoderResult = httpObject.decoderResult();
    if (decoderResult == null) {
        return null;
    }

    if (!decoderResult.isFailure()) {
        return null;
    }

    return decoderResult.cause();
}
 
Example 2
Source File: RequestDecoderAux.java    From xian with Apache License 2.0 5 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, FullHttpRequest msg, List<Object> out) throws Exception {
    LOG.debug("    httpRequest  ---->   UnitRequest Pojo");
    /*if (!HttpMethod.POST.equals(msg.method())) {
        throw new BadRequestException(new IllegalArgumentException("拒绝非POST请求!"));
    }*/
    DecoderResult result = msg.decoderResult();
    if (!result.isSuccess()) {
        throw new BadRequestException(result.cause());
    }
    updateLongConnectionStatus(msg, ctx);
    Request request = new Request(msg, MsgIdHolder.get());
    offerReqQueue(ctx, request);
    out.add(request);
}
 
Example 3
Source File: SearchQueryDecoder.java    From elastic-rabbitmq with MIT License 5 votes vote down vote up
@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);
}
 
Example 4
Source File: HttpClientHandler.java    From protools with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRead0(final ChannelHandlerContext ctx, final HttpObject msg) {
    if (msg instanceof FullHttpResponse) {
        final FullHttpResponse response = (FullHttpResponse) msg;

        httpReceive.setStatusCode(response.status().code())
                .setStatusText(response.status().codeAsText().toString());

        HttpHeaders headers = response.headers();
        if (httpSend.getNeedReceiveHeaders() && !headers.isEmpty()) {

            final Map<String, String> responseHeaderMap = Maps.newHashMapWithExpectedSize(headers.size());

            headers.forEach(one -> {
                responseHeaderMap.put(one.getKey(), one.getValue());
            });

            httpReceive.setResponseHeader(responseHeaderMap);
        }

        if (HttpUtil.isTransferEncodingChunked(response)) {
            if (log.isDebugEnabled()) {
                log.debug("#HTTP 内容开始{");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("#HTTP 内容开始{");
            }
        }

        final String responseBody = response.content().toString(httpSend.getCharset());

        httpReceive.setResponseBody(responseBody);

        if (log.isDebugEnabled()) {
            log.debug(responseBody);
        }

        if (log.isDebugEnabled()) {
            log.debug("}EOF#");
        }

        final DecoderResult decoderResult = response.decoderResult();
        if (decoderResult.isFailure()) {
            Throwable cause = decoderResult.cause();
            if (log.isErrorEnabled()) {
                log.error(ToolFormat.toException(cause), cause);
            }
            httpReceive.setHaveError(true)
                    .setErrMsg(cause.getMessage())
                    .setThrowable(cause);
        } else if (response.status().code() != 200) {
            httpReceive.setHaveError(true)
                    .setErrMsg("本次请求响应码不是200,是" + response.status().code());
        }

        httpReceive.setIsDone(true);
        ctx.close();
    }
}