diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-12 06:21:38 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-12 06:21:38 +0000 |
commit | ee14a5168606daa06748d32216535f96e8a7416a (patch) | |
tree | 7341ec21d139be2d67cda33727d5079c93a7ba70 /sca-java-2.x/trunk/modules/common-http | |
parent | 0bf4df347d4933da8535f9649c9a095d60700a02 (diff) |
Adding generated eTag to RPC style invocations
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@943389 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java index 3dc9f5891d..f810970869 100644 --- a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java +++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java @@ -19,6 +19,9 @@ package org.apache.tuscany.sca.common.http; +import java.math.BigInteger; +import java.security.MessageDigest; + import javax.servlet.http.HttpServletRequest; /** @@ -71,4 +74,20 @@ public class HTTPUtil { return contextRoot; } + + public static String calculateHashETag(byte[] content) { + String eTag = "invalid"; + try { + MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + byte[] digest = messageDigest.digest(content); + BigInteger number = new BigInteger(1, digest); + StringBuffer sb = new StringBuffer('0'); + sb.append(number.toString(16)); + eTag = sb.toString(); + } catch(Exception e) { + //ignore, we will return random etag + eTag = Integer.toString((new java.util.Random()).nextInt(Integer.MAX_VALUE)); + } + return eTag; + } } |