Hi,
I'm generally just a lurker on this list but we use jclouds internally here for
various things. I was just trying to understand the implementation of
ApacheHCHttpCommandExecutorService. While doing so, I could not understand
following code snippet from
[drivers>apachehc]ApacheHCHttpCommandExecutorService.java->convert(HttpRequest
request) method. (Please refer the following code snippet, highlighted if
condition)
protected HttpUriRequest convert(HttpRequest request) throws IOException {
HttpUriRequest returnVal = apacheHCUtils.convertToApacheRequest(request);
if (request.getPayload() != null &&
request.getPayload().getContentMetadata().getContentMD5() != null) {
String md5 =
base64().encode(ByteStreams2.hashAndClose(request.getPayload().openStream(),
md5()).asBytes());
returnVal.addHeader("Content-MD5", md5);
}
if (!returnVal.containsHeader(HttpHeaders.USER_AGENT)) {
returnVal.addHeader(HttpHeaders.USER_AGENT, userAgent);
}
return returnVal;
}
I have couple of queries on this if condition code -
1. I Could not understand the purpose of generating MD5 hashcode of payload,
if it is already available in payload metadata.
2. While generating md5 of payload in this heighlighted if condition
snippet, InputStream is consumed. And as it is consumed to generate MD5,
payload will be empty.
Please put some lights on this. We are blocked on this.
Thank You,
Kiran