在写一个servlet上传文件功能过程中,部署环境为WildFfly10,当上传文件大于10M时,后台抛出相关异常:
16:49:20,715 ERROR [stderr] (default task-9) org.apache.commons.fileupload.FileUploadException: UT000020: Connection terminated as request was larger than 10485760
16:49:20,716 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
16:49:20,716 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:115)
16:49:20,717 ERROR [stderr] (default task-9) at UploadServlet.doPost(UploadServlet.java:51)
16:49:20,717 ERROR [stderr] (default task-9) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
16:49:20,717 ERROR [stderr] (default task-9) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
16:49:20,717 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
16:49:20,718 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
16:49:20,718 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
16:49:20,718 ERROR [stderr] (default task-9) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
16:49:20,718 ERROR [stderr] (default task-9) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
16:49:20,719 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
16:49:20,719 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
16:49:20,719 ERROR [stderr] (default task-9) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
16:49:20,719 ERROR [stderr] (default task-9) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
16:49:20,720 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
16:49:20,720 ERROR [stderr] (default task-9) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
16:49:20,720 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
16:49:20,721 ERROR [stderr] (default task-9) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
16:49:20,721 ERROR [stderr] (default task-9) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
16:49:20,721 ERROR [stderr] (default task-9) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
16:49:20,721 ERROR [stderr] (default task-9) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
16:49:20,722 ERROR [stderr] (default task-9) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
16:49:20,725 ERROR [stderr] (default task-9) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
16:49:20,725 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
16:49:20,725 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
16:49:20,727 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
16:49:20,728 ERROR [stderr] (default task-9) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
16:49:20,728 ERROR [stderr] (default task-9) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
16:49:20,728 ERROR [stderr] (default task-9) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
16:49:20,728 ERROR [stderr] (default task-9) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
16:49:20,729 ERROR [stderr] (default task-9) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
16:49:20,729 ERROR [stderr] (default task-9) at java.lang.Thread.run(Thread.java:745)
16:49:20,729 ERROR [stderr] (default task-9) Caused by: java.io.IOException: UT000020: Connection terminated as request was larger than 10485760
16:49:20,729 ERROR [stderr] (default task-9) at io.undertow.conduits.FixedLengthStreamSourceConduit.checkMaxSize(FixedLengthStreamSourceConduit.java:168)
16:49:20,730 ERROR [stderr] (default task-9) at io.undertow.conduits.FixedLengthStreamSourceConduit.read(FixedLengthStreamSourceConduit.java:229)
16:49:20,730 ERROR [stderr] (default task-9) at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127)
16:49:20,730 ERROR [stderr] (default task-9) at io.undertow.channels.DetachableStreamSourceChannel.read(DetachableStreamSourceChannel.java:209)
16:49:20,730 ERROR [stderr] (default task-9) at io.undertow.server.HttpServerExchange$ReadDispatchChannel.read(HttpServerExchange.java:2231)
16:49:20,731 ERROR [stderr] (default task-9) at org.xnio.channels.Channels.readBlocking(Channels.java:294)
16:49:20,731 ERROR [stderr] (default task-9) at io.undertow.servlet.spec.ServletInputStreamImpl.readIntoBuffer(ServletInputStreamImpl.java:170)
16:49:20,731 ERROR [stderr] (default task-9) at io.undertow.servlet.spec.ServletInputStreamImpl.read(ServletInputStreamImpl.java:146)
16:49:20,731 ERROR [stderr] (default task-9) at java.io.FilterInputStream.read(FilterInputStream.java:133)
16:49:20,732 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:134)
16:49:20,732 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:999)
16:49:20,732 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:903)
16:49:20,732 ERROR [stderr] (default task-9) at java.io.InputStream.read(InputStream.java:101)
16:49:20,732 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.util.Streams.copy(Streams.java:100)
16:49:20,733 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.util.Streams.copy(Streams.java:70)
16:49:20,733 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:593)
16:49:20,733 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:617)
16:49:20,733 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:634)
16:49:20,734 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:1023)
16:49:20,734 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:1003)
16:49:20,734 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:310)
16:49:20,734 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:334)
16:49:20,735 ERROR [stderr] (default task-9) ... 31 more
16:49:20,735 ERROR [stderr] (default task-9) Caused by:
16:49:20,735 ERROR [stderr] (default task-9) java.io.IOException: UT000020: Connection terminated as request was larger than 10485760
16:49:20,735 ERROR [stderr] (default task-9) at io.undertow.conduits.FixedLengthStreamSourceConduit.checkMaxSize(FixedLengthStreamSourceConduit.java:168)
16:49:20,736 ERROR [stderr] (default task-9) at io.undertow.conduits.FixedLengthStreamSourceConduit.read(FixedLengthStreamSourceConduit.java:229)
16:49:20,736 ERROR [stderr] (default task-9) at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127)
16:49:20,736 ERROR [stderr] (default task-9) at io.undertow.channels.DetachableStreamSourceChannel.read(DetachableStreamSourceChannel.java:209)
16:49:20,736 ERROR [stderr] (default task-9) at io.undertow.server.HttpServerExchange$ReadDispatchChannel.read(HttpServerExchange.java:2231)
16:49:20,736 ERROR [stderr] (default task-9) at org.xnio.channels.Channels.readBlocking(Channels.java:294)
16:49:20,737 ERROR [stderr] (default task-9) at io.undertow.servlet.spec.ServletInputStreamImpl.readIntoBuffer(ServletInputStreamImpl.java:170)
16:49:20,737 ERROR [stderr] (default task-9) at io.undertow.servlet.spec.ServletInputStreamImpl.read(ServletInputStreamImpl.java:146)
16:49:20,737 ERROR [stderr] (default task-9) at java.io.FilterInputStream.read(FilterInputStream.java:133)
16:49:20,737 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:134)
16:49:20,738 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:999)
16:49:20,738 ERROR [stderr] (default task-9) at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:903)
16:49:20,738 ERROR [stderr] (default task-9) at java.io.InputStream.read(InputStream.java:101)
原因是在jboss相关配置中,有个max-post-size参数,该参数配置默认是10M,如果想改变上传文件大小的限制,需要对该参数的值进行修改,详细配置可以参考这里:https://docs.jboss.org/author/display/WFLY10/Undertow+subsystem+configuration,这里有对配置参数的说明。