HttpResponse's externalizable implementation not works on Linux/Unix systems
----------------------------------------------------------------------------

                 Key: SHINDIG-695
                 URL: https://issues.apache.org/jira/browse/SHINDIG-695
             Project: Shindig
          Issue Type: Bug
          Components: Gadget Rendering Server (Java)
            Reporter: Zsolt Bányai


In readExternal(ObjectInput in) it cannot read the whole content at the first 
time so the responseString could be truncated.

One of the right ways:

 /**
   * Expected layout:
   *
   * int - status code
   * Map<String, List<String>> - headers
   * int - length of body
   * byte array - body, of previously specified length
   */
  @SuppressWarnings("unchecked")
  public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
    httpStatusCode = in.readInt();
    Map<String, List<String>> headerCopy = (Map<String, 
List<String>>)in.readObject();
    int bodyLength = in.readInt();
    responseBytes = new byte[bodyLength];
    int cnt, offset = 0;
    while ((cnt = in.read(responseBytes, offset, bodyLength)) >= 0) {
        //cnt cannot be 0, because: "This method will block until some input is 
available.", but can be lower than bodyLength 
                offset += cnt;
                bodyLength -= cnt;
    }
    if (offset != responseBytes.length) {
        throw new IOException("Invalid body! Expected length = " + 
responseBytes.length + ", bytes readed = " + offset + ".");
    }

    date = getAndUpdateDate(headerCopy);
    encoding = getAndUpdateEncoding(headerCopy, responseBytes);
    headers = Collections.unmodifiableMap(headerCopy);
    metadata = Collections.emptyMap();
  }



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to