How to handle HTTP error 414 Request-URI Too Long

HTTP Apache

Typically Web servers set fairly generous limits on length for URL query string e.g. up to 2048 or 4096 characters. While running a web application in Tomcat & HTTP Apache server, we came across a situation where we were asked to handle an extremely long URL query strings. Which was throwing HTTP 414 “Request-URI Too Long” error. For this situation the Web server may need to be reconfigured to allow long query string URLs.

Configure Tomcat to handle HTTP 414 error.

For this configuration change we have to first find out which Apache Tomcat connector we have configured. Here is a short discription of these connectors.

Apache Tomcat Connectors

1. HTTP Connector

The HTTP Connector element represents a Connector component that supports the HTTP/1.1 protocol. It enables Catalina to function as a stand-alone web server, in addition to its ability to execute servlets and JSP pages. A particular instance of this component listens for connections on a specific TCP port number on the server. One or more such Connectors can be configured as part of a single Service, each forwarding to the associated Engine to perform request processing and create the response.

At server startup time, this Connector will create a number of request processing threads (based on the value configured for the minSpareThreads attribute). Each incoming request requires a thread for the duration of that request. If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount attribute). Any further simultaneous requests will receive “connection refused” errors, until resources are available to process them.

More details about HTTP Connector can be found at Apache Tomcat Configuration Reference

2. AJP Connector

The AJP Connector element represents a Connector component that communicates with a web connector via the AJP protocol. This is used for cases where you wish to invisibly integrate Tomcat into an Apache installation.

This connector supports load balancing when used in conjunction with the jvmRoute attribute of the Engine.

More details about AJP connector can be found at Apache Tomcat Configuration Reference

Handle HTTP 414 error if using Apache Tomcat HTTP Connector

If we are using Apache TOmcat HTTP Connector then we have to reconfigure the below mentioned setting of tomcat.

Go to tomcat/conf/server.xml’s HTTP/1.1 Connector entry, and add a maxHttpHeaderSize=”65536″ to increase from the default maximum of 8K or so, to 64K. I imagine that you could up this number as high as necessary, but 64K suffices for all types of needs. Understand that Web servers have to set some reasonable limit here, because they have to deal with badly programmed clients trying to give them huge garbage URLs.

 

Hope it will help you.

Handle HTTP 414 error if using Apache Tomcat AJP Connector

Step 1. Go to tomcat/conf/server.xml’s AJP 1.3 Connector on port 8009 entry , and add a packetSize=”65536″ to increase from the default maximum of 8K or so, to 64K.


Step 2. Go to Apache/conf/workers.properties file and add the below mentioned line while defining the template.

worker.template.max_packet_size=65536

Step 3. Go to Apache/conf/http.conf file and add LimitRequestLine “bytes” which is used to limit the size of the HTTP request line that will be accepted from the client.

LimitRequestLine 65536