Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Bug
-
3.2.8
-
None
-
None
-
Unknown
Description
When a file is uploaded with a slow connection (only), using my CXF REST API, I get Couldn't find MIME boundary error. So I debugged the CXF core code to find out why. Now I'm looking at this code[1].
private static boolean readTillFirstBoundary(PushbackInputStream pbs, byte[] bp) throws IOException { // work around a bug in PushBackInputStream where the buffer isn't // initialized // and available always returns 0. int value = pbs.read(); pbs.unread(value); while (value != -1) { value = pbs.read();
When the client to server connection is very slow, the first read() of the input stream almost always is -1. That results Couldn't find MIME boundary error at the later on the flow.
If I change the code (just to debug) to skip the first byte when it's -1, like below, it works smoothly. See the 3 lines shown with "<<<<<<<". That means the data I expect is available after -1.
private static boolean readTillFirstBoundary(PushbackInputStream pbs, byte[] bp) throws IOException { // work around a bug in PushBackInputStream where the buffer isn't // initialized // and available always returns 0. int value = pbs.read(); if (value == -1) { <<<<<< if the first byte is -1, value = pbs.read(); <<<<<< ignore that and read the } <<<<<< next byte pbs.unread(value); while (value != -1) { value = pbs.read();
Another important thing is this happens only for non-localhost and https connections.
Any idea what could be the reason for giving -1 for the first read always when the connection is slow?