• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Request header is too large - Spring + JSF + Hibernate project

 
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 28114
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim and Karthik,
Yes. The image is sent as a parameter in a POST request. Is there a problem?
 
Tim Holloway
Saloon Keeper
Posts: 28114
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim
I am new to REST service development. Can you please explain the details?
 
Tim Holloway
Saloon Keeper
Posts: 28114
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,

Here is the code I use to receive the image



img is the parameter I use to receive the base64 encoded string.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Tim Holloway
Saloon Keeper
Posts: 28114
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic