diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache')
-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; + } } |