NutzCN Logo
问答 启用 jetty-starter改变form post数据大小无效怎么破?
发布于 1583天前 作者 shuxinyun 2248 次浏览 复制 上一个帖子 下一个帖子
标签:

引入后,保持jetty默认参数,但在项目中form提交数据的时候,运行到如下代码:

public void extractFormParameters(MultiMap<String> params) {
        try {
            int maxFormContentSize = 200000;
            int maxFormKeys = 1000;
            int maxFormKeys;
            if (this._context != null) {
                ContextHandler contextHandler = this._context.getContextHandler();
                maxFormContentSize = contextHandler.getMaxFormContentSize();
                maxFormKeys = contextHandler.getMaxFormKeys();
            } else {
                maxFormContentSize = this.lookupServerAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", maxFormContentSize);
                maxFormKeys = this.lookupServerAttribute("org.eclipse.jetty.server.Request.maxFormKeys", maxFormKeys);
            }

            int contentLength = this.getContentLength();
            if (maxFormContentSize >= 0 && contentLength > maxFormContentSize) {
                throw new IllegalStateException("Form is larger than max length " + maxFormContentSize);
            } else {
                InputStream in = this.getInputStream();
                if (this._input.isAsync()) {
                    throw new IllegalStateException("Cannot extract parameters with async IO");
                } else {
                    UrlEncoded.decodeTo(in, params, this.getCharacterEncoding(), maxFormContentSize, maxFormKeys);
                }
            }
        } catch (IOException var6) {
            LOG.debug(var6);
            throw new RuntimeIOException(var6);
        }
    }

执行这里:

 if (this._context != null) {
                ContextHandler contextHandler = this._context.getContextHandler();
                maxFormContentSize = contextHandler.getMaxFormContentSize();
                maxFormKeys = contextHandler.getMaxFormKeys();
            } 

获取的参数还是系统默认的200000,jetty-starter中设置的在这里没有加载到,这里的this._context是不等于null的。

7 回复

看配置手册呀,

jetty.maxFormContentSize=102400000

但默认值已经非常大, 为啥你还需要调整呢?

我是提交图片转化为base64格式字符串。
我按照配置手册配置了,我更进入看了一下,jetty.starter已经加载设置了这个参数为102400000,但是上面
contextHandler.getMaxFormContentSize();
还是200000。

this.wac.setErrorHandler((ErrorHandler)ep);
        this.wac.setWelcomeFiles(this.getWelcomeFiles());
        this.wac.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        this.updateMonitorValue("welcome_files", Strings.join(",", this.wac.getWelcomeFiles()));
        this.server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", this.getMaxFormContentSize());
        this.updateMonitorValue("maxFormContentSize", this.server.getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize"));
        this.server.setAttribute("org.eclipse.jetty.server.Request.maxFormKeys", this.getMaxFormKeys());
        this.server.setDumpAfterStart(false);
        this.server.setDumpBeforeStop(false);
        this.server.setStopAtShutdown(true);
        this.addNutzSupport();

这里已近执行无误

主要是如果这里this._context == null的话,配置的参数会起作用,如果不为null就跳过了配置

是打包成war之后测试的?感觉不会这样。。。

OK!辛苦了!

添加回复
请先登陆
回到顶部