The request could not be processed normally due to ignoring httpcontent
Opened this issue · 13 comments
在NettyMessageToServletRunnable里面先处理HttpRequest,在处理HttpContent。当msg是DefaultFullHttpRequest时会被忽略掉HttpConetnt导致不能正常处理请求
我复现下, 还没有到过有DefaultFullHttpRequest的情况, 因为我把HttpObjectAggregator去掉了, 应该是没有Full请求的情况了.
提交解决了. 不过我没有复现出来啊, 你是如何发现的.
我看了下你修复合包的那个问题的提交,感觉这里有点问题。然后在HttpServletProtocol的ChannelPipeline最前面加了一个ChannelInboundHandlerAdapter,在里面构造DefaultFullHttpRequest向下传递,可以复现这个问题。
FullHttpRequest只有 HttpObjectAggregator这个类, 和http请求行解析失败时, 会收到.
但HttpObjectAggregator这个类的聚合不支持long类型, 所以去掉了.
不过为了代码健壮, 刚才也都加上了. 现在2.0.17这个版本还是没问题的.
2.0.17不支持apache common-fileupload了么。
public ResponseEntity<String> upload(HttpServletRequest request, HttpServletResponse response)
throws IOException, FileUploadException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload();
Map<String, String> params = new HashMap<>();
InputStream is = null;
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
if (!item.isFormField()) {
is = item.openStream();
try {
.....
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != is) {
is.close();
}
}
} else {
String fieldName = item.getFieldName();
String value = Streams.asString(item.openStream());
params.put(fieldName, value);
}
}
}
return new ResponseEntity<String>("success", HttpStatus.OK);
}
应该是不影响的啊, 我试试咋回事
tomcat也不支持, 这里实现的逻辑和tomcat是一样的. 你可以这样保存文件
try {
Part part = request.getPart("myFile");
InputStream inputStream = part.getInputStream();
IOUtil.writeFile(inputStream,"D://test//upload","myfile.txt",false);
} catch (Exception e) {
e.printStackTrace();
}
解析的逻辑不需要你主动用common-fileupload写, servlet已经实现了.
tomcat 是可以的,另外2.0.15这个用法也是可以的,2.0.17不行。
好吧 那我加下. 然后发个版. 估计这两天就能好. 好了就告诉你
好的
这次提交解决了这个问题, 已经发版在2.0.18, 过两天就能在maven**仓库拉包了.
多多提意见啊, 感谢感谢