1

I'm searching for weeks now to find a solution how to use chunked transfer encoding in a Java client without coding my own myHttpURLConnection.

The HttpUrlConnection of Java expects a fixed chunk size, which is not usable for me. The data consists of several messages that are different in size and must be sent in neartime to the server. The system currently (in Prelive/UAT state) works based on having fixed 1024 byte chunks but since most messages are significantly shorter, this is a waste of band width not acceptable in PROD.

Furthermore, messages larger than 1024 bytes would be chopped apart so a) the server would need to assemble them again and b) the last part of the message would not be send until enough data is available for filling 1024 bytes (even worse, not neartime anymore).

Does anybody have an idea how to workaround the restriction of the HttpUrlConnection of Java (non compliant with RFC2616 as it does not fully implement it) without having to code everything on top of URLConnection? I did not find any possibility to hook into the needed funcs for just setting a new chunk size for each heap of data.

My current option: douplicate all HTTPUrlConnection code and modify the parts dealing with CHUNKED (e.g. having some flush() function to adjust the chunk size and send what's there).

Synopsis
  • 191
  • 1
  • 5
  • Are you claiming that chunks of less than 1024 bytes are being padded? – user207421 Mar 08 '16 at 15:51
  • Whow, you are right, it's so easy ... I just read the flush() comments: Implementation details: In some releases the chunkLength is treated as a hint: chunks sent to the server may actually be larger or smaller. To force a chunk to be sent to the server call flush(). Thanks, sometimes the solution can be so easy, that one (me) can't see it ;-) – Synopsis Mar 08 '16 at 17:22
  • it's pretty difficult to see the actual chunk size since it gets processed in a specialized Apache module with no options to see the chunk size. So indeed the "padding" claim was just guessed by me ... thanks again for showing me this fatal mistake – Synopsis Mar 08 '16 at 17:31

0 Answers0