Skip to content

Commit

Permalink
fix 无参数Http请求处理
Browse files Browse the repository at this point in the history
  • Loading branch information
tzfun committed Apr 12, 2023
1 parent 594ebb4 commit 20d5721
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.sql.Ref;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -167,7 +166,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
}

@Override
@SuppressWarnings({"unchecked","rawtypes"})
@SuppressWarnings({"unchecked", "rawtypes"})
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
PairKey<URI, String> pair = filterUri(ctx, msg);
if (pair == null) {
Expand Down Expand Up @@ -216,6 +215,9 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) thro

if (parameterType.isArray()) {
List<String> valueArr = (List<String>) params.get(key + "[]");
if (valueArr == null) {
continue;
}
Class<?> componentType = parameterType.getComponentType();
Object array = Array.newInstance(componentType, valueArr.size());
for (int j = 0; j < valueArr.size(); j++) {
Expand All @@ -224,6 +226,9 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) thro
parameter[i] = array;
} else if (parameterType.isAssignableFrom(List.class)) {
List<String> valueArr = (List<String>) params.get(key + "[]");
if (valueArr == null) {
continue;
}
Type componentType = ((ParameterizedType) method.getGenericParameterTypes()[0]).getActualTypeArguments()[0];
List list = new ArrayList(valueArr.size());
for (String s : valueArr) {
Expand All @@ -233,7 +238,7 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) thro
} else {
parameter[i] = ReflexUtil.parseValueFromStr(parameterType, (String) value);
if (parameter[i] == null) {
parameter[i] = new Gson().fromJson(value.toString(), parameterType);
parameter[i] = new Gson().fromJson((String) value, parameterType);
}
}
}
Expand Down

0 comments on commit 20d5721

Please sign in to comment.