Configure max post size for a external webapp in j

2019-07-15 12:59发布

My issue is as follows:

I deliver a webapp.war and a Tomcat server to deploy it from.

My client has the option to not use my server and use a service that deploys my app in Jetty as an external webapp.

That Jetty has a limitiation for POST size that is default (200k) and is too small for my app to run all its features properly - my HTTP 1/1 POST request get truncated and become mainly unusable.

What I need to do is configure my webapp so that when deployed in Jetty as an external app, its max POST size is a value of my choosing - like 1M.

I have done some research and I found that one can configure jetty to change POST size only for a particular webapp, but as I don't use Jetty I am yet unclear where this settings should go and what is the difference, from the settings point of view, between an external webapp and an internal webapp in Jetty (other than path).


http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size#Changing_the_Maximum_Form_Size_for_All_Apps_on_a_Server


http://wiki.eclipse.org/Jetty_WTP_Plugin/Jetty_WTP_External_WebApp

I would have liked to have found out more, but my research was not quite fortuitous with respect to external webapps in Jetty.

I have tried the JVM approach, setting "org.eclipse.jetty.server.Request.maxFormContentSize" environment variable to 1000000, but I noticed no change in my setup behaviour.

The request is not truncated in Tomcat (which also runs on a default configuration), but was so far truncated on Jetty no matter what I did to stop that from happening.

I should not change the Jetty server's global setting, if I can avoid it, but any progress would be welcome even if I have to compromise on this.

Do you guys have any ideas on what I should do?

2条回答
神经病院院长
2楼-- · 2019-07-15 13:29

You could

1) start Jetty with the org.eclipse.jetty.server.Request.maxFormContentSize system property set to your desired value.

(this will set all count for All Apps in the JVM)

 java  -Dorg.eclipse.jetty.server.Request.maxFormContentSize=99900000 -jar start.jar 

2) Changing the Maximum Form Size for a Single Webapp

ContextHandler.setMaxFormContentSize(int maxSize);

You can do this either in a context XML deployment descriptor external to the webapp, or in a jetty-web.xml file in the webapp's WEB-INF directory.

In either case the syntax of the XML file is the same:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  <!-- Max Form Size                                                   -->
  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  <Set name="maxFormContentSize">200000</Set>
</Configure>

3) Changing the Maximum Form Size for All Apps on a Server

Set an attribute on the Server instance for which you want to modify the maximum form content size:

<configure class="org.eclipse.jetty.server.Server">
      <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
      <Arg>200000</Arg>
    </Call>
</configure>

source: jetty wiki

查看更多
家丑人穷心不美
3楼-- · 2019-07-15 13:37

If you are programing your own java jetty server, this is the way, how to change body size directly from java source code

org.eclipse.jetty.server.Server server =
    new org.eclipse.jetty.server.Server(port);

// configure http request body size limit to 100MB
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", "100000000");
...
server.start();
server.join();
查看更多
登录 后发表回答