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

The following examples show how to use io.netty.handler.codec.DecoderResult#isSuccess() . 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: DefaultSocks4CommandResponse.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(96);
    buf.append(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", dstAddr: ");
    } else {
        buf.append("(dstAddr: ");
    }
    buf.append(dstAddr());
    buf.append(", dstPort: ");
    buf.append(dstPort());
    buf.append(')');

    return buf.toString();
}
 
Example 2
Source File: DefaultSocks4CommandRequest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(128);
    buf.append(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", type: ");
    } else {
        buf.append("(type: ");
    }
    buf.append(type());
    buf.append(", dstAddr: ");
    buf.append(dstAddr());
    buf.append(", dstPort: ");
    buf.append(dstPort());
    buf.append(", userId: ");
    buf.append(userId());
    buf.append(')');

    return buf.toString();
}
 
Example 3
Source File: DefaultSocks5PasswordAuthResponse.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", status: ");
    } else {
        buf.append("(status: ");
    }
    buf.append(status());
    buf.append(')');

    return buf.toString();
}
 
Example 4
Source File: DefaultSocks5InitialRequest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", authMethods: ");
    } else {
        buf.append("(authMethods: ");
    }
    buf.append(authMethods());
    buf.append(')');

    return buf.toString();
}
 
Example 5
Source File: DefaultSocks5CommandRequest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(128);
    buf.append(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", type: ");
    } else {
        buf.append("(type: ");
    }
    buf.append(type());
    buf.append(", dstAddrType: ");
    buf.append(dstAddrType());
    buf.append(", dstAddr: ");
    buf.append(dstAddr());
    buf.append(", dstPort: ");
    buf.append(dstPort());
    buf.append(')');

    return buf.toString();
}
 
Example 6
Source File: DefaultSocks5CommandResponse.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(128);
    buf.append(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", status: ");
    } else {
        buf.append("(status: ");
    }
    buf.append(status());
    buf.append(", bndAddrType: ");
    buf.append(bndAddrType());
    buf.append(", bndAddr: ");
    buf.append(bndAddr());
    buf.append(", bndPort: ");
    buf.append(bndPort());
    buf.append(')');

    return buf.toString();
}
 
Example 7
Source File: DefaultSocks5InitialResponse.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", authMethod: ");
    } else {
        buf.append("(authMethod: ");
    }
    buf.append(authMethod());
    buf.append(')');

    return buf.toString();
}
 
Example 8
Source File: DefaultSocks5PasswordAuthRequest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder(StringUtil.simpleClassName(this));

    DecoderResult decoderResult = decoderResult();
    if (!decoderResult.isSuccess()) {
        buf.append("(decoderResult: ");
        buf.append(decoderResult);
        buf.append(", username: ");
    } else {
        buf.append("(username: ");
    }
    buf.append(username());
    buf.append(", password: ****)");

    return buf.toString();
}
 
Example 9
Source File: RequestAdapter.java    From k3pler with GNU General Public License v3.0 5 votes vote down vote up
private String getShortResult(DecoderResult result){
    if (result.isSuccess())
        return "S";
    else if (result.isFinished())
        return "F";
    else if (result.isFailure())
        return "X";
    else
        return "-";
}
 
Example 10
Source File: RequestUtils.java    From tutorials with MIT License 5 votes vote down vote up
static StringBuilder evaluateDecoderResult(HttpObject o) {
    StringBuilder responseData = new StringBuilder();
    DecoderResult result = o.decoderResult();

    if (!result.isSuccess()) {
        responseData.append("..Decoder Failure: ");
        responseData.append(result.cause());
        responseData.append("\r\n");
    }

    return responseData;
}
 
Example 11
Source File: SampleHandler.java    From xio with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 12
Source File: SampleHandler.java    From xio with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 13
Source File: HttpSnoopServerHandler.java    From netty.book.kor with MIT License 5 votes vote down vote up
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");
}
 
Example 14
Source File: HttpSnoopServerHandler.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 15
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 16
Source File: HttpSnoopServerHandler.java    From tools-journey with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 17
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 18
Source File: HttpSnoopServerHandler.java    From julongchain with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 19
Source File: HttpSnoopServerHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 20
Source File: HttpRequestParamDecoder.java    From fastjgame with Apache License 2.0 4 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
    DecoderResult decoderResult = msg.decoderResult();
    if (!decoderResult.isSuccess()) {
        ctx.writeAndFlush(HttpResponseHelper.newBadRequestResponse())
                .addListener(ChannelFutureListener.CLOSE);
        logger.warn("decode failed.", decoderResult.cause());
        return;
    }
    HttpMethod method = msg.method();
    // 仅限get和post请求
    if (method != HttpMethod.GET && method != HttpMethod.POST) {
        ctx.writeAndFlush(HttpResponseHelper.newBadRequestResponse())
                .addListener(ChannelFutureListener.CLOSE);
        logger.info("unsupported method {}", method.name());
        return;
    }

    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(msg.uri());
    String path = queryStringDecoder.path();
    Map<String, String> paramsMap = new LinkedHashMap<>();

    if (method == HttpMethod.GET) {
        for (Map.Entry<String, List<String>> entry : queryStringDecoder.parameters().entrySet()) {
            paramsMap.put(entry.getKey(), entry.getValue().get(0));
        }
    } else {
        // You <strong>MUST</strong> call {@link #destroy()} after completion to release all resources.
        HttpPostRequestDecoder postRequestDecoder = new HttpPostRequestDecoder(msg);
        try {
            for (InterfaceHttpData httpData : postRequestDecoder.getBodyHttpDatas()) {
                if (httpData.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
                    Attribute attribute = (Attribute) httpData;
                    paramsMap.put(attribute.getName(), attribute.getValue());
                }
            }
        } finally {
            postRequestDecoder.destroy();
        }
    }
    final HttpRequestParam httpRequestParam = new HttpRequestParam(method, paramsMap);
    publish(new HttpRequestEvent(ctx.channel(), path, httpRequestParam, portExtraInfo));
}