下面列出了 io.netty.handler.codec.DecoderResult # isSuccess ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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();
}
@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();
}
@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();
}
@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();
}
@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();
}
@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();
}
@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();
}
@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();
}
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");
}
private String getShortResult(DecoderResult result){
if (result.isSuccess())
return "S";
else if (result.isFinished())
return "F";
else if (result.isFailure())
return "X";
else
return "-";
}
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");
}
@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);
}
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");
}
@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);
}
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");
}
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");
}
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");
}
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");
}
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;
}
@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));
}