32

When I send a large file using a post request the system shows an exception:

java.lang.IllegalStateException: Form too large1105723>200000
at org.mortbay.jetty.Request.extractParameters(Request.java:1404)
at org.mortbay.jetty.Request.getParameter(Request.java:749)......

When I search help for this in Google they give some help e.g., webappcontext.setMaxFormContentSize(5000000);

I am using this code but the problem is not solved

Also I am using the code jettyServer.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", 5000000);

But no result

Note:-I am using Jetty-6.1.0

rjohnston
  • 7,153
  • 8
  • 30
  • 37
Narendra nnvd
  • 413
  • 1
  • 5
  • 11

18 Answers18

34

Try setting System properties via jetty.xml

    <Call class="java.lang.System" name="setProperty">
      <Arg>org.mortbay.jetty.Request.maxFormContentSize</Arg>
      <Arg>500000</Arg>
    </Call>

ok you can configure it from your web app

Add WEB-INF/jetty-web.xml file in your web application and configure the parameter in that file:

  <?xml version="1.0"?>
  <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
  "http://jetty.mortbay.org/configure.dtd">

  <Configure id="WebAppContext" class="org.mortbay.jetty.webapp.WebAppContext">
          <Set name="maxFormContentSize" type="int">600000</Set>
  </Configure>

Document

Version 7 or Higher

Since version 7, Jetty's classes have moved to a different package. You must replace org.mortbay... with org.eclipse... (Thanks to David for his comment).

Adam Paynter
  • 46,244
  • 33
  • 149
  • 164
jmj
  • 237,923
  • 42
  • 401
  • 438
  • Thanks For Writing Code But Their Is One Big Problem i.e We Doesn't Maintains The Server please Tell me Their is Another way To Do This – Narendra nnvd Oct 05 '10 at 07:16
  • @Narendra nnvd you deploy your app using maven plugin ? – jmj Oct 05 '10 at 07:17
  • I am Using The Server It Has Been Already Setuped We Doesn't Change the Xml File. – Narendra nnvd Oct 05 '10 at 07:24
  • Is Their Anyway To Do This Other Xml Files ? We Cann't Edit Jetty Xml Files Please Understand My Problem – Narendra nnvd Oct 05 '10 at 07:36
  • @Narendra nnvd No its just you need to add a config file in your web app , you won't touch the actual jetty's config file – jmj Oct 05 '10 at 07:42
  • Do i need to create jetty-web.xml file or need add it in web.xml file and will work without doing any extract modifications? – Narendra nnvd Oct 05 '10 at 08:49
  • @Narendra nnvd you need to add a new file check the documentation given – jmj Oct 05 '10 at 08:55
  • creating document with file name jetty-web.xml by using above code what ever you show and it places in Webapp/WEB-INF/ folder in my project. when i restart the my project.Still I got a exception – Narendra nnvd Oct 05 '10 at 09:22
  • @Narendra nnvd it should work recheck it also check this doc http://wiki.eclipse.org/Jetty/Reference/jetty-web.xml – jmj Oct 05 '10 at 10:04
  • my problem is solved my setting of "webappcontext.getServletContext().getContextHandler() .setMaxFormContentSize(10000000);" – Narendra nnvd Nov 30 '10 at 13:07
  • @Narendra nnvd Thanks for sharing :) it took too long time but its good you have updated here :) – jmj Nov 30 '10 at 13:11
  • 3
    In maven jetty plugin: 500000 – Mikael Lepistö Apr 08 '14 at 12:24
11
import org.mortbay.jetty.Server;
//... other code here...//
int port = 8080;
Server server = new Server(port);
server.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", -1);

This code works on jetty 6.0.2 which I'm using.
The size of "-1" means the form has no limit I tryed to post a form large 20,000,000 bytes and I had no problem.
For eclipse releases of Jetty(jetty 7) you have to use the following code:

import org.eclipse.jetty.server.Server;
//... other code here...//
int port = 8080;
Server server = new Server(port);
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1);
  • Is that right ? On my environment, to configure "-1" let jetty server to limit uploaded file size. Perhaps, it's up to the version of jetty application server. – hiropon Mar 22 '18 at 05:49
5

Unfortunately, I'm not able to make any changes to jetty.xml, so instead I simply set some options to adjust the maxFormContentSize like so:

JVM_OPTS="$JVM_OPTS -Dorg.eclipse.jetty.server.Request.maxFormContentSize=5000000"

This exists in the shell script that we use to launch our instance of Solr.

seth
  • 171
  • 2
  • 8
4

More documentation on form size: http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size

volni
  • 5,196
  • 8
  • 38
  • 44
3
            <!-- Development Jetty -->
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.8.v20121106</version>
            <configuration>
                <scanIntervalSeconds>1</scanIntervalSeconds>
                <webApp>
                    <contextPath>/${project.build.finalName}</contextPath>
                </webApp>
                <systemProperties>
                    <systemProperty>
                        <name>org.eclipse.jetty.server.Request.maxFormContentSize</name>
                        <value>10485760</value>
                    </systemProperty>
                </systemProperties>
            </configuration>
        </plugin>

Work for jetty 8 in maven plugin

Timmy Chiu
  • 549
  • 4
  • 13
3

I came across this problem too (running Jetty embedded in another application, so I'm not using jetty.xml).

I used the setMaxFormContentSize method on the ContextHandler class, which fixed the "form too large" exception. (See http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty#Setting_a_ServletContext for an example of creating/using a context handler).

Ash
  • 9,296
  • 2
  • 24
  • 32
2

I use jetty 9.2.3.v20140905, and i fixed the problem use the follow:

  • confiure pom.xml

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.2.3.v20140905</version>
  <configuration>
    <jettyXml>
      src/main/resources/jetty/jetty.xml
    </jettyXml>
  </configuration>
</plugin>
  • configure jetty.xml

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Call name="setAttribute">
    <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
    <Arg>-1</Arg>
  </Call>
</Configure>
guvivi
  • 21
  • 1
2
webappcontext.getServletContext().getContextHandler() .setMaxFormContentSize(10000000);
CoolBeans
  • 20,654
  • 10
  • 86
  • 101
Narendra nnvd
  • 413
  • 1
  • 5
  • 11
1

Depending on how old your Jetty Version is you are using (in my case jetty-5.1.14 embedded in Eclipse Equinox), it also could be that the property needs to be org.mortbay.http.HttpRequest.maxFormContentSize

From: org.mortbay.http.HttpRequest

/**
 * Max size of the form content. Limits the size of the data a client can push at the server.
 * Set via the org.mortbay.http.HttpRequest.maxContentSize system property.
 */
public static int __maxFormContentSize = Integer.getInteger(
        "org.mortbay.http.HttpRequest.maxFormContentSize", 200000).intValue();

So you need to do something like this in your application on startup to set the value:

System.setProperty("org.mortbay.http.HttpRequest.maxFormContentSize", "10000000");
Christoph
  • 3,980
  • 2
  • 40
  • 41
1

None of the above Solution worked for me ,

So in order to make this work I set the system property before creating the server, rather then setting it as server attribute

 System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "500000000");

 Server server = ServerFactory.createServer(host, port, contextPath, war);
NullPointerException
  • 3,732
  • 5
  • 28
  • 62
1

I ran into a similar issue on ActiveMQ so i had to edit the jetty.xml and add

  <property name="maxFormContentSize" value="-1" /> 

to the handler property.

from:-

 <property name="handler">
 <bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
 <property name="handlers">
 <list>
 <bean class="org.eclipse.jetty.webapp.WebAppContext">
  <property name="contextPath" value="/admin" /> 
  <property name="resourceBase" value="${activemq.home}/webapps/admin" /> 
  <property name="logUrlOnStart" value="true" /> 
  </bean>

to

 <property name="handler">
 <bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
 <property name="handlers">
 <list>
 <bean class="org.eclipse.jetty.webapp.WebAppContext">
  <property name="contextPath" value="/admin" /> 
  <property name="resourceBase" value="${activemq.home}/webapps/admin" /> 
  <property name="logUrlOnStart" value="true" /> 
  <property name="maxFormContentSize" value="-1" /> 
  </bean>
1

If you use jetty in embedded mode,try this.

    ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletHandler.setMaxFormContentSize(1024*1024*1024);//size you want to allow.
riversun
  • 758
  • 8
  • 12
1

I use Spring boot and set server.jetty.max-http-post-size: maxSize in application.properties to fix it.

server.jetty.max-http-post-size: 500000
piet.t
  • 11,718
  • 21
  • 43
  • 52
Ryze
  • 21
  • 3
1

set in jetty/webapps -> configure .xml (e.g jetty-web.xml) file

"-1" for unlimited content

<Set name="maxFormContentSize" type="int">600000</Set>

OR

<Set name="maxFormContentSize" type="int">-1</Set>

Cananau Cristian
  • 436
  • 2
  • 6
  • 30
0

Possibly because of changes in Jetty since version 7, but I only had success like so:

in jetty-web.xml, add the below to the Server object (1000000 is an example size, obv)

<Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
      <Arg>1000000</Arg>
</Call>

full file might look something like mine

<Configure id="Server" class="org.eclipse.jetty.server.Server">
    <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
      <Arg>1000000</Arg>
    </Call>

    <Ref id="DeploymentManager">
          <Call id="webappprovider" name="addAppProvider">
            <Arg>
(...)

ref http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size

jsh
  • 1,995
  • 18
  • 28
0

If you're running from eclipse/spring add the below to vm arguments -Dorg.mortbay.jetty.Request.maxFormContentSize=-1

C oneil
  • 157
  • 1
  • 4
0

Start jenkins by adding command line argument
-Dorg.eclipse.jetty.server.Request.maxFormContentSize=500000

i.e java -Dorg.eclipse.jetty.server.Request.maxFormContentSize=500000 -jar jenkins.war

Manoj
  • 11
  • 3
0

ActiveMQ:

The problem here is with Jetty, on which ActiveMQ is based. You can find more details here, documentation

Solution is in apache-activemq-5.9.0/bin/win64/wrapper.conf file, add the following line a after b (refer below).

  • a: wrapper.java.additional.16=-Dorg.eclipse.jetty.server.Request.maxFormContentSize=1000000
  • b: wrapper.java.additional.15=-Djava.security.auth.login.config=%ACTIVEMQ_CONF%/login.config

If you are running on a 32 bit computer, then please add the same line in apache-activemq-5.9.0/bin/win32/wrapper.conf.

Happy Coding..

Community
  • 1
  • 1
Bandham Manikanta
  • 1,858
  • 21
  • 21