netty-codec-http:4.1.30解析application/json資料仍按鍵值對的方式解析,導致在windows系統下因為檔名錯誤而使程式奔潰,堆疊如下,
2019/02/13 12:33:53 ERROR [ worker@thread-1 ] c.b.m.h.DefaultExceptionHandler : io.netty.handler.codec.http.multipart.HttpPostRequestDecoder$ErrorDataDecoderException: java.io.IOException: Unable to create temporary file, C:\Users\GDY\AppData\Local\Temp\Attr_8394434811706373163_{"cid":5,"title":...
2019/02/13 12:33:53 INFO [ worker@thread-1 ] j.t.JetTemplateImpl : Loading template: /comm/error_500.html
at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBodyAttributes(HttpPostStandardRequestDecoder.java:609)
at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBody(HttpPostStandardRequestDecoder.java:361)
at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.offer(HttpPostStandardRequestDecoder.java:290)
at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.offer(HttpPostStandardRequestDecoder.java:47)
at io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.offer(HttpPostRequestDecoder.java:227)
at com.blade.mvc.http.HttpRequest.init(HttpRequest.java:359)
at com.blade.server.netty.HttpServerHandler.buildWebContext(HttpServerHandler.java:95)
at com.blade.server.netty.HttpServerHandler.lambda$channelRead0$0(HttpServerHandler.java:84)
at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:462)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at java.lang.Thread.run(Thread.java:745)
複製程式碼
Caused by: java.io.IOException: Unable to create temporary file, C:\Users\GDY\AppData\Local\Temp\Attr_8394434811706373163_{"cid":5,"title":"...
at java.io.File$TempDirectory.generateFile(File.java:1921)
at java.io.File.createTempFile(File.java:2010)
at java.io.File.createTempFile(File.java:2070)
at io.netty.handler.codec.http.multipart.AbstractDiskHttpData.tempFile(AbstractDiskHttpData.java:90)
at io.netty.handler.codec.http.multipart.AbstractDiskHttpData.addContent(AbstractDiskHttpData.java:163)
at io.netty.handler.codec.http.multipart.DiskAttribute.addContent(DiskAttribute.java:99)
at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBodyAttributes(HttpPostStandardRequestDecoder.java:597)
... 15 more
複製程式碼
修復如下:
修改類檔案:HttpPostStandardRequestDecoder.java
if(!this.request.headers().get("Content-Type").startsWith(APPLICATION_X_WWW_FORM_URLENCODED)){ return; }