Forums Register Login
Request header is too large - Spring + JSF + Hibernate project
Hi all,
I am currently working in Spring + JSF + Hibernate project. I have written REST controller in Spring. In the edit profile API, I am recieving the image as a base64 encoded String. The String was initially 73 pages when we copied it in word document but again our android developer compressed it but still it comes around 13 pages. When the API is called with this image, the following exception is thrown

INFO: Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Request header is too large
at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:111)
at org.apache.coyote.http11.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:268)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1010)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

I tried googling and came up with 2 solutions, one to increase maxPostSize and the other is to increase the maxHttpHeaderSize. I tried increasing both the values to 5 MB but I still get the exception. How can I solve this? or should I be following some other method to upload images?
Something sounds odd there. It would appear that you're attempting to upload(?) an image by embedding it in an HTTP header.

Normally, you'd POST such a large amount of data in the HTTP request body, not put it in a header.

Maybe you could clarify that.
I suspect the client is sending a GET (POST also possible) request with the encoded image as a URL parameter. That would explain how it ends up in the request header.
Tim and Karthik,
Yes. The image is sent as a parameter in a POST request. Is there a problem?
A POST request of an x-encoded FORM with a large amount of data is OK. A POST that also carries a lot of data in the actual POST URL would be equivalent to a GET with a large URL parameter. Either way, the GET/POST statement isn't equipped for a lot of data. Large data should be in the body of a POST (because a GET doesn't use the body for form data).
I am new to REST service development. Can you please explain the details?
The limitations here aren't in ReST, they are in the HTTP/HTML transport that ReST is using.

Perhaps if you provided a sample of your code it would help.

Here is the code I use to receive the image

img is the parameter I use to receive the base64 encoded string.
(1 like)
The solution to your problem is that image data should be sent by client in the request body, not in header.

Client changes:
The mistake is in the client application, and that's the one which should change. It should send all parameters and values inside request body, not in URL.
In the request body, it can handle image data in two ways:
1) either send image data as a base64 encoded string, but in the body instead of URL
2) or send image data as raw binary data (again in the body, not in URL) . For this, the request should be formed as a multipart request.
The second option is the normal preferred way of doing it.

Server changes:
You need not changing anything in your controller if client goes with the first option above.
You have to make a change only if the android client chooses the second option of sending raw image data (again, this is the recommended way).
If that happens, reply back. I'll explain how to change your spring project to support it.

I agree with Karthik. I don't see anything wrong with your server-side code. It sounds like the problem is in the client.

Can you show us how the client builds and submits a request?
Tim and Karthik,

As you suggested the problem was with parameters passed in URL. I changed it to request body and now its working fine. Thank you guys so much for the timely assist.
Hang a left on main. Then read this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

This thread has been viewed 6531 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 20, 2018 00:43:43.