简体   繁体   中英

How do I send large (over 64k) http responses from a java servlet in a jetty server?

I am working with a Jetty server, and have a servlet that produces large responses of well over 65536 bytes in size. I tried curl, wget, and python urllib2 to request the content at the url of the servlet, but all have a truncated response body size of just 65536 bytes, which leads me to believe that the limit is on the server. Interestingly, if I run the server on my desktop rather than a production server, there does not seem to be a cap of 65536 on the response size for the same servlet. Can someone explain why this might be happening and how I might resolve it and send larger responses?

There is no limit to the size of a response from Jetty.

It can literally stream a single HTTP chunked-encoded response until the heat death of the universe.

The jetty-distribution comes with a demo-base (or "test webapp" with old versions of jetty) that has several multi-megabyte examples for you to test as well.

Post some code for your servlet, that might reveal what is going on.

Self-answering, so that the question has an answer. From the comments:

Found the issue. We had a very low idle timeout for reading from and writing to the request input stream and response output stream. Thus, responses that were larger than 1 chunk (in this case 65536 bytes), were blocking on the write call for longer than this low timout before they could write the second chunk. This is why the problem did not occur on the local machine -- since the request was local, it was not hitting the timeout. In our case, the solution is not to set such a low timeout for requests and responses involving servlets that need to send large amounts of data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM