Generating a MD5 hash of HTTP request body and storing it into a session attribute

After much searching online and reviewing the Gatling source code and docs I'm still stumped with how to generate a MD5 hash of the body of an HTTP request in order to then use it in a subsequent request. 

I know I can use a signature calculator to generate the MD5 checksum if I want to add it to the current request. But I couldn't work out how to store this value into the session in order to use it on a subsequent request.

In my test I basically need to upload a message body to one web service. And then send the MD5 checksum of the message along with other meta data to another web service. 

The snippet below shows the problem. The 'upload' steps put the message into a webservice, this is where I need to capture the MD5 checksum of the body so that it can be used in the subsequent call to the 'sendMsg' steps.

Any advice would be very gratefully received as this is blocking me from getting my load test operational.

val upload = exec(http("MsgSvcUpload")
    .headers(Map(("X-Auth-Token", "${keystoneToken}"), ("accept", "*/*"), ("X-Delete-After", "86400")))

val sendMsg = exec(http("MsgSvcSendMsg")
    .headers(Map(("X-Auth-Token", "${keystoneToken}"), ("accept", "application/json")))

I finally found an acceptable solution to this problem. Although it does involve processing the file body twice which is not great but in my case the bodies are quite small so it’s not a huge problem.

Here is the solution:

.exec(session => {
  val bodyExpr = ElFileBody("${fileBody}")
  val bodyStr = bodyExpr(session).get
  session.set("msgSvcMsgMd5", digestMD5.digest(bodyStr.getBytes).map("%02x".format(_)).mkString)
    .set("msgSvcMsgSize", bodyStr.length)

Thanks Andy